Sending the BM_GETSTATE message to a button retrieves information about the state of the button. This message works will all types of buttons, including command buttons, check boxes, and radio buttons.
If an error occured, the message returns zero. Otherwise, the message returns a combination of the following values specifying the button's current state:
None.
Const BM_GETSTATE = &HF2
Const BST_CHECKED = &H1
Const BST_FOCUS = &H8
Const BST_INDETERMINATE = &H2
Const BST_PUSHED = &H4
Const BST_UNCHECKED = &H0
Use the BM_GETSTATE message to determine the state of check box Check1 when a button is pressed. To run this example, you need to create a check box control named Check1 and a command button named Command1 in a form window. The check box may be any type you wish.
' 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_GETSTATE = &HF2
Public Const BST_CHECKED = &H1
Public Const BST_FOCUS = &H8
Public Const BST_INDETERMINATE = &H2
Public Const BST_PUSHED = &H4
Public Const BST_UNCHECKED = &H0
' *** Place the following code inside the form window. ***
Private Sub Command1_Click()
Dim state As Long ' checked state of the check box
' Find the state of Check1 and tell the user what it is.
state = SendMessage(Check1.hWnd, BM_GETSTATE, ByVal CLng(0), ByVal CLng(0))
If state And BST_CHECK Then
Debug.Print "The check box is checked."
ElseIf state And BST_INDETERMINATE Then
Debug.Print "The check box is in its third state (grayed)."
Else
Debug.Print "The check box is not checked."
End If
If state And BST_FOCUS Then Debug.Print "The check box has the keyboard focus."
If state And BST_PUSHED Then Debug.Print "The check box is being pushed."
End Sub
Back to the Function list.
Back to the Reference section.
Last Modified: July 30, 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_getstate.html