Results 1 to 2 of 2

Thread: Detecting titlebar click event

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    england
    Posts
    1

    Question Detecting titlebar click event

    Please could anyone help, Im trying to detect a click event in the title bar, I have looked at a few suguestions but im very confused they dont seem to do what i want. Im not using mdi forms, i just want to detect an click, mouse down etc events.

  2. #2
    Megatron
    Guest
    You could subclass your window and catch the WM_NCLBUTTONDOWN event.

    Add to a Module
    VB Code:
    1. Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    2. Public 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
    3. Public Const GWL_WNDPROC = (-4)
    4. Public WinProcOld As Long
    5. Private Const WM_NCLBUTTONDOWN = &HA1
    6.  
    7. Public Function WinProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    8.     If wMsg = WM_NCLBUTTONDOWN Then
    9.         '< -- Add code here
    10.     End If
    11.    
    12.     WinProc = CallWindowProc(WinProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    13. End Function
    14.  
    15. Sub SubClassWnd(hwnd As Long)
    16.     WinProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WinProc)
    17. End Sub
    18.  
    19. Sub UnSubclassWnd(hwnd As Long)
    20.     SetWindowLong hwnd, GWL_WNDPROC, WinProcOld&
    21.     WinProcOld& = 0
    22. End Sub

    Add to a Form.
    VB Code:
    1. Private Sub Form_Load()
    2.     SubClassWnd hwnd
    3. End Sub
    4.    
    5. Private Sub Form_Unload(Cancel As Integer)
    6.     UnSubclassWnd hwnd
    7. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width