2个回答
展开全部
VB 中 有句柄 hwnd 的控件,就可以通过 API 函数操作 比如 commandbutton,picturebox 没有句柄 hwnd 的控件就不可以 比如 label 通过 API 获取 commandbutton 的Captio Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Lon Private Sub Command1_Click() Dim i As Long Dim a As String i = GetWindowTextLength(Command1.hwnd) a = String$(i + 1, 0) GetWindowText Command1.hwnd, a, Len(a) Print a End Sub 显示的就是 Command1 的 属性 Caption 值: Command1
展开全部
用FindWindowEx
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Dim x
Private Sub Command1_Click()
AppActivate x
Dim NotepadHwnd As Long, hwnd As Long
NotepadHwnd = FindWindow("notepad", vbNullString)
hwnd = FindWindowEx(NotepadHwnd, 0, "Edit", vbNullString) '得到窗口类名为Edit的窗口句柄
a = PostMessage(hwnd, WM_KEYDOWN, &HBB, 0&)
' a = PostMessage(hwnd, WM_KEYUP, &HBB, 0&)
End Sub
Private Sub Form_Load()
x = Shell("notepad.exe", vbNormalFocus)
End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Dim x
Private Sub Command1_Click()
AppActivate x
Dim NotepadHwnd As Long, hwnd As Long
NotepadHwnd = FindWindow("notepad", vbNullString)
hwnd = FindWindowEx(NotepadHwnd, 0, "Edit", vbNullString) '得到窗口类名为Edit的窗口句柄
a = PostMessage(hwnd, WM_KEYDOWN, &HBB, 0&)
' a = PostMessage(hwnd, WM_KEYUP, &HBB, 0&)
End Sub
Private Sub Form_Load()
x = Shell("notepad.exe", vbNormalFocus)
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询