Page 1 of 1

Absolute (VB style) z order of gadgets/controls using API?

Posted: Tue Nov 16, 2010 10:05 pm
by mesozorn
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...

Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Tue Nov 16, 2010 10:07 pm
by PB
> 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.

Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Tue Nov 16, 2010 10:12 pm
by mesozorn
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.
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.

Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Tue Nov 16, 2010 11:56 pm
by blueznl
The question comes to mind: why would you want to do this?

Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Wed Nov 17, 2010 2:21 am
by RASHAD

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


Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Wed Nov 17, 2010 3:45 pm
by mesozorn
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! :wink:

Much appreciated!

Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Wed Nov 17, 2010 5:07 pm
by RASHAD
Hi mesozorn
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


Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Sun Nov 21, 2010 9:52 am
by Kwai chang caine
Coolllll !!! very useful thanks :wink:

Re: Absolute (VB style) z order of gadgets/controls using AP

Posted: Mon Nov 22, 2010 4:54 pm
by mesozorn
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