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.
Printable View
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.
To make it always the topmost window doIs this what you mean?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
Here's a "two-way" solution:However, another window can still steel the focus with the same procedure.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
Or simplyCode: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
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 ;)