Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Windows Hwnd句柄选择文件_Vb.net_Hwnd - Fatal编程技术网

Vb.net Windows Hwnd句柄选择文件

Vb.net Windows Hwnd句柄选择文件,vb.net,hwnd,Vb.net,Hwnd,我有一个web应用程序,它可以成功访问页面并单击“上载文件”按钮 我的应用程序还通过监视和挂接弹出窗口成功地处理它们。在大多数情况下,只需单击“确定”或“取消”按钮。按钮很容易 我需要的帮助是“选择文件”对话框。我很好地勾住了它,但是有很多控制,我需要一些方向 这些是其上的子控件: DUIViewWndClassName,DirectUIHWND,CtrlNotifySink,NamespaceTreeControl,Static,SysTreeView32,CtrlNotifySink,Sh

我有一个web应用程序,它可以成功访问页面并单击“上载文件”按钮

我的应用程序还通过监视和挂接弹出窗口成功地处理它们。在大多数情况下,只需单击“确定”或“取消”按钮。按钮很容易

我需要的帮助是“选择文件”对话框。我很好地勾住了它,但是有很多控制,我需要一些方向

这些是其上的子控件:

DUIViewWndClassName,DirectUIHWND,CtrlNotifySink,NamespaceTreeControl,Static,SysTreeView32,CtrlNotifySink,Shell Preview Extension Host,CtrlNotifySink,SHELLDLL_DefView,DirectUIHWND,CtrlNotifySink,ScrollBar,CtrlNotifySink,ScrollBar,Static,Static,Static,ListBox,Static,Static,ComboBoxEx32,ComboBox,Edit,Static,ComboBox,Button,Button,Button,ScrollBar,WorkerW,ReBarWindow32,TravelBand,ToolbarWindow32,Address Band Root,msctls_progress32,Breadcrumb Parent,ToolbarWindow32,ToolbarWindow32,UniversalSearchBand,Search Box,SearchEditBoxWrapperClass,DirectUIHWND
我很乐意将一个精确的路径/文件粘贴到文件名文本框/组合框中,然后单击“打开”。按钮部分很简单,但我不知道如何在窗口中选择文件,和/或如何将路径放入文件名输入字段

现在我有这样的事情:

<DllImport("user32.dll")> _
Private Shared Function GetClassName(ByVal hWnd As IntPtr, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Int32) As Int32
End Function

<DllImport("user32.dll")> _
Private Shared Function GetWindowText(ByVal hWnd As IntPtr, ByVal text As StringBuilder, ByVal maxLength As Int32) As Int32
End Function

<DllImport("user32.dll")> _
Private Shared Function GetDlgCtrlID(ByVal hwndCtl As IntPtr) As Integer
End Function

....

Private Shared Function hwndHandler() As Int32
    Dim ptrButtonhwnd As IntPtr

    For Each pChild As IntPtr In Interop.ChildWindows(pPopup.hwnd)
        Dim sbControl As New StringBuilder(255)
        GetClassName(pChild, sbControl, sbControl.Capacity)
        If "Button".Equals(sbControl.ToString()) Then
            Dim sbText As New StringBuilder(255)
            GetWindowText(pChildOfDialog, sbText, sbText.Capacity)
            If "&Open".Equals(sbText.ToString()) Then
                ptrButtonHwnd = pChild
            End If
        End If
    Next

    If ptrButtonHwnd <> IntPtr.Zero Then
        Dim ctrlId As Int32 = GetDlgCtrlID(ptrButtonHwnd)
        SendMessage(pPopup.hwnd, WM_COMMAND, New IntPtr(ctrlId), ptrButtonHwnd)
        Return 1
    End If

Return 0
End Function
_
私有共享函数GetClassName(ByVal hWnd作为IntPtr,ByVal lpClassName作为StringBuilder,ByVal nMaxCount作为Int32)作为Int32
端函数
_
私有共享函数GetWindowText(ByVal hWnd作为IntPtr,ByVal text作为StringBuilder,ByVal maxLength作为Int32)作为Int32
端函数
_
私有共享函数GetDlgCtrlID(ByVal hwndCtl作为IntPtr)作为整数
端函数
....
私有共享函数hwndHandler()作为Int32
调暗ptrButtonhwnd为IntPtr
对于Interop.ChildWindows(pPopup.hwnd)中作为IntPtr的每个pChild
Dim sbControl作为新的StringBuilder(255)
GetClassName(pChild、sbControl、sbControl.Capacity)
如果“Button.”等于(sbControl.ToString()),则
将sbText标注为新的StringBuilder(255)
GetWindowText(pChildOfDialog、sbText、sbText.Capacity)
如果“&Open.”等于(sbText.ToString()),则
ptrButtonHwnd=pChild
如果结束
如果结束
下一个
如果ptrButtonHwnd IntPtr.Zero,则
Dim ctrlId As Int32=GetDlgCtrlID(ptrButtonHwnd)
SendMessage(pPopup.hwnd,WM_命令,新的IntPtr(ctrlId),ptrButtonHwnd)
返回1
如果结束
返回0
端函数

这很好,但我需要添加一些东西来选择要打开的文件,或者将其输入文本/组合字段,或者在窗口中选择它。

我发现答案是查找文本为“Edit”的控件,这是我原始列表中列出的控件之一

因此,根据上面发布的代码,我创建了一个新指针
ptrEdit
,并将控件分配给它,其中
“Edit”.Equals(sbControl.ToString())

然后为了操纵它,我使用了一个DLL:

If ptrEdit <> IntPtr.Zero Then
    SetWindowText(pEditHwnd, strFilePath)
    If ptrButtonHwnd <> IntPtr.Zero Then
        Dim ctrlId As Int32 = GetDlgCtrlID(ptrButtonHwnd)
        SendMessage(cwp.hwnd, WM_COMMAND, New IntPtr(ctrlId), ptrButtonHwnd)
        Return 1
    End If
End If
如果ptrEdit IntPtr.Zero,则
SetWindowText(pEditHwnd、strFilePath)
如果ptrButtonHwnd IntPtr.Zero,则
Dim ctrlId As Int32=GetDlgCtrlID(ptrButtonHwnd)
SendMessage(cwp.hwnd、WM_命令、新IntPtr(ctrlId)、ptrButtonHwnd)
返回1
如果结束
如果结束
所以我可以控制“选择上传文件”对话框