【问题标题】:Windows Hwnd Handle Choose FileWindows Hwnd 句柄选择文件
【发布时间】:2013-06-27 16:10:39
【问题描述】:

我有一个网络应用程序可以成功访问一个页面并单击“上传文件”按钮。

我的应用还通过监视和挂钩来成功处理弹出窗口。大多数情况下,只需单击“确定”或“取消”按钮。按钮很简单。

我需要帮助的是选择文件对话框。我挂得很好,但是上面有很多控件,我需要一些指导。

这些是上面的子控件:

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

我很乐意将确切的路径/文件粘贴到文件名文本框/组合框中并单击“打开”。按钮部分很简单,但我不知道如何在窗口中选择文件,和/或如何将我的路径放入 File-Name 输入字段。

现在我有这样的东西:

<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

这很好用,但我需要添加一些内容来选择要打开的文件,方法是在文本/组合字段中输入文件,或者在窗口中选择它。

【问题讨论】:

    标签: vb.net hwnd


    【解决方案1】:

    我发现答案是寻找带有“编辑”文本的控件,这是我原始列表中列出的控件之一。

    所以根据我上面贴出的代码,我新建了一个指针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
    

    所以我能够控制“选择要上传的文件”对话框。

    【讨论】:

      猜你喜欢
      • 2012-01-15
      • 2011-06-16
      • 2021-04-20
      • 2011-06-13
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多