zIndex back into top

Windows specific forum
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

zIndex back into top

Post by HanPBF »

Hello,

I have this code which works and puts a text gadget behind a canvas gadget.

Code: Select all

enableExplicit


declare		zIndexBackGadget(Gadget.i)

define NrWin = OpenWindow(#PB_Any, 0, 0, 480, 320, "TestWindow")

if NrWin
	define NrS = StringGadget(#PB_Any, 8, 12, 128, 32, "Test Text", #PB_String_BorderLess)
	define NrC = CanvasGadget(#PB_Any, 8, 8, 32, 32)
	define NrS1 = StringGadget(#PB_Any, 8, 48, 128, 32, "Test Text")
	
	StartDrawing(CanvasOutput(NrC))
		Box(0, 0, 32, 32, #Red)
		Box(8, 8, 16, 16, RGB(0,0,1))
	StopDrawing()
	
	
	define P	.POINT
	define R	.RECT
	
	Repeat
	  define Event = WaitWindowEvent(25)
	 	
	 	GetCursorPos_(P)
	 	GetWindowRect_(GadgetID(NrS),R)
	 	
	 	if PtInRect_(R, P\y << 32 + P\x)
	 		zIndexBackGadget(NrS)
	 	endif 
	Until Event = #PB_Event_CloseWindow
endif

procedure zIndexBackGadget(Gadget)
	SetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE, GetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
  SetWindowPos_(GadgetID(Gadget), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)	  
endProcedure ; zIndex_PBCadget
How should a zIndexForeGadget(Gadget) procedure look like? One that puts a gadget in front?
I have changed some things for SetWindowLongPtr_ and SetWindowPos_ but did not succeed.
(o.k., back or fore shouldn't matter; but with many gadgets can be helpful).

Any help apreciated!
Thanks!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: zIndex back into top

Post by RASHAD »

Hi

Code: Select all

  SetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE, GetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
  SetWindowPos_(GadgetID(Gadget), #HWND_TOP, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
OR :

Code: Select all

    SetForegroundWindow_(GadgetID(Gadget))
OR :

Code: Select all

    BringWindowToTop_(GadgetID(Gadget))
OR:

Code: Select all

   SetActiveWindow_(GadgetID(Gadget))
Egypt my love
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: zIndex back into top

Post by HanPBF »

Hello RASHAD,

thanks a lot for the hints.

All 4 tips do not work.

I checked #HWND_TOP before; but did not work.

While with zIndexBackGadget() You even can type in the text gadget and canvas keeps top.

Here is the comple example; maybe I have an error in there:

Code: Select all

enableExplicit


declare		zIndexBackGadget(Gadget)
declare		zIndexForeGadget(Gadget)

define NrWin = OpenWindow(#PB_Any, 0, 0, 480, 320, "TestWindow")

if NrWin
	define NrS1 = StringGadget(#PB_Any, 16, 12, 128, 32, "Test Text", #PB_String_BorderLess)
	define NrC1 = CanvasGadget(#PB_Any, 8, 8, 32, 32)
	define NrS2 = StringGadget(#PB_Any, 16, 48, 128, 32, "Test Text", #PB_String_BorderLess)
	define NrC2 = CanvasGadget(#PB_Any, 8, 48, 32, 32)
	
	StartDrawing(CanvasOutput(NrC1))
		Box(0, 0, 32, 32, #Red)
		Box(8, 8, 16, 16, RGB(0,0,1))
	StopDrawing()
	
	StartDrawing(CanvasOutput(NrC2))
		Box(0, 0, 32, 32, #Red)
		Box(8, 8, 16, 16, RGB(0,0,1))
	StopDrawing()
	
	
	define P	.POINT
	define R	.RECT
	
	Repeat
	  define Event = WaitWindowEvent(25)
	 	
	 	GetCursorPos_(P)
	 	GetWindowRect_(GadgetID(NrS1),R)
	 	
	 	if PtInRect_(R, P\y << 32 + P\x)
	 		zIndexBackGadget(NrS1)	 		
	 	endif 
	 	
	 	GetWindowRect_(GadgetID(NrS2),R)
	 	
	 	if PtInRect_(R, P\y << 32 + P\x)
	 		zIndexForeGadget(NrC2)
	 	endif 
	Until Event = #PB_Event_CloseWindow
endif

procedure zIndexBackGadget(Gadget)
	SetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE, GetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
  SetWindowPos_(GadgetID(Gadget), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)	  
endProcedure ; zIndexBackGadget(Gadget)

procedure zIndexForeGadget(Gadget)
	SetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE, GetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
  SetWindowPos_(GadgetID(Gadget), #HWND_TOP, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
  
  ;BringWindowToTop_(GadgetID(Gadget))
  
  ;SetForegroundWindow_(GadgetID(Gadget))
  
  ;SetActiveWindow_(GadgetID(Gadget))
endProcedure ; zIndexForeGadget(Gadget)

Anyway, walking through a list of gadgets and put them in order to the back should not be a problem.


Thanks!
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: zIndex back into top

Post by mestnyi »

Maybe it's you need :)

Code: Select all

EnableExplicit
;-
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Procedure GadgetsClipCallBack( GadgetID, lParam )
      If GadgetID
        Protected Gadget = GetProp_( GadgetID, "PB_ID" )
        
        If GetWindowLongPtr_( GadgetID, #GWL_STYLE ) & #WS_CLIPSIBLINGS = #False 
          If IsGadget( Gadget ) 
            Select GadgetType( Gadget )
              Case #PB_GadgetType_ComboBox
                Protected Height = GadgetHeight( Gadget )
                
            EndSelect
          EndIf
          
          SetWindowLongPtr_( GadgetID, #GWL_STYLE, GetWindowLongPtr_( GadgetID, #GWL_STYLE ) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN )
          
          If Height
            ResizeGadget( Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, Height )
          EndIf
          
          SetWindowPos_( GadgetID, #GW_HWNDFIRST, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
        EndIf
        
      EndIf
      
      ProcedureReturn GadgetID
    EndProcedure
  CompilerEndIf
  Procedure ClipGadgets( WindowID )
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      EnumChildWindows_( WindowID, @GadgetsClipCallBack(), 0 )
    CompilerEndIf
  EndProcedure
  
   Procedure SetGadgetIDPos( GadgetID, Pos ) ;Set gadget pos
    If GadgetID
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        SetWindowPos_( GadgetID, Pos, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
      CompilerEndIf
    EndIf
  EndProcedure
  

Declare      zIndexBackGadget(Gadget)
Declare      zIndexForeGadget(Gadget)

Define NrWin = OpenWindow(#PB_Any, 0, 0, 480, 320, "TestWindow")

If NrWin
   Define NrS1 = StringGadget(#PB_Any, 16, 12, 128, 32, "Test Text", #PB_String_BorderLess)
   Define NrC1 = CanvasGadget(#PB_Any, 8, 8, 32, 32)
   
   Define NrS2 = StringGadget(#PB_Any, 16, 48, 128, 32, "Test Text", #PB_String_BorderLess)
   Define NrC2 = CanvasGadget(#PB_Any, 8, 48, 32, 32)
   
   StartDrawing(CanvasOutput(NrC1))
      Box(0, 0, 32, 32, #Red)
      Box(8, 8, 16, 16, RGB(0,0,1))
   StopDrawing()
   
   StartDrawing(CanvasOutput(NrC2))
      Box(0, 0, 32, 32, #Red)
      Box(8, 8, 16, 16, RGB(0,0,1))
   StopDrawing()
   
   
   Define P   .POINT
   Define R   .RECT
   
   ClipGadgets(UseGadgetList(0))
   Repeat
     Define Event = WaitWindowEvent(25)
       
       GetCursorPos_(P)
       GetWindowRect_(GadgetID(NrS2),R)
       
       If PtInRect_(R, P\y << 32 + P\x)
         ;zIndexForeGadget(NrS2)
         SetGadgetIDPos( GadgetID(NrS2), 0 )
       Else
         SetGadgetIDPos( GadgetID(NrS2), 1 )
       EndIf 
   Until Event = #PB_Event_CloseWindow
EndIf

Procedure zIndexBackGadget(Gadget)
  
EndProcedure ; zIndexBackGadget(Gadget)

Procedure zIndexForeGadget(Gadget)
  
EndProcedure ; zIndexForeGadget(Gadget)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: zIndex back into top

Post by RASHAD »

Hi

Code: Select all

EnableExplicit
;-
Define Quit,Gadget
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Procedure GadgetsClipCallBack( GadgetID, lParam )
      If GadgetID
        Protected Gadget = GetProp_( GadgetID, "PB_ID" )
       
        If GetWindowLongPtr_( GadgetID, #GWL_STYLE ) & #WS_CLIPSIBLINGS = #False
          If IsGadget( Gadget )
            Select GadgetType( Gadget )
              Case #PB_GadgetType_ComboBox
                Protected Height = GadgetHeight( Gadget )
               
            EndSelect
          EndIf
         
          SetWindowLongPtr_( GadgetID, #GWL_STYLE, GetWindowLongPtr_( GadgetID, #GWL_STYLE ) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN )
         
          If Height
            ResizeGadget( Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, Height )
          EndIf
         
          SetWindowPos_( GadgetID, #GW_HWNDFIRST, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
        EndIf
       
      EndIf
     
      ProcedureReturn GadgetID
    EndProcedure
  CompilerEndIf
  Procedure ClipGadgets( WindowID )
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      EnumChildWindows_( WindowID, @GadgetsClipCallBack(), 0 )
    CompilerEndIf
  EndProcedure
 
   Procedure SetGadgetIDPos( GadgetID, Pos ) ;Set gadget pos
    If GadgetID
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        SetWindowPos_( GadgetID, Pos, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
      CompilerEndIf
    EndIf
  EndProcedure
  
Procedure TopPos( GadgetID ) ;Set gadget pos
  SetWindowLongPtr_(GadgetID(GadgetID), #GWL_STYLE, GetWindowLongPtr_(GadgetID(GadgetID), #GWL_STYLE) | #WS_CLIPSIBLINGS)
  SetWindowPos_(GadgetID(GadgetID), #HWND_TOP, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
EndProcedure
 

Define NrWin = OpenWindow(#PB_Any, 0, 0, 480, 320, "TestWindow")

If NrWin
   Define NrS1 = StringGadget(#PB_Any, 16, 12, 128, 32, "Test Text", #PB_String_BorderLess)
   Define NrC1 = CanvasGadget(#PB_Any, 8, 8, 32, 32)
   
   Define NrS2 = StringGadget(#PB_Any, 16, 48, 128, 32, "Test Text", #PB_String_BorderLess)
   Define NrC2 = CanvasGadget(#PB_Any, 8, 48, 32, 32)
   
   StartDrawing(CanvasOutput(NrC1))
      Box(0, 0, 32, 32, #Red)
      Box(8, 8, 16, 16, RGB(0,0,1))
   StopDrawing()
   
   StartDrawing(CanvasOutput(NrC2))
      Box(0, 0, 32, 32, #Red)
      Box(8, 8, 16, 16, RGB(0,0,1))
   StopDrawing()
   
   
   Define P   .POINT
   Define R   .RECT
   
   ClipGadgets(UseGadgetList(0))
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit =1
        
      Case #WM_MOUSEMOVE
          GetCursorPos_ (@p.POINT) 
          ScreenToClient_ (WindowID(NrWin), @p)     
            Gadget = ChildWindowFromPoint_ (WindowID(NrWin), p\y<< 32+p\x)
            If Gadget = GadgetID(NrS1)    
              TopPos(NrS1)
              TopPos(NrC2)
              SetActiveGadget(NrS1)
            ElseIf Gadget = GadgetID(NrS2)                                                      
              TopPos(NrS2)
              TopPos(NrC1)
              SetActiveGadget(NrS2)
            Else
              TopPos(NrC1)
              TopPos(NrC2)
              SetActiveGadget(-1)
            EndIf        
            UpdateWindow_(WindowID(NrWin))
    EndSelect
  Until Quit = 1
EndIf

Egypt my love
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: zIndex back into top

Post by mestnyi »

RASHAD :)
Post Reply