MSHFlexGrid column resizing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gord

    #1

    MSHFlexGrid column resizing

    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?

    Thanks,

    Gord


  • Brad Thomas

    #2
    Re: MSHFlexGrid column resizing

    Gord
    [color=blue]
    > 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?[/color]

    Put the following into a bas module.

    ' from ExtremeVBTalk - get a notification when the grid columns have been resized
    ' B Chernyachuk 1999 - BodyaC@hotmail. com
    '
    Public g_lngDefaultHan dler As Long ' Original handler of the grid events
    Private m_bLMousePresse d As Boolean 'true if the left button is pressed
    Private m_bLMouseClicke d 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 "CallWindowProc A" (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(ByV al hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long

    If m_bLMousePresse d And Msg = WM_LBUTTONUP Then
    'button have been just released
    m_bLMousePresse d = False
    m_bLMouseClicke d = True
    End If

    If Not (m_bLMousePress ed) And Msg = WM_LBUTTONDOWN Then
    'button have been just pressed
    m_bLMousePresse d = True
    m_bLMouseClicke d = False
    End If

    If m_bLMouseClicke d 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_bLMouseClicke d = False

    End If

    'call the default message handler
    GridMessage = CallWindowProc( g_lngDefaultHan dler, 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_lngDefaultHan dler = GetWindowLong(M SFlexgrid.hwnd, GWL_WNDPROC)

    'Define new message handler routine
    Call SetWindowLong(M SFlexgrid.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(M SFlexgrid.hwnd, GWL_WNDPROC, g_lngDefaultHan dler)


    Always remember to restore the original handler (as above) before the form gets destroyed.

    Regards

    Brad

    Comment

    Working...