Page 1 of 1

Always On Top/Bottom

Posted: Wed Apr 28, 2010 11:05 pm
by Foz
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! :)

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

Re: Always On Top/Bottom

Posted: Wed Apr 28, 2010 11:09 pm
by STARGĂ…TE
BottomMost() ist oke, but for TopMost you can use PB-Function:
StickyWindow(#Window, Status)

Re: Always On Top/Bottom

Posted: Wed Apr 28, 2010 11:10 pm
by Foz
:shock: I totally missed that one!

*** edit: actually, it StickyWindow() doesn't work very well when flicking between Bottom Most and Top Most - which is the behaviour I need for my app.

However, I will make note of that for future notice.

Re: Always On Top/Bottom

Posted: Thu Apr 29, 2010 12:32 am
by Foz
And a further look confirmed that I was talking out of my backside :lol:

Here's just the BottomMost then, with the toggles between top most and bottom most.

Code: Select all

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
        BottomMostEnabled = #False
        BottomMost(0, BottomMostEnabled)

        TopMostEnabled = ~TopMostEnabled & #True
        StickyWindow(0, TopMostEnabled)
      Case 2
        TopMostEnabled = #False
        StickyWindow(0, TopMostEnabled)

        BottomMostEnabled = ~BottomMostEnabled & #True
        BottomMost(0, BottomMostEnabled)
    EndSelect
  EndIf  
Until Event = #PB_Event_CloseWindow