vb.net 获取【打开】文件夹句柄 10C

想用一个程序操作【程序1】操作另一个程序【程序2】中的控件,之前都挺顺利的,但是:当程序2中的 按钮【...】通过程序1点开后,无法获取当前【打开文件夹】的句柄??好像程序卡在【SendMessage(hwnd12, BM_CLICK, 0, 0)】代码和程序窗体 请见图片,谢谢。。请给位帮帮忙。。

补充: 我手动先把【程序2】的子窗口打开后,利用【程序1】就能获取其子窗口的句柄。

 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    '此函数用于寻找其他程序的句柄。这里用来寻找音量控制系统的窗口句柄。
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
    '此函数用于寻找其他程序的控件句柄。
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    '此函数用于向窗体及控件发送消息。

    Private Const BM_CLICK As Integer = &HF5

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim hwnd0 As Integer '主窗口句柄
        Dim hwnd00 As Integer '字窗口句柄
        Dim hwnd11 As Integer '控件句柄 第一个...
        Dim hwnd12 As Integer '控件句柄 第二个...

        hwnd0 = FindWindow(vbNullString, "PPT") '获取主窗体句柄

        hwnd11 = FindWindowEx(hwnd0, 0, "Button", "...") '获取句柄  ,Button
        hwnd12 = FindWindowEx(hwnd0, hwnd11, "Button", "...") '获取句柄,Button
        SendMessage(hwnd12, BM_CLICK, 0, 0) '点击控件


        hwnd00 = FindWindow("#32770", "打开")

        TextBox2.Text = hwnd00


    End Sub

图片说明
图片说明

1个回答

用spy++看下窗体的层次关系,还有窗口类是否正确。

wslnjut
拉风的Lee 感谢你的回答! 我查过都是正确的! 问题是 我手动先把【程序2】的子窗口打开后,利用【程序1】就能获取其句柄?
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐