ListView to HEADER RTIPE Pictures

xiaoxiao2021-03-06  101

// Declare this structure first [system.runtime.interopservices.structLayout (layoutkind.sequential, charset = charset.ansi)]

Struct HDITEM

{

Public uint mask;

Public int CXY;

Public INTPTR PSZTEXT;

// !!!!!! IF Anybody Should Know How I Can Pass A String Here Instead of An INTPTR (Which IS a Hack), please let me know !!!!!!!

Public INTPTR HBM;

Public int cchtextmax;

Public int FMT;

Public INTPTR LPARAM;

Public Int iimage;

Public IORDER;

Public uint type;

Public INTPTR PVFILTER;

}

// Put this decaration in your class [DLLIMPORT ("User32.dll", entrypoint = "sendMessage";)] public static extern INTPTR SendMessage (INTPTR HWND, INT MSG, INTPTR WPARAM, INTPTR LPARAM);

// Make a SetHeaderImageList function private void SetHeaderImageList (ListView lv, ImageList il) {// Get the header ctrl int LVM_GETHEADER = 0x1000 31; IntPtr hwndHeader = SendMessage (lv.Handle, LVM_GETHEADER, new IntPtr (0), new IntPtr ( 0); // set the imagelist of the header ctrl int hdm_setimagelist = 0x1200 8; SendMessage (HWndHeader, HDM_SetImageList, New INTPTR (0), Il.handle);}

// Make a SetHeaderImage function unsafe private void SetHeaderImage (ColumnHeader ch, int imageIndex) {// Get the header ctrl int LVM_GETHEADER = 0x1000 31; IntPtr hwndHeader = SendMessage (ch.ListView.Handle, LVM_GETHEADER, new IntPtr (0), new IntPtr (0)); // Put the image in the header uint HDI_IMAGE = 0x0020; uint HDI_FORMAT = 0x0004; int HDF_LEFT = 0; int HDF_STRING = 0x4000; int HDF_IMAGE = 0x0800; int HDM_SETITEM = 0x1200 4; hDITEM hdItem = new hDITEM (); hdItem.mask = HDI_IMAGE | HDI_FORMAT; hdItem.fmt = HDF_LEFT | HDF_STRING | HDF_IMAGE; hdItem.iImage = imageIndex; SendMessage (hwndHeader, HDM_SETITEM, new IntPtr (0), new (& hdItem) IntPtr);} Now Use these functions to set the image (set the imagelist only overce)

转载请注明原文地址:https://www.9cbs.com/read-96893.html

New Post(0)