vb如何通过外部程序窗口句柄和控件id获取控件内容

请不要复制网上的答案,我需要直接的代码... 请不要复制网上的答案,我需要直接的代码 展开
 我来答
You136999
2019-01-23 · TA获得超过307个赞
知道小有建树答主
回答量:537
采纳率:78%
帮助的人:75万
展开全部
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
l7722526
2019-01-23 · TA获得超过2.7万个赞
知道大有可为答主
回答量:2.8万
采纳率:84%
帮助的人:3787万
展开全部
用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
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式