|
-
Sep 12th, 2000, 05:45 PM
#1
How do I find a window's handle if I know what it says in the titlebar?
I assume I'd use FindWindow(Ex?) but I just can't crack it...I know I've done it in the past, but now...?
-
Sep 12th, 2000, 06:22 PM
#2
Addicted Member
GetClassName API
I dont remember for sure..but i think if you want to get a windows handle...you should use the "GetClassName" API or something... try looking for that at http://www.allapi.com i remember seeing it there b4.
Sorry i cant provide code..but like i said.. i forgot.
-
Sep 12th, 2000, 06:26 PM
#3
He! He! He!
Here's the declare for that function:
Code:
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Notice that is asks for the class name and the window handle?! Both things that I ain't got!! Duh! 
I'll have a look at that website tho. 
Ta.
-
Sep 12th, 2000, 06:47 PM
#4
Fanatic Member
Use FindWindow:
Code:
'place this code in a module
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Function GetWindowHwnd(Caption As String) As Long
If Len(Caption) = 0 Then
GetWindowHwnd = 0
Exit Function
EndIf
GetWindowHwnd = FindWindow(vbNullString,Caption)
End Function
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Sep 13th, 2000, 02:31 PM
#5
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Sub Command1_Click()
Dim hApp As Long
hApp = FindWindowEx(vbNullString, "MyAppTitle"
If hApp <> 0 Then MsgBox("The App is open")
End Sub
-
Sep 14th, 2000, 03:53 AM
#6
Cheers, people! :)
I'd sorta half figured out what to do, I just couldn't workout what I should specify for FindWindow's first argument.
I'd tried Null, Empty, "", vbNull...hadn't realised there was a vbNullString I had to use!!!
Why the heck does VB have to have so many ways of saying "Bugger All"?! 
Well... t'works now, so I'm happy. Ta.
-
Sep 14th, 2000, 07:06 AM
#7
Fanatic Member
The First Arg is Classname, almost all API's that will be left blank are either vbNullString or 0 (for numbers). You use classname if you want to get any instance, say:
Code:
FindWindow("IEFrame",vbNullString)
'vs.
FindWindow(vbNullString,"VB Q and A - Reply to Topic - Microsoft Internet Explorer")
I think that is correct
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Sep 14th, 2000, 02:40 PM
#8
FindWindowEx's arguments are somewhat out of wack. Here is a proper definition for it.
Code:
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hParent As Long, ByVal hChild As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
|