Results 1 to 7 of 7

Thread: [RESOLVED] [VB6] Switch to another active window.

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2008
    Location
    Milton Keynes, UK
    Posts
    49

    Resolved [RESOLVED] [VB6] Switch to another active window.

    I need to make a button that will switch the active window to a web browser that will always have the same title. I've been google'ing for it and have searched this forum but cant find an answer anywhere.

    Does anyone know a sample of code that will achieve this?

    Regards

    PsYiOn

  2. #2
    Junior Member
    Join Date
    Jun 2008
    Posts
    30

    Re: [VB6] Switch to another active window.

    Ooh any easy one...

    AppActivate "{Title}"

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    30

    Re: [VB6] Switch to another active window.

    Or for a fancy version that activates from partial title...

    http://www.freevbcode.com/ShowCode.asp?ID=526

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2008
    Location
    Milton Keynes, UK
    Posts
    49

    Re: [VB6] Switch to another active window.

    Thanks for the speedy reply, I used the non fancy version as my window name will never change but i have ran into a problem. If the user does not already have that window open then they get a runtime error. Is there a way to check its open before trying to activate it?

  5. #5
    Junior Member
    Join Date
    Jun 2008
    Posts
    30

    Re: [VB6] Switch to another active window.

    Well, you could either use the EnumWindows API to check the window exists first as per the fancy version, or the quick and dirty way would be to catch the error eg...

    On Error Goto ErrHandler
    AppActive "{Title}"
    Exit Sub
    ErrHandler:
    Msgbox "Doh!"

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2008
    Location
    Milton Keynes, UK
    Posts
    49

    Re: [VB6] Switch to another active window.

    Brilliant works well!! somthing worth noting is the non fancy code also pick up partial titles. I had it look for [VB6] and it found this window fine.

    Thanks for the help

  7. #7
    Junior Member
    Join Date
    Jun 2008
    Posts
    30

    Re: [RESOLVED] [VB6] Switch to another active window.

    Cool! Never knew that! Also, for reference, theres a FindWindow API. Saves the hassle of EnumWindows.

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