-
Nov 10th, 2000, 08:34 PM
#1
Thread Starter
New Member
Dear All:
I know this is the easy question to all of you. but i had spent alot of time to search the solution but still cannot find it. my problem is that how can i get windows' hwnd? and these windows are opened after my program. in other word, as long as my program is running, i can get all windows' hwnd which are opened after my program. is it possible? i had search this forum and find some ways to get hwnd. but these ways are for geting all hwnd, so i don;t know which one is after my program!! Anyone can help me?
thank you ver much!!
-
Nov 10th, 2000, 08:39 PM
#2
Me.hWnd <-gets your program's handle.
And you can use the FindWindow api function to get another Window's hWnd.
Code:
Private Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" (ByVal lpClassName As Any, ByVal _
lpWindowName As Any) As Long
Private Sub Command1_Click()
'Find the Calculator
hWin = FindWindow("SciCalc", "Calculator")
'hWin = FindWindow(classname,caption)
If hWin <> 0 Then
Msgbox hWin
Else
Msgbox "Window was not found!", vbCritical
End If
End Sub
-
Nov 10th, 2000, 08:44 PM
#3
Here is a code from Megatron which will get the handle of every window.
Code:
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim Length As Long
Dim sName As String
Dim Temp As String
Static iCount As Integer
iCount = iCount + 1
Length = GetWindowTextLength(hwnd) + 1
If Length > 1 Then
sName = Space(Length)
GetWindowText hwnd, sName, Length
Debug.Print Left(sName, Length - 1)
End If
EnumWindowsProc = 1
End Function
Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
-
Nov 11th, 2000, 08:42 AM
#4
Thread Starter
New Member
Dear Matthew:
Thank you very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|