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;
}