Results 1 to 10 of 10

Thread: Problem with FindWindow.....

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Hellmer/Quebec/Canada
    Posts
    32

    Unhappy

    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

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Hellmer/Quebec/Canada
    Posts
    32
    I was using msgbox....just to know if the function was correct
    Forza Scuderia Ferrari

  4. #4
    Guest
    Is "browser" the name of the Browser? Replace it withthe name of the browser.

  5. #5
    Guest
    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.

  6. #6
    Guest
    No, if the handle is found than it should be returned.

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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"
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  8. #8
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    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
    < o >

  9. #9
    Guest
    Use Spy++ to get the class name.

  10. #10
    Guest
    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
  •  



Click Here to Expand Forum to Full Width