Using visual Basic 6, I can very easily place two command buttons on a form/window so that they overlap each other, but specify which one remains always on top, no matter what. So that even if the button that is "behind" the other button gets clicked, it doesn't "jump to the front" and block out the other button. Since this can be done with VB, it must therefore be possible directly through the Windows API, but I haven't figured out so far how to do this.
Using SetWindowPos_() or BringWindowToTop_() will accomplish the effect temporarily, but as soon as the button/control at the "back" is interacted-with, it always jumps to the front right away, whereas under VB6 that front-jumping action is suppressed entirely if it is specified as "sent to back" at design time.
So, what would be the simplest, least elaborate way of accomplishing this through the API, that preferably doesn't require using callbacks, custom subclassed window procedures, or manual handling of #WM_PAINT messages? Seeing as it can be done with essentially one click in VB, I'm really hoping there is a reasonably straightforward method for doing this via the API.
Any help is greatly appreciated, thanks...
Absolute (VB style) z order of gadgets/controls using API?
Absolute (VB style) z order of gadgets/controls using API?
Last edited by mesozorn on Tue Nov 16, 2010 10:07 pm, edited 1 time in total.
Re: Absolute (VB style) z order of gadgets/controls using AP
> Seeing as it can be done with essentially one click in VB
Just so you know: what VB does with "one click" or even one command,
can usually be very complicated or bloated in the final executable. Just
because you don't see the complicated code doesn't mean it's a simple
thing to accomplish with just a single API call or such. VB just hides all
the work and code from the programmer, to make it easy for them.
Just so you know: what VB does with "one click" or even one command,
can usually be very complicated or bloated in the final executable. Just
because you don't see the complicated code doesn't mean it's a simple
thing to accomplish with just a single API call or such. VB just hides all
the work and code from the programmer, to make it easy for them.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Absolute (VB style) z order of gadgets/controls using AP
Fair enough and I realized this might be the case, but I am optimistically hoping that for this issue there is in fact a solution that can be implemented with an tolerable degree of simplicity. If not then so be it, I'll accept that and decide how to proceed. But I wanted to ask the question first in the hopes that there might be a straightforward-ish option.PB wrote:Just so you know: what VB does with "one click" or even one command,
can usually be very complicated or bloated in the final executable. Just
because you don't see the complicated code doesn't mean it's a simple
thing to accomplish with just a single API call or such. VB just hides all
the work and code from the programmer, to make it easy for them.
Re: Absolute (VB style) z order of gadgets/controls using AP
The question comes to mind: why would you want to do this?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Absolute (VB style) z order of gadgets/controls using AP
Code: Select all
OpenWindow(1,0,0,300,300,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1, 35, 35,50,50, "TEST",#WS_CLIPSIBLINGS)
ButtonGadget(2, 10, 10,100,100, "",#WS_CLIPSIBLINGS)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "Gadget 1 pressed"
Case 2
Debug "gadget 2 pressed"
EndSelect
EndSelect
Until Q =1
End
Egypt my love
Re: Absolute (VB style) z order of gadgets/controls using AP
Thanks Rashad! Interestingly enough I had tried playing around with the #WS_CLIPSIBLINGS flag without success before posting my question, but had only applied it to one of the buttons. Seems as long as it is applied to either both or just the button on top, it works fine. It would of course make sense that the style gets applied to the gadget that is to do the "clipping", but leave it to me to ignore the obvious!
Much appreciated!

Much appreciated!
Re: Absolute (VB style) z order of gadgets/controls using AP
Hi mesozorn
It will be a good practice to use #WS_CLIPSIBLINGS in all gadgets to keep Z-Order intact
See next
It will be a good practice to use #WS_CLIPSIBLINGS in all gadgets to keep Z-Order intact
See next
Code: Select all
OpenWindow(1,0,0,300,300,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1, 50, 50,50,50, "TEST",#WS_CLIPSIBLINGS)
ButtonGadget(2, 30, 30,90,90, "",#WS_CLIPSIBLINGS)
ButtonGadget(3, 10, 10,130,130, "",#WS_CLIPSIBLINGS)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "Gadget 1 pressed"
Case 2
Debug "gadget 2 pressed"
Case 3
Debug "gadget 3 pressed"
EndSelect
EndSelect
Until Q =1
End
Egypt my love
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Absolute (VB style) z order of gadgets/controls using AP
Coolllll !!! very useful thanks 


Not a destination
Re: Absolute (VB style) z order of gadgets/controls using AP
Yes indeed, very helpful and appreciated! And once this flag has been set, SetWindowPos_() or BringWindowToTop_() can be successfully used to change z-order on the fly at run-time, as follows:
Code: Select all
OpenWindow(1,0,0,500,300,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1, 50, 50,100,50, "Button 1"+Chr(13)+"is on top",#WS_CLIPSIBLINGS|#PB_Button_MultiLine)
ButtonGadget(2, 125, 50,100,50, "Button 2",#WS_CLIPSIBLINGS|#PB_Button_MultiLine)
ButtonGadget(3, 200, 50,100,50, "Button 3",#WS_CLIPSIBLINGS|#PB_Button_MultiLine)
ButtonGadget(4, 100, 150,100,50, "Bring to Top",#WS_CLIPSIBLINGS)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 4
BringWindowToTop_(GadgetID(2))
BringWindowToTop_(GadgetID(3))
SetGadgetText(3,"Button 3"+Chr(13)+"is now on top")
SetGadgetText(1,"Button 1")
EndSelect
EndSelect
Until Q =1
End