-
Hi,
I'm building a one form application to work alongside a SCADA system.
I need the for to remain on top of this SCADA system at all times (I don't want it to be modal as the users of the SCADA need to be able to perform functions), I just need it to sit on top of this other window.
Does anyone know how to do this?
Best Regards,
Rob Brown.
-
<?>
Code:
'to make form stay topmost
'put this in a bas module
'
Public 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
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
'=============================================
'
'put this in events click or load or whatever
'or hardcopy
'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)
-
Note:
Just something to add to that, with some stayontop codes, alt + esc makes it loose priority. If yours does this can be a flaw like ive found out the hard way. To avoid that either set a loop or timer that everytime that form is visible to stayontop.
-
<?>
not so much a flaw as an override by windows..
Alt/tab switches screens...yes this one falls to that as well.
-
put the ontop statment if the form_activate sub
-
Thanks,
the code keeps the window on top, however:
The window is resized and part of it (title bar) is missing (off the top of the screen).
I've tried playing around with the x,y,cx,cy co-ordinates but it makes no difference.
Is there some way to set the Z-order without moving or sizing the window?
Best regards,
Rob Brown.
-
<?>
You might want to look up SetWindowPos in API functions and set your windows in compatible spaces.
I've used it(don't fully understand it) by putting my app at top 0 left 0 (top right) and then position Notepad directly below it(bottom right)
Maybe it might apply to your situtation.