|
-
Feb 22nd, 2001, 10:39 AM
#1
Thread Starter
Member
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
-
Feb 22nd, 2001, 12:13 PM
#2
Frenzied Member
Why are you using a MBox.
MsgBox FindWindow(vbNullString, "browser")
This will only show a number (the handle).
To close the app do this:
Code:
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
-
Feb 22nd, 2001, 01:02 PM
#3
Thread Starter
Member
I was using msgbox....just to know if the function was correct
-
Feb 22nd, 2001, 03:18 PM
#4
Is "browser" the name of the Browser? Replace it withthe name of the browser.
-
Feb 22nd, 2001, 03:57 PM
#5
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, 04:16 PM
#6
No, if the handle is found than it should be returned.
-
Feb 23rd, 2001, 04:24 AM
#7
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"
-
Feb 23rd, 2001, 01:31 PM
#8
Addicted Member
what about the class?
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, 03:19 PM
#9
Use Spy++ to get the class name.
-
Feb 23rd, 2001, 03:22 PM
#10
Actually, as Lord Orwell mentioned, you have the declaration wrong. It should be:
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (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
|