Results 1 to 6 of 6

Thread: [RESOLVED] Form1 bring to front?

  1. #1

    Thread Starter
    Addicted Member cc2^^'s Avatar
    Join Date
    Apr 2008
    Location
    Right behind you.
    Posts
    165

    Resolved [RESOLVED] Form1 bring to front?

    is there a way to make a window (at runtime) appear all over the other windows? Or maybe let the task bar flash orange? because i want this program i am making to warn you somehow.
    I think I am, therefore, I am. I think.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form1 bring to front?

    To make it always the topmost window do
    Code:
    Option Explicit
    
    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
    
    Private Sub Form_Load()
    Call SetWindowPos(hwnd, -1, 0, 0, 0, 0, 3)
    End Sub
    Is this what you mean?

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Form1 bring to front?

    Here's a "two-way" solution:
    Code:
    Option Explicit
      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
      Private Const HWND_TOPMOST = -1
      Private Const HWND_NOTOPMOST = -2
      Private Const SWP_NOMOVE = &H2
      Private Const SWP_NOSIZE = &H1
    
    Private Sub Command1_Click()
      'set the Form to be always on top
      SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    End Sub
    
    Private Sub Command2_Click()
      'return to "normal"
      SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    End Sub
    However, another window can still steel the focus with the same procedure.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form1 bring to front?

    Or simply
    Code:
    Call SetWindowPos(hwnd, -1, 0, 0, 0, 0, 3) '- Makes the window topmost
    Call SetWindowPos(hwnd, 1, 0, 0, 0, 0, 3)  '- Makes the window normal

  5. #5
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Form1 bring to front?

    I prefer using constants because it makes your work much easier, flexible, changeable, if there's a big project involved. Try searching for a "-1" number in a 200k line project

  6. #6

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