BM_CLICK Message

Platforms

Description & Usage

Sending the BM_CLICK message to a button simulates the user clicking on that button. Sometimes this message will not work if the button's parent window is not active. To avoid this, use SetActiveWindow to make its parent window active before sending this message.

Return Value

This message does not return a meaningful value.

Visual Basic-Specific Issues

None.

Parameters

wParam
Not used -- set to 0.
lParam
Not used -- set to 0.

Constant Definitions

Const BM_CLICK = &HF5

Example

This code uses a Timer object to periodically check for a dialog box to appear. If found, the code uses BM_CLICK to "click" the button labeled "Resume" to close the dialog box. Something akin to this code might make a nifty way to automatically clear out those annoying "Are you still online?" dialog boxes that some ISP connection programs open every 45 minutes or so. To use this code, place a timer control named Timer1 in a window and give it a period of something like 10000 (every 10 seconds).

' 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 SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd _
	As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Public Const BM_CLICK = &HF5
Public Declare Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal _
	lpClassName As Any, ByVal lpWindowName As Any) As Long
Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal _
	hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As Any, _
	ByVal lpszWindow As Any) As Long

' *** Place the following code in the form. ***
Private Sub Timer1_Timer()
	Dim hwndDialog As Long  ' handle to the dialog box
	Dim hwndButton As Long  ' handle to the Resume button
	Dim retval As Long      ' return value
	
	' First, see if the dialog box (titled "Inactivity Warning" is currently open.
	hwndDialog = FindWindow(CLng(0), "Inactivity Warning")
	If hwndDialog = 0 Then Exit Sub
	
	' Now get a handle to the "Resume" button in the dialog.
	hwndButton = FindWindowEx(hwndDialog, 0, CLng(0), "Resume")
	
	' After making sure that the dialog box is the active window, click "Resume".
	retval = SetActiveWindow(hwndDialog)
	retval = SendMessage(hwndButton, BM_CLICK, ByVal CLng(0), ByVal CLng(0))
End Sub

Category

Buttons

Back to the Messagelist.
Back to the Reference section.


Last Modified: October 29, 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/b/bm_click.html