Gord
Hello,
Anybody know how to detect when a user drags between columns in a
MSHFlexGrid when resizing column width? (Short of setting up a timer event
that continuously monitors column width.) MouseDown, MouseUp, MouseMove,
MouseIcon etc. all seem to be 'blind' when my mouse cursor changes to the
horizontal double headed arrow for column resizing. No events seem to be
triggered when the mouse pointer is in this state?
Put the following into a bas module.
' from ExtremeVBTalk - get a notification when the grid columns have been resized
' B Chernyachuk 1999 -
Bo****@hotmail.com
'
Public g_lngDefaultHandler As Long ' Original handler of the grid events
Private m_bLMousePressed As Boolean 'true if the left button is pressed
Private m_bLMouseClicked As Boolean 'true just after the click (i.e. just after the left button is released)
'API declarations ================================================== ==========
' Function to retrieve the address of the current Message-Handling routine
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
' Function to define the address of the Message-Handling routine
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As
Long) As Long
' Function to execute a function residing at a specific memory address
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg
As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Windows messages constants
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_ERASEBKGND = &H14
'this is our event handler
Public Function GridMessage(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
If m_bLMousePressed And Msg = WM_LBUTTONUP Then
'button have been just released
m_bLMousePressed = False
m_bLMouseClicked = True
End If
If Not (m_bLMousePressed) And Msg = WM_LBUTTONDOWN Then
'button have been just pressed
m_bLMousePressed = True
m_bLMouseClicked = False
End If
If m_bLMouseClicked And (Msg = WM_ERASEBKGND) Then
'Only when resize happens this event may occur after releasing the button !
'When user is making a simple click on grid,
'the WM_ERASEBKGND event occurs before WM_LBUTTONUP,
'and therefore will not be handled there
Debug.Print "Grid message: ", "Resized !" 'TO DO: Replace this futile code
'with something usefull
m_bLMouseClicked = False
End If
'call the default message handler
GridMessage = CallWindowProc(g_lngDefaultHandler, hwnd, Msg, wp, lp)
End Function
Put the following into a form:
' This constant is used to refer to the Message Handling function in a given window
Private Const GWL_WNDPROC = (-4)
In your form_load:
' setup the handler for knowing when the user has resized the grid columns
'Save the address of the existing Message Handler
g_lngDefaultHandler = GetWindowLong(MSFlexgrid.hwnd, GWL_WNDPROC)
'Define new message handler routine
Call SetWindowLong(MSFlexgrid.hwnd, GWL_WNDPROC, AddressOf GridMessage)
Then, when the user resizes the grod columns, the code in the GridMessage function will run.
Replace the
Debug.Print "Grid message: ", "Resized !" 'TO DO: Replace this futile code
'with something usefull
code with whatever you need to do when the user resizes the column.
* IMPORTANT *
In your form_unload:
'Return the old grid message handler back
Call SetWindowLong(MSFlexgrid.hwnd, GWL_WNDPROC, g_lngDefaultHandler)
Always remember to restore the original handler (as above) before the form gets destroyed.
Regards
Brad