Always On Top/Bottom
Posted: Wed Apr 28, 2010 11:05 pm
Due to a little tool I'm building these functions were necessary, and I required it to work on both Windows & Linux (the two OSs I use) - the code is dotted around the forum, but not nicely tied up like I have it here.
If you have any suggestions, or you have the Mac version handy, let me know so I can add to it!
If you have any suggestions, or you have the Mac version handy, let me know so I can add to it!

Code: Select all
Procedure TopMost(Window, Enable)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
*Widget.GtkWidget = WindowID(Your_Window)
*GdkWindow = *Widget\Window
gdk_window_set_keep_above_(*GdkWindow, Enable)
CompilerCase #PB_OS_Windows
If Enable
SetParent_(WindowID(Window), 0)
SetWindowPos_(WindowID(Window),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
Else
SetWindowPos_(WindowID(Window),#HWND_NOTOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
EndIf
CompilerEndSelect
EndProcedure
Procedure BottomMost(Window, Enable)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
*Widget.GtkWidget = WindowID(Your_Window)
*GdkWindow = *Widget\Window
gdk_window_set_keep_below_(*GdkWindow, Enable)
CompilerCase #PB_OS_Windows
If Enable
SetWindowPos_(WindowID(Window),#HWND_NOTOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
SetParent_(WindowID(Window), FindWindow_(0,"Program Manager"))
Else
SetParent_(WindowID(Window), 0)
EndIf
CompilerEndSelect
EndProcedure
TopMostEnabled = #False
BottomMostEnabled = #False
OpenWindow(0, 0, 0, 200, 230, "Notes", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(1, 10, 10, 180, 100, "Top Most Toggle")
ButtonGadget(2, 10, 120, 180, 100, "Bottom Most Toggle")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case 1
TopMostEnabled = ~TopMostEnabled & #True
TopMost(0, TopMostEnabled)
BottomMostEnabled = #False
Case 2
BottomMostEnabled = ~BottomMostEnabled & #True
BottomMost(0, BottomMostEnabled)
TopMostEnabled = #False
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow