Page 1 of 1

Window always underneath a third-party window?

Posted: Thu Oct 03, 2019 1:48 pm
by BarryG
We all know how to make a window stay on top of others, but I want a window to always stay underneath a third-party one. So if Notepad was open, I want my window to open underneath it but offset a bit, so I can see my window behind it, but it'll still be mainly hidden by Notepad. Also, if my window is clicked, it should remain under Notepad as well. Anyone know if this can be done?

This is my goal:

Image

Code: Select all

np=FindWindow_(0,"Untitled - Notepad")
GetWindowRect_(np,win.RECT)
x=win\left
y=win\top

OpenWindow(1,x-50,y-50,300,100,"Always under Notepad",#PB_Window_SystemMenu)

; What goes here to keep it under Notepad?

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Window always underneath a third-party window?

Posted: Thu Oct 03, 2019 4:40 pm
by spikey
I think the only way to do it would be to refresh the window location on a regular basis; either by having a timeout on the WaitWindowEvent or by using a callback procedure. Something like:

Code: Select all

OpenWindow(1,0,0,300,100,"Always under Notepad",#PB_Window_SystemMenu)

Repeat
  
  np=FindWindow_(0,"Untitled - Notepad")
  If np
    GetWindowRect_(np,win.RECT)
    x=win\left - 50
    y=win\top - 50
    SetWindowPos_(WindowID(1), np, x, y, 0, 0, #SWP_NOSIZE)
  EndIf
  
Until WaitWindowEvent(200)=#PB_Event_CloseWindow
I would expect it to interfere with the normal event processing of the window however, which might make interacting with it difficult.

Re: Window always underneath a third-party window?

Posted: Thu Oct 03, 2019 7:16 pm
by mestnyi

Code: Select all

OpenWindow(1,0,0,300,100,"Always under Notepad",#PB_Window_SystemMenu)
np=FindWindow_(0,"Безымянный - Блокнот")

SetWindowLongPtr_(np, #GWLP_HWNDPARENT, WindowID(1))
SetWindowPos_( np, #GW_HWNDFIRST, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
        
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Window always underneath a third-party window?

Posted: Fri Oct 04, 2019 8:33 am
by BarryG
spikey, that didn't work for me - I could still bring my window on top of Notepad when I clicked it.

mestnyi, that worked. Thanks!

Re: Window always underneath a third-party window?

Posted: Fri Oct 04, 2019 6:20 pm
by mestnyi
BarryG wrote:mestnyi, that worked. Thanks!
I was wondering why this is necessary.

Re: Window always underneath a third-party window?

Posted: Sat Oct 05, 2019 2:16 am
by BarryG
mestnyi wrote:I was wondering why this is necessary.
A customer's request for my app. I didn't ask them what for, but I added it because I knew (thanks to you) that it would be a quick easy addition. Makes the vendor-client relationship even stronger.

Re: Window always underneath a third-party window?

Posted: Sat Oct 05, 2019 11:46 am
by mestnyi
Got it, I asked it because I write gui for purebasiс.