Declare Function GetCapture Lib "user32.dll" () As Long
GetCapture identifies which window currently has captured the mouse input, if any. However, this function only works if a window owned by the calling thread; if another program's window has captured the mouse, this function will not work.
If a window owned by the calling thread has captured the mouse, the function returns a handle to that window. If no thread window has captured the mouse, the function returns 0.
None.
None.
If a window owned by the program has captured the mouse input, display its caption. If not, inform the user that no program window has captured the mouse. The capture is checked when the user clicks button Command1. To use this example, you must first place a command button named Command1 on a form window.
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function GetCapture Lib "user32.dll" () As Long
Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd _
As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" _
(ByVal hWnd As Long) As Long
' *** Place the following code inside a form window. ***
Private Sub Command1_Click()
Dim hWndCapture As Long ' handle to the window that captured the mouse
Dim wintext As String ' receives the text of the capturing window
Dim slength As Long ' the length of that string
' First, see if a thread window has even captured the mouse.
hWndCapture = GetCapture()
If hwndCapture = 0 Then
Debug.Print "This program has not captured the mouse."
Else
' Get the capturing window's text and display it.
slength = GetWindowTextLength(hWndCapture) + 1
wintext = Space(slength)
slength = GetWindowText(hWndCapture, wintext, slength)
wintext = Left(wintext, slength)
Debug.Print "The window " & Chr(34) & wintext & Chr(34) & " has captured the mouse."
End If
End Sub
Back to the Function list.
Back to the Reference section.
Last Modified: August 26, 2000
This page is copyright © 2000 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getcapture.html