Forcing window on top of everything

BlitzPlus Forums/BlitzPlus Programming/Forcing window on top of everything

Below is a procedure extracted from a PureBasic program I wrote a few months ago. It is based on a routine I received from James L Boyd and it works very reliably.

The parameter 'ontop' should be True to force the window to remain on top, and False to subsequently cancel the effect.

It should be quite easy to translate to Blitz Plus code. The names of API constants start with # and the names of API routines end in _ .

Procedure.b WindowOnTop(ontop)
; ontop = True (1) for window to be on top, else False (0)
Hwin = WindowID() ; Window handle
If ontop
ontop = 1
zorder = #HWND_TOPMOST
BringWindowToTop_(Hwin)
Else
zorder = #HWND_NOTOPMOST
EndIf
; Make the on top request persistent
begindeferstruct = BeginDeferWindowPos_(1)
If begindeferstruct

deferstruct = DeferWindowPos_(begindeferstruct, Hwin, zorder, 0, 0, 0, 0, #SWP_NOMOVE+#SWP_NOSIZE+#SWP_SHOWWINDOW*ontop)

If deferstruct
res.b = EndDeferWindowPos_(deferstruct)
ProcedureReturn res
EndIf
EndIf
EndProcedure

Anthony Jordan