0/5 (2 avis)
Snippet vu 11 533 fois - Téléchargée 31 fois
//COPYRIGHT Original author .... public class NotResizableListView: ListView { #region Interop #region Consts const int LVM_FIRST = 0x1000; const int LVM_GETHEADER = LVM_FIRST + 31; const int HDM_FIRST = 0x1200; const int HDM_HITTEST = HDM_FIRST + 6; const int HHT_ONDIVIDER = 0x0004; const int WM_SETCURSOR = 0x0020; const int WM_LBUTTONDOWN = 0x0201; #endregion Consts [StructLayout(LayoutKind.Sequential)] struct HDHITTESTINFO { public Point pt; public int flags; public int iItem; } [DllImport("User32.dll")] static extern int SendMessage(IntPtr hWnd, int uMsg, IntPtr wParam, IntPtr lParam); #endregion Interop protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); //Recupere l'objet columnheader. IntPtr hHeader = (IntPtr)SendMessage(Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero); ColumnHeader nativeWindow = new ColumnHeader(hHeader); } private class ColumnHeader : NativeWindow { public ColumnHeader(IntPtr hHeader) { this.AssignHandle(hHeader); } protected override void WndProc(ref Message m) { switch(m.Msg) { case WM_SETCURSOR: // Pas de changement de curseur return; case WM_LBUTTONDOWN: Int16 x = (Int16)m.LParam; Int16 y = (Int16)((int)m.LParam >> 16); // Recuepere la position du cursor Point cursorPosition = new Point(x, y); HDHITTESTINFO hitInfo = new HDHITTESTINFO(); hitInfo.pt = cursorPosition; IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(hitInfo)); Marshal.StructureToPtr(hitInfo, buffer, true); //Declenche le hit, permet l'execution des autres actions lié au click sur le header SendMessage(m.HWnd, HDM_HITTEST, IntPtr.Zero, buffer); hitInfo = (HDHITTESTINFO)Marshal.PtrToStructure(buffer, typeof(HDHITTESTINFO)); Marshal.FreeHGlobal(buffer); if (hitInfo.flags == HHT_ONDIVIDER) //On est sur le separateur donc pas d'action return; break; } base.WndProc(ref m); } } }
17 mars 2006 à 14:31
Le using qui manque naturellement est le using System.Runtime.InteropServices;
Celà paraissait logique.
17 mars 2006 à 13:21
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.