PDA

Click to See Complete Forum and Search --> : Problem with FindWindow.....


Padrino
Feb 22nd, 2001, 09:39 AM
Hi, I'm trying to find a application call "browser" and close it after. But when I call the function findwindow, it doesn't work. Can you please help me...here's my code

'Declare in the general part of the project
Private Declare Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub cmdGo_Click()
MsgBox FindWindow(vbNullString, "browser")
'But the msgbox is not done....why???
End sub

THankz in advance

Vlatko
Feb 22nd, 2001, 11:13 AM
Why are you using a MBox.
MsgBox FindWindow(vbNullString, "browser")

This will only show a number (the handle).
To close the app do this:

Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

Dim handle as Long
handle = FindWindow(vbNullString, "browser")
DestroyWindow(handle)
'the window is destroyed

Padrino
Feb 22nd, 2001, 12:02 PM
I was using msgbox....just to know if the function was correct :)

Feb 22nd, 2001, 02:18 PM
Is "browser" the name of the Browser? Replace it withthe name of the browser.

Feb 22nd, 2001, 02:57 PM
Padrino, even if the caption is not correct, a message box should still appear with a 0 or any number (if it exists). It should do something, not just hang there and do nothing.

Feb 22nd, 2001, 03:16 PM
No, if the handle is found than it should be returned.

Lord Orwell
Feb 23rd, 2001, 03:24 AM
The only reason the message box shouldn't display with the code he has is:
The function is named wrong. Is Cmdgo the name of the button? If no window is found, the function will return a zero, not a null. So he should get a msgbox.

Another possibility: The caption search is case-sensitive.
If it is an actual window name, it should be "Browser"

Rh0ads
Feb 23rd, 2001, 12:31 PM
i always try to use the class because that usualy doesn't change but the caption might change if a new document is opened ect. Maybe if you use the class of "Browser" it will return something

Feb 23rd, 2001, 02:19 PM
Use Spy++ to get the class name.

Feb 23rd, 2001, 02:22 PM
Actually, as Lord Orwell mentioned, you have the declaration wrong. It should be:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long