Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleKeep track of the last control to have the focus before a button is pressed
Keywordsfocus, button
CategoriesAPI
 
Subclass and watch for WM_SETCURSOR messages for the buttons. If the currently active control is not a button, save its name so you can tell that control had the focus later.
 
' Process Windows messages.
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) As _
    Long
Const WM_SETCURSOR = &H20

    ' See if this is a WM_SETCURSOR message.
    If msg = WM_SETCURSOR Then
        ' See if the message is for a button.
        If wParam = Form1.Command1.hwnd Or _
           wParam = Form1.Command2.hwnd _
        Then
            ' It is a button. See if the active
            ' control is not a button. Don't save
            ' the name of a button (in case the
            ' user clicks a button twice).
            If Not (TypeOf Screen.ActiveControl Is _
                CommandButton) Then
                gFocusControl = Screen.ActiveControl.Name
            End If
        End If
    End If

    ' Process the message normally.
    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
 
See also Keep track of the last control to have the focus.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated