Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# 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  

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

  Print Answers RSS
0 OriginalGriff 300
1 Sergey Alexandrovich Kryukov 176
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
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