none
Overlay image not working 64bits application RRS feed

  • Question

  • I have a windows application in c#. The application is 32bits. We have used following method to set the overlay image in the treeview. The function works perfectly. Now, we have change the platform target from x86 to x64. But since then, the overlay overlay image is not set in the treeview node. It seems that the code does not work on 64bits.

    Could anybody suggest why this code works on 32bits application and not for 64bits application?

    The code neither throws any exception nor work correctly.

    Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/bb760017(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/bb773456(v=vs.85).aspx

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, IntPtr msg, IntPtr wParam, ref TVITEM lParam);
    
    private const int TVIS_OVERLAYMASK = 0x0F00;
    private const int TVIF_HANDLE = 0x08;
    private const int TVIF_STATE = 0x0F;
    
    
    
    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
    public struct TVITEM
    {
        public uint mask;
        public IntPtr hItem;
        public uint state;
        public uint stateMask;
        public IntPtr pszText;
        public int cchTextMax;
        public int iImage;
        public int iSelectedImage;
        public int cChildren;
        public IntPtr lParam;
    }
    
    public bool SetNodeOverlayImage(TreeNode node, int overlayIndex)
        {          
            try
            {
                if (overlayIndex < 0 || overlayIndex > 4)
                    return false;
    
                var tvi = new TVITEM
                              {
                                  mask = TVIF_HANDLE | TVIF_STATE, 
                                  hItem = node.Handle
                              };
    
    
                SendMessage(Handle, (IntPtr)WindowsMessages.TVM_GETITEM, IntPtr.Zero, ref tvi);
    
                uint prevState = tvi.state & TVIS_OVERLAYMASK;
    
                if (prevState == overlayIndex << 8)
                    return false;
    
                tvi.mask = TVIF_HANDLE | TVIF_STATE;
                tvi.hItem = node.Handle;
                tvi.state = (uint)overlayIndex << 8;
                tvi.stateMask = TVIS_OVERLAYMASK;
    
              SendMessage(Handle, (IntPtr)WindowsMessages.TVM_SETITEM, IntPtr.Zero, ref tvi);
    
                return true;
            }
            catch
            {}
            return false;
        }




    • Edited by pkt30 Monday, July 22, 2013 5:45 PM
    Monday, July 22, 2013 5:45 PM

Answers

  • Hi,

    According your description ,the same code works on 32bit platform ,but it doesn't  works after you change the platform x86 to x64,and the code neither throws any exception nor work correctly on 64bits.

    Based on my experience, you can try the following steps:

    1. Record log ,the log content contains the value of variables used in the SetNodeOverlayImage method. like the following code:

    public bool SetNodeOverlayImage(TreeNode node, int overlayIndex)
        {          
            try
            {
                if (overlayIndex < 0 || overlayIndex > 4)
                    return false;
                 //add log content:the value of verlayIndex and the value of (overlayIndex < 0 || overlayIndex > 4) is true or not
                var tvi = new TVITEM
                              {
                                  mask = TVIF_HANDLE | TVIF_STATE, 
                                  hItem = node.Handle
                              };
                //add log content :the value of tvi.mask and tvi.hItem
                SendMessage(Handle, (IntPtr)WindowsMessages.TVM_GETITEM, IntPtr.Zero, ref tvi);
                //add log content :the value of tvi.mask and tvi.hItem
                uint prevState = tvi.state & TVIS_OVERLAYMASK;
                //add log content :the value of prevState 
                if (prevState == overlayIndex << 8)
                    return false;
                //add log content :the value of prevState and  (prevState == overlayIndex << 8) is true or not 
                tvi.mask = TVIF_HANDLE | TVIF_STATE;
                tvi.hItem = node.Handle;
                tvi.state = (uint)overlayIndex << 8;
                tvi.stateMask = TVIS_OVERLAYMASK;
                //add log content :the value of tvi.mask and tvi.hItem and tvi.state and tvi.stateMask
              SendMessage(Handle, (IntPtr)WindowsMessages.TVM_SETITEM, IntPtr.Zero, ref tvi);
                //add log content :the value of tvi.mask and tvi.hItem and tvi.state and tvi.stateMask
                return true;
            }
            catch
            {}
            return false;
        }

    2.run the application on 32bits platform,then you will get the log1

    3.run the application on 64bits platform,then you will get the log2

    4.compare the log1 content with the log2 content,check the differences.

    Regards,

    Damon

    Tuesday, July 23, 2013 10:03 AM