Results 1 to 7 of 7

Thread: Force Window To Top

  1. #1

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Force Window To Top

    In response to a wash out in another thread (that's been closed) this should solve your problem:

    VB Code:
    1. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
    2. Private Declare Function GetForegroundWindow Lib "user32" () As Long
    3. Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
    4. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
    5.  
    6. Public Sub ForceWindowToTop(hWnd As Long)
    7.    
    8.     Dim lMyPId As Long
    9.     Dim lCurPId As Long
    10.    
    11.     lMyPId = GetWindowThreadProcessId(hWnd, 0)
    12.     lCurPId = GetWindowThreadProcessId(GetForegroundWindow(), 0)
    13.    
    14.     If Not (lMyPId = lCurPId) Then
    15.         AttachThreadInput lCurPId, lMyPId, True
    16.         SetForegroundWindow hWnd
    17.         AttachThreadInput lCurPId, lMyPId, False
    18.     End If
    19.    
    20.     If Not (GetForegroundWindow() = hWnd) Then
    21.         SetForegroundWindow hWnd
    22.     End If
    23.    
    24. End Sub

    NEVER say never . . .

    Yr

  2. #2

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    Apologies.

    I should read more carefully . . .

    Sorry!

  3. #3
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Is this a question of some sort?

    Otherwise it belongs in the Codebank

  4. #4

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    Let someone else do and collect the credit for it . . .




  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    You could go through the entire forum and collect credit for code that people have written

    believe it or not, pretty much everything's been posted before

    except for a few highly specialised questions

    skilled searchers will rarely ask questions

  6. #6
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Re: Force Window To Top

    Greetings and Salutations!

    Do not care where it was posted.... just glad it was. This worked perfectly!
    Steve Stunning

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Force Window To Top

    What does:
    Code:
    Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
    Do?

    Woka

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