如何操作CheckBox?
今日在搞外挂。用Button类型获得CheckBox句柄后,不知道如何获得该CheckBox是否是Checked。
还有如何用API来设置CheckBox的Checked值?
请高手现身!!! --------------------编程问答-------------------- 用 Windows 消息 --------------------编程问答--------------------
--------------------编程问答-------------------- 除
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
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_GETCHECK = &HF0
Public Const BM_SETCHECK = &HF1
Public Const BST_CHECKED = &1
Public Const BST_INDETERMINATE = &2
Public Const BST_UNCHECKED = &0
' *** Place the following code inside the form window. ***
Private Sub Command1_Click()
Dim hwnd As Long
Dim xHwnd As Long
Dim state As Long ' checked state of the check box
hwnd = FindWindow(vbNullString, "form1")
If hwnd = 0 Then
MsgBox "没有找到完全窗口句柄"
Else
xHwnd = FindWindowEx(hwnd, 0&, vbNullString, "Check1")
If xHwnd = 0 Then
MsgBox "没有找到子窗口句柄 "
Else
' Find the checked state of Check1 and tell the user what it is.
state = SendMessage(xHwnd, BM_GETCHECK, ByVal CLng(0), ByVal CLng(0))
Select Case state
Case BST_CHECKED
Debug.Print "The check box is checked."
Case BST_INDETERMINATE
Debug.Print "The check box is in its third state (grayed)."
Case BST_UNCHECKED
Debug.Print "The check box is not checked."
End Select
End If
End If
End Sub
Private Sub Command2_Click()
Dim hwnd As Long
Dim xHwnd As Long
hwnd = FindWindow(vbNullString, "form1")
If hwnd = 0 Then
MsgBox "没有找到完全窗口句柄"
Else
xHwnd = FindWindowEx(hwnd, 0&, vbNullString, "Check1")
If xHwnd = 0 Then
MsgBox "没有找到子窗口句柄 "
Else
SendMessage xHwnd, BM_SETCHECK, ByVal CLng(BST_CHECKED), ByVal CLng(0)
End If
End If
End Sub
补充:VB , API