|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionI was recently tasked with figuring out a way to disable column resizing in a BackgroundWhen the Ultimately, this means that a whole host of Windows messages are being sent to the SolutionThe solution is a three step process:
Step 1The first step is easy. Remember the good ol' days of Win32 API calls? Well...they still work as well in Visual Basic .NET as they did in VB6. Put the following declarations in a scope reachable by your form load event: Private Declare Function GetWindow Lib "user32" Alias "GetWindow" _
(ByVal hwnd As IntPtr, ByVal wCmd As Integer) As IntPtr
Private Const GW_CHILD As Integer = 5
Dim SysHdr32Handle As IntPtr
and in your form load event, add the following: SysHdr32Handle = GetWindow(ListView1.Handle, GW_CHILD)
The code above assumes you've created a form window and drawn a Step 2We now need a way to intercept messages being sent to the child window. Fortunately, the .NET Framework Class Library contains a class designed especially for this purpose - the
To use the class, we need to create a new class that inherits the Private Class ListViewHeader
Inherits System.Windows.Forms.NativeWindow
Private ptrHWnd As IntPtr
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)
' We'll add this in step 3
MyBase.WndProc(m)
End Sub
Protected Overrides Sub Finalize()
Me.ReleaseHandle()
MyBase.Finalize()
End Sub
Public Sub New(ByVal ControlHandle As IntPtr)
ptrHWnd = ControlHandle
Me.AssignHandle(ptrHWnd)
End Sub
End Class
Of course, we'll need a form global variable declaration to work with, and we'll need to initialize our instance of the class. Put the following declaration in your form class declaration: Private ListViewHeader1 As ListViewHeader
Then add the following line of code to your form load event: SysHdr32Handle = _
GetWindow(ListView1.Handle, GW_CHILD) ' <-- added this in step 1
ListViewHeader1 = New ListViewHeader(SysHdr32Handle)
Step 3Now that we have a way to receive messages, we can add code to do something about them. In this simple example, we are going to intercept Protected Overrides Sub WndProc(ByRef m _
As System.Windows.Forms.Message)
Select Case m.Msg
Case Is = &H20 ' WM_SETCURSOR
m.Msg = 0
Case Is = &H201 ' WM_LBUTTONDOWN
m.Msg = 0
End Select
MyBase.WndProc(m)
End Sub
ConclusionThe above example gives you a bare-bones method of getting a handle on those
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||