Results 1 to 9 of 9

Thread: Bring window to front..

  1. #1

    Thread Starter
    Fanatic Member tim_l_012's Avatar
    Join Date
    Mar 2001
    Location
    Next to a Coffee Cup.
    Posts
    641

    Red face Bring window to front..

    How do I bring the window to the front of all others??

    I dont want to use always on top api, just bring it forward, and allow it to losefocus again..

    know what i mean?

    Thanks.
    /: Tim :\____________________
    \: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/

  2. #2
    Member
    Join Date
    Mar 2002
    Location
    Montreal, Quebec
    Posts
    51

    ZOrder

    Use the ZOrder method,

    text1.ZOrder 0

    will bring the text1 text box to the front of everything else.

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Declarations:
    VB Code:
    1. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    2.  
    3. Private Const SWP_NOMOVE = 2
    4. Private Const SWP_NOSIZE = 1
    5. Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    6. Private Const HWND_TOPMOST = -1
    7. Private Const HWND_NOTOPMOST = -2
    8.  
    9. Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
    10.  
    11. On Error Goto ErrRtn
    12.  
    13. If (Topmost) Then
    14.      SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    15. Else
    16.      SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
    17.      SetTopMostWindow = False
    18. End If
    19.  
    20. Exit Function
    21. ErrRtn:
    22. MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel
    23. End Function

    To make it ontop:
    VB Code:
    1. Private Sub Form_Load()
    2. SetTopMostWindow Me.hwnd, True
    3. End Sub

    To disable, just run:
    VB Code:
    1. SetTopMostWindow Me.hwnd, False
    Last edited by TomGibbons; Apr 5th, 2002 at 01:50 PM.

  4. #4

    Thread Starter
    Fanatic Member tim_l_012's Avatar
    Join Date
    Mar 2001
    Location
    Next to a Coffee Cup.
    Posts
    641
    yeah, im using that at the moment.. the problem is that I dont want it to be over the windows taskbar...

    also, your code says:
    Code:
    SetTopMostWindow Me.hwnd, True
    and you've written the same thing for disabling it!!

    anyway, how do I bring it forward, without it appearing over the taskbar??

    Thanks,
    /: Tim :\____________________
    \: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/

  5. #5
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I am wondering why somebody not use the following code to accomplish what you are saying....

    '''''''
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


    Private Sub Timer1_Timer()
    SetForegroundWindow Me.hwnd

    End Sub

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Don't get confused by Timer control!! I just put it to check the code... just call the setForegroundwindow whenever you want to make the window in Focus...

  7. #7

    Thread Starter
    Fanatic Member tim_l_012's Avatar
    Join Date
    Mar 2001
    Location
    Next to a Coffee Cup.
    Posts
    641
    more info??

    also, would it be good to use API to make:

    1) my app on top
    2) taskbar on top

    ??

    Thanks,
    /: Tim :\____________________
    \: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/

  8. #8
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    1)
    My code will make your application on top


    2)
    to make task bar on top just get its handler through FindWindow API and then pass it in place of me.hwnd

    Any more details... ?

  9. #9

    Thread Starter
    Fanatic Member tim_l_012's Avatar
    Join Date
    Mar 2001
    Location
    Next to a Coffee Cup.
    Posts
    641
    I hope it works

    will my idea work?

    Thanks for all of your help,
    /: Tim :\____________________
    \: VB, HTML, ASP, VBScript, QBASIC, JavaScript :/

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