How do I get my application on top?
To force a form to the front of the screen, use the following command:
Form1.ZOrder
To make the application stay on top, put the Zorder command in a Timer event repeatedly called, say every 1000 msecs. This makes a "softer" on-top than other methods, and allows the user to make a short peek below the form.
There are two different "Zorder"'s of forms in Windows, both implemented internally as linked lists. One is for "normal" windows, the other for real "topmost" windows (like the Clock application which is distributed with MS Windows). The Zorder command above simply moves your window to the top of the "normal" window stack. To make your window truly topmost, use the SetWindowPos API call like this:
'Make these declares: Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos"_ (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 Global Const SWP_NOMOVE = 2 Global Const SWP_NOSIZE = 1 Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Global Const HWND_TOPMOST = -1 Global Const HWND_NOTOPMOST = -2
'To set Form1 as a TopMost form, do the following:
res& = SetWindowPos (Form1.hWnd, HWND_TOPMOST, _ 0, 0, 0, 0, FLAGS) 'if res&=0, there is an error
'To turn off topmost (make the form act normal again):
res& = SetWindowPos (Form1.hWnd, HWND_NOTOPMOST, _ 0, 0, 0, 0, FLAGS)