Window always underneath a third-party window?

Windows specific forum
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Window always underneath a third-party window?

Post 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
User avatar
spikey
Enthusiast
Enthusiast
Posts: 586
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Window always underneath a third-party window?

Post 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.
mestnyi
Addict
Addict
Posts: 1000
Joined: Mon Nov 25, 2013 6:41 am

Re: Window always underneath a third-party window?

Post 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
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Window always underneath a third-party window?

Post 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!
mestnyi
Addict
Addict
Posts: 1000
Joined: Mon Nov 25, 2013 6:41 am

Re: Window always underneath a third-party window?

Post by mestnyi »

BarryG wrote:mestnyi, that worked. Thanks!
I was wondering why this is necessary.
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Window always underneath a third-party window?

Post 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.
mestnyi
Addict
Addict
Posts: 1000
Joined: Mon Nov 25, 2013 6:41 am

Re: Window always underneath a third-party window?

Post by mestnyi »

Got it, I asked it because I write gui for purebasiс.
Post Reply