2013-06-27 7 views
0

J'ai une application Web qui parvient à une page et clique sur un bouton "Télécharger le fichier".Windows Hwnd Handle Choisissez le fichier

Mon application gère également avec succès les fenêtres contextuelles en les surveillant et en les accrochant. Pour la plupart, c'est juste pour cliquer sur les boutons "OK" ou "Annuler". Les boutons sont faciles.

Ce dont j'ai besoin d'aide, c'est la boîte de dialogue Choisir un fichier. J'y vais très bien, mais il y a beaucoup de contrôles et j'ai besoin de direction.

Choose File Dialog Example

Ce sont les contrôles enfants sur elle:

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 

Je serais heureux avec coller un chemin/fichier exact dans la zone de texte/combobox nom de fichier et cliquez sur « Ouvrir ». La partie bouton est facile, mais je ne sais pas non plus comment sélectionner les fichiers dans la fenêtre, et/ou comment placer mon chemin dans le champ de saisie Nom du fichier.

En ce moment, j'ai quelque chose comme ceci:

<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 

Cela fonctionne très bien, mais je dois ajouter quelque chose pour sélectionner un fichier à ouvrir soit en entrant dans le champ texte/combo, ou en le sélectionnant dans la fenêtre.

Répondre

1

J'ai trouvé la réponse était de chercher un contrôle avec le texte de "Modifier", qui était l'un des contrôles énumérés dans ma liste originale. Donc selon mon code affiché ci-dessus, j'ai fait un nouveau pointeur ptrEdit, et lui a assigné le contrôle où "Edit".Equals(sbControl.ToString()).

ensuite de le manipuler, je l'une des 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 

Et donc je suis en mesure de contrôler le « Choisissez le fichier à télécharger » boîte de dialogue.

+0

+1. Merci de partager votre solution avec la communauté. – Neolisk

Questions connexes