28. januar 2008 - 19:02Der er
1 kommentar og 1 løsning
Find flere hWnd efter titel/window-class
Hejsa Eksperter :)
Jeg prøver at finde hWnd for 2 programmer. Programmerne har den sammen window-class og samme titel, men jeg kan stadig kun finde hWnd for en af programmerne med den kode jeg har fundet. Jeg har forgæves forsøgt at rette programmet til, og søger derfor efter hjælp til, hvordan jeg ellers kan finde de 2 hWnd's! :)
Hvis der er nogen, som har et forslag til hvordan dette kan findes (helst ud fra window-class), så vil jeg gladeligt tage imod hjælp :D
Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" _ (ByVal hWnd As Long, _ ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _ Alias "GetWindowTextA" _ (ByVal hWnd As Long, _ ByVal lpString As String, _ ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" _ Alias "GetClassNameA" _ (ByVal hWnd As Long, _ ByVal lpClassName As String, _ ByVal nMaxCount As Long) As Long
Public Function FindWindowLike(hWndArray() As Long, _ ByVal hWndStart As Long, _ WindowText As String, _ Classname As String) As Long
Dim hWnd As Long Dim sWindowText As String Dim sClassname As String Dim r As Long
'Hold the level of recursion and 'hold the number of matching windows Static level As Long Static found As Long
'Initialize if necessary If level = 0 Then found = 0 ReDim hWndArray(0 To 0) If hWndStart = 0 Then hWndStart = GetDesktopWindow() End If
'Increase recursion counter level = level + 1
'Get first child window hWnd = GetWindow(hWndStart, GW_CHILD)
Do Until hWnd = 0
'Search children by recursion Call FindWindowLike(hWndArray(), hWnd, WindowText, Classname)
'Get the window text and class name sWindowText = Space(255) r = GetWindowText(hWnd, sWindowText, 255) sWindowText = Left(sWindowText, r)
'Get next child window hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop
'Decrement recursion counter level = level - 1
'Return the number of windows found FindWindowLike = found
End Function
Og funktionen kaldes således: Call FindWindowLike(hWnds(), 0, strWindowTitle, strWindowClass)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.