0
我們在c#中有一個Windows應用程序。該應用程序是32位。我們使用以下方法在樹視圖中設置疊加圖像。該功能完美工作。 現在,我們已將平臺目標從x86更改爲x64。但從那時起,覆蓋圖覆蓋圖像未在樹視圖節點中設置。看起來代碼在64位上不起作用。覆蓋圖像不工作64位應用程序
有人可以建議爲什麼這個代碼在32位應用程序,而不是64位應用程序?
代碼既不會引發任何異常,也不會正常工作。
編號: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;
}
感謝。
你真了不起:)它的作品。感謝Hans。 – Prakash