Results 1 to 3 of 3

Thread: OK, set forground window problem?

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    OK, set forground window problem?

    Hey,
    OK, if there is already a copy of my application open, i wanna bring that copy to the front,

    and then unload the new copy.

    Now, it is making the screen flicker, but nothing other then that happens...

    should this work?

    My app's form caption is "[" & webbrowser PageTitle & "] - The Walks Chat"

    so is there something im doing wrong with this, since it dont work proper?


    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    3.  
    4. Private Sub Form_Load()
    5.  
    6.     If App.PrevInstance = True Then GoTo PrevInst:
    7.  
    8. ' Some code here
    9.  
    10. Exit Sub
    11. PrevInst:
    12.     ' Theres a previous open copy of the application,
    13.     ' so lets bring that copy to the front, and unload this copy
    14.     Dim WinHan As Long
    15.     WinHan = FindWindow(vbNullString, " - The Walks Chat")
    16.     WinHan = SetForegroundWindow(WinHan)
    17.     Unload Me
    18. Exit Sub
    19. ' More Sub's ETC
    20. End Sub
    Wayne

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    There are a couple of problems:

    1. You're checking from within a Form, so it would find the form
    you're checking from first. You can use findWindowEx() to
    search for the next matching window.

    2. FindWindow/Ex do not do partial caption matching.
    You will need to implement your own function which scans all form
    captions looking for a match. (Look at the EnumWindows callback function API.)

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    OK, Tnx for the info.

    BTW: if i have a form open VBModal to the owning window .. will it bring it forwards then?
    Wayne

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