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...?![]()
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...?![]()
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.
He! He! He!
Here's the declare for that function:Notice that is asks for the class name and the window handle?! Both things that I ain't got!! Duh!Code:Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
I'll have a look at that website tho.
Ta.
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]
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
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.
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:
I think that is correctCode:FindWindow("IEFrame",vbNullString) 'vs. FindWindow(vbNullString,"VB Q and A - Reply to Topic - Microsoft Internet Explorer")![]()
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
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