|
-
May 22nd, 2009, 05:14 AM
#1
Thread Starter
Addicted Member
[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.
-
May 22nd, 2009, 05:49 AM
#2
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?
-
May 22nd, 2009, 06:15 AM
#3
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.
-
May 22nd, 2009, 07:03 AM
#4
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
-
May 22nd, 2009, 07:08 AM
#5
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
-
May 22nd, 2009, 07:28 AM
#6
Re: Form1 bring to front?
 Originally Posted by gavio
I prefer using constants because it makes your work much easier...
And safer too. It's easy enough to change value in one place so entire project gets affected.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|