Toggle a window from always on top to bottom

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Toggle a window from always on top to bottom

Post by PB »

I've got a window which I've "pinned" to the desktop so it's
always underneath all other windows:

Code: Select all

SetParent_(WindowID(win),FindWindow_(0,"Program Manager"))
And it works totally fine. But now I need to toggle it so that
it's sometimes on top of all other windows for a while. I tried
this, but it doesn't work:

Code: Select all

SetParent_(WindowID(win),0)
SetWindowPos_(WindowID(win),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
Normally the SetWindowPos line does it, but it's failing because
of SetParent. What else can I try? Thanks.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
TI-994A
Addict
Addict
Posts: 2754
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Toggle a window from always on top to bottom

Post by TI-994A »

PB wrote:...I need to toggle it so that it's sometimes on top of all other windows for a while.
Hi PB. Try this:

Code: Select all

  SetParent_(WindowID(win), 0)
  StickyWindow(win, 1)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Toggle a window from always on top to bottom

Post by netmaestro »

Agree with TI-994A. StickyWindow is what I use and it's worked well for years. I guess the only reason you might look for another option is if the window you're working with is an api window and not a PB window. Dunno if that's a consideration or not, but if it's a native window, StickyWindow should give good results.
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Toggle a window from always on top to bottom

Post by PB »

Thanks TI-994A, using StickyWindow did it! :D
Don't know why SetWindowPos failed, though.
I shouldn't use so much API code, I guess. :?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply