Click here to Skip to main content
12,355,575 members (68,287 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Windows Win7 ListView
I have the following C# code on Win7 64bit, Visual Studio 2008.

The class is to implement a virtual ListView.

protected override void WndProc(ref Message m)
        {
            bool bHandled = false;
 
            switch (m.Msg)
            {
                case MessageId.OCM_NOTIFY:  // Reflected messages
                    NMHDR nm = (NMHDR) m.GetLParam(typeof(NMHDR));
 
                    switch (nm.code)
                    {
                       case CommCtrl.LVN_GETDISPINFO:
                            //do something
                            break;
                       case CommCtrl.LVN_ODCACHEHINT:
                            //do something
                            break;
                       case CommCtrl.LVN_ODFINDITEM:
                            //do something
                            break;
 
                     // ....

public struct NMHDR
    {
        /// <summary>hwndFrom</summary>
        public IntPtr hwndFrom;
        /// <summary>idFrom</summary>
        public int idFrom;
        /// <summary>code</summary>
        public int code;
    }

/// <summary>EXTERNALSYM LVN_FIRST</summary>
        public const int LVN_FIRST                = (0-100);    //listview
/// <summary>EXTERNALSYM LVN_ODCACHEHINT</summary>
        public const int LVN_ODCACHEHINT            = (LVN_FIRST - 13);
        /// <summary>EXTERNALSYM LVN_GETDISPINFO</summary>
        public const int LVN_GETDISPINFO            = (LVN_FIRST - 77);
        /// <summary>EXTERNALSYM LVN_ODFINDITEM</summary>
        public const int LVN_ODFINDITEM             = (LVN_FIRST - 79);

It works well when I compile it as x86 platform. The
nm.code
is sometimes -13, or -77 or -79. But the
nm.code
is always 0 when I compile as x64. In this way, the following switch code will never be executed any more. Does anyone know why this happens?
Posted 3-Feb-13 0:07am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The problem here is that the structure of NMHDR has changed for x64. The idFrom field is now IntPtr:

public struct NMHDR
    {
        /// <summary>hwndFrom</summary>
        public IntPtr hwndFrom;
        /// <summary>idFrom</summary>
        public IntPtr idFrom;
        /// <summary>code</summary>
        public int code;
    }

I recently had this issue and changing it as above got it working for me.

David
  Permalink  
Comments
234dada 19-Jan-15 3:23am
   
Thanks David. You saved me from a lot of headache. I had a similar issue running some part of the code i had written earlier in visual studio 2008 and win XP. had to move it to visual studio 2013 on windows 8.1. I used your solution and it worked perfectly. Kudos.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100