2013-01-23 150 views
1

的標題我手柄的所有Child Windows
現在我想通過手柄讓每一個子窗口的標題。
我的代碼:獲取手柄

For Each p As Process In Process.GetProcessesByName("MyProccess") 
      Dim ChildrenList As New List(Of IntPtr) 
      ChildrenList = GetChildWindows(p.MainWindowHandle) 
      MsgBox(ChildrenList.Count) ' = 343 
      For Each hh As IntPtr In ChildrenList 

       ' i want to do something like: MsgBox(getCaption(hh)) 

      Next 
     Next 

我該怎麼辦呢?

+0

你見過這個網站嗎? http://pinvoke.net/ – WraithNath

+0

你的意思是你想'FindWindow'標題? – spajce

+0

@WraithNath當然,我看到了這個網站。 – sthml

回答

1

你可以得到一個窗口的標題與GetWindowText功能。你需要對它進行p/invoke。你可以在pinvoke.net找到這個示例代碼。

1

來源#1 & #2


通過字幕我希望你的意思是你已經創建的子窗口的窗口句柄列表 「窗口標題文本」

休息會很容易

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ 
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer 
    End Function 
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ 
Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer 
    End Function 

    Public Function GetText(ByVal hWnd As IntPtr) As String 
     Dim length As Integer 
     If hWnd.ToInt32 <= 0 Then 
      Return Nothing 
     End If 
     length = GetWindowTextLength(hWnd) 
     If length = 0 Then 
      Return Nothing 
     End If 
     Dim sb As New System.Text.StringBuilder("", length + 1) 

     GetWindowText(hWnd, sb, sb.Capacity) 
     Return sb.ToString() 
    End Function 

用法:

For Each p As Process In Process.GetProcessesByName("MyProccess") 
      Dim ChildrenList As New List(Of IntPtr) 
      ChildrenList = GetChildWindows(p.MainWindowHandle) 
      MsgBox(ChildrenList.Count) ' = 343 
      For Each hh As IntPtr In ChildrenList 

       Dim caption As String = GetText(hh) 
       ' use the caption the way u want 

      Next 
     Next 
+1

請不要從其他來源不歸屬複製代碼。這確實是非常糟糕的形式。 –

+0

對不起! &THNX提醒! –