Z-order (cross platform)
Z-order (cross platform)
How do I know that the gadget above or below (top or bottom)
Re: Z-order (cross platform)
PB doesn't support Z-order. So don't put one gadget over another!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Z-order (cross platform)
But sometimes you have toSo don't put one gadget over another!
win only:
Code: Select all
OpenWindow(0, 0, 0, 200, 100, "", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonGadget(0, 50, 30, 100, 40, "button")
ButtonGadget(1, 10, 10, 180, 80, "click" + Space(38) + "click", #WS_CLIPSIBLINGS)
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Debug "button 0 pressed"
Case 1
Debug "button 1 pressed"
EndSelect
EndSelect
Until event = #PB_Event_CloseWindowEt cetera is my worst enemy
Re: Z-order (cross platform)
Code: Select all
Enumeration
#window
#GADGET_0
#GADGET_1
#GADGET_2
#GADGET_3
EndEnumeration
Procedure CreateElements()
If OpenWindow(#window, 0, 0,430,110, "Окно", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
Define Flag
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Flag = #WS_CLIPSIBLINGS
CompilerEndIf
ButtonGadget(#GADGET_0, 100, 20, 150, 25, "сверху", Flag) ;#WS_CLIPSIBLINGS Z- порядок на форме :сверху
ButtonGadget(#GADGET_1, 140, 20, 150, 25, "в середине", Flag) ;#WS_CLIPSIBLINGS Z- порядок на форме :в середине
ButtonGadget(#GADGET_2, 180, 20, 150, 25, "снизу", Flag) ;#WS_CLIPSIBLINGS Z- порядок на форме :снизу
ButtonGadget(#GADGET_3, 140, 55, 150, 40, "Сделать средную кнопку сверху" ,#PB_Button_MultiLine)
EndIf
EndProcedure
Procedure MainLoop()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow :Break
Case #PB_Event_Gadget
Select EventGadget()
Case #GADGET_0 :Debug "сверху" ;#button
Case #GADGET_1 :Debug "в середине" ;#button
Case #GADGET_2 :Debug "снизу" ;#button
Case #GADGET_3 ;#button
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
BringWindowToTop_(GadgetID(#GADGET_1)) ; Указать самому Z- порядок на форме
CompilerElse
CompilerEndIf
EndSelect
EndSelect
ForEver
EndProcedure
Procedure Main()
CreateElements()
MainLoop()
EndProcedure :Main()
Last edited by mestnyi on Sun Dec 06, 2015 8:09 pm, edited 2 times in total.
Re: Z-order (cross platform)
Code: Select all
; -------------------------------------
;{- перечисление гаджетов формы ; Ok
; -------------------------------------
Structure StructureWindowGadgetList
Text.s
Name.s
pX.l
pY.l
X.l
Y.l
Height.l
Width.l
Number.l
Handle.l
Parent.l
IsParent.l
EndStructure :Global NewList EnumGadget.StructureWindowGadgetList()
Procedure WindowGadgetList(hWnd,lParam)
Protected Text$,Name$
Text$ = Space(250)
Name$ = Space(1024)
GetWindowText_(hWnd,Text$,Len(Text$))
GetClassName_(hWnd,@Name$,Len(Name$))
AddElement(EnumGadget())
If Name$<>"PureScrollAreaChild"
EnumGadget()\X=GadgetX(GetProp_(hwnd, "PB_ID"))
EnumGadget()\Y=GadgetY(GetProp_(hwnd, "PB_ID"))
EnumGadget()\Height=GadgetHeight(GetProp_(hwnd, "PB_ID"))
EnumGadget()\Width=GadgetWidth(GetProp_(hwnd, "PB_ID"))
EndIf
EnumGadget()\Text=Text$
EnumGadget()\Name=Name$
EnumGadget()\Number=GetProp_(hwnd, "PB_ID")
EnumGadget()\Handle=hwnd
EnumGadget()\Parent=GetParent_(hwnd)
EnumGadget()\IsParent=GetParent_(GetProp_(hwnd, "PB_ID"))
ProcedureReturn #True
EndProcedure
Procedure EnumWindowGadget(WindowID,lParam=0)
Protected hWnd
If IsWindow(WindowID)
hWnd=WindowID(WindowID)
EndIf
EnumChildWindows_(hWnd,@WindowGadgetList(),lParam)
EndProcedure
;}-
; --------------------------------------
If OpenWindow(5,5,5,700,400,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
CreatePopupMenu(443)
MenuItem(1, "Поместить сверху") ; You can use all commands for creating a menu
MenuItem(2, "Поместить снизу") ; just like in a normal menu...
MenuItem(3, "На один верх") ; You can use all commands for creating a menu
MenuItem(4, "На один вниз") ; just like in a normal menu...
ButtonGadget(0,5,160,130,25,"1");, #WS_CLIPSIBLINGS)
ButtonGadget(1,15,175,130,25,"2");, #WS_CLIPSIBLINGS)
TextGadget(214, 95, 10, 60, 25, "TextGadget");,#SS_NOTIFY); остается всегда внизу
ButtonGadget(230, 25, 5, 80, 25, "ButtonGadget")
StringGadget(244, 300, 35, 139, 25, "TStringGadget")
ScrollAreaGadget(344, 0, 50, 480,100, 480, 100, 30)
ButtonGadget(444, 15, 10, 130, 45, "ButtonGadget",6543)
StringGadget(174, 225, 10, 150, 25, "StringGadget",19)
CloseGadgetList()
ComboBoxGadget(144, 300, 20, 120, 25);, #WS_CLIPSIBLINGS)
EnumWindowGadget(5)
ForEach EnumGadget() ;прибиваем к полу всех гаджетов
SetWindowLong_(GadgetID(EnumGadget()\Number),#GWL_STYLE,GetWindowLong_(GadgetID(EnumGadget()\Number), #GWL_STYLE)|#WS_CLIPSIBLINGS)
Next
SetWindowPos_(GadgetID(144),#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) ;указать Z-положение гаджетов
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
If Event=#PB_Event_Gadget
DisplayPopupMenu(443, WindowID(5))
gadget= EventGadget()
EndIf
Case #PB_Event_Menu ; an item of the popup-menu was clicked
Select EventMenu() ; get the clicked menu item...
Case 1 : SetWindowPos_(GadgetID(gadget),#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) ;указать Z-положение гаджетов
Case 2 : SetWindowPos_(GadgetID(gadget),#HWND_BOTTOM,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) ;указать Z-положение гаджетов
;нужно реализовать но не знаю как
Case 3
Case 4
EndSelect
EndSelect
ForEver
EndIfRe: Z-order (cross platform)
Is there a question involved in the above code or is it just an example that it works?
есть вопрос, участвующих в приведенном выше коде, или это только один пример, что он работает? (bing translator)
есть вопрос, участвующих в приведенном выше коде, или это только один пример, что он работает? (bing translator)
Et cetera is my worst enemy
Re: Z-order (cross platform)
in windows and in Linux, I do not know. And I wanted to learn how to put on top of one?is it just an example that it works?
Re: Z-order (cross platform)
Like I said, #WS_CLIPSIBLINGS or #WS_CLIPCHILDREN only works on windows (win api)... Don't know if there are similar functions on Linux or Mac.
Maybe you should rethink your layout and go with a more cross-platform solution that doesn't include z-ordering?!
Maybe you should rethink your layout and go with a more cross-platform solution that doesn't include z-ordering?!
Et cetera is my worst enemy
Re: Z-order (cross platform)
No this will not work.Maybe you should rethink your layout and go with a more cross-platform solution that doesn't include z-ordering?!
What is interesting in Lazarus is to implement
Re: Z-order (cross platform)
Code: Select all
OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonGadget(4, 250, 30, 100, 20, "1")
ButtonGadget(5, 250, 60, 100, 20, "2")
ButtonGadget(6, 250, 90, 100, 20, "3")
ButtonGadget(7, 250, 130, 100, 20, "reset")
ButtonGadget(8, 250, 160, 100, 20, "gettopgadget")
ButtonGadget(0, 10, 30, 100, 40, "1")
ButtonGadget(1, 50, 30, 100, 40, "2")
ButtonGadget(2, 100, 30, 100, 40, "3")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 4
SetWindowLong_(GadgetID(0),#GWL_STYLE,GetWindowLong_(GadgetID(0), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(0)
SetGadgetState(0,1)
BringWindowToTop_(GadgetID(0))
Case 5
SetWindowLong_(GadgetID(1),#GWL_STYLE,GetWindowLong_(GadgetID(1), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(1)
SetGadgetState(1,1)
BringWindowToTop_(GadgetID(1))
Case 6
SetWindowLong_(GadgetID(2),#GWL_STYLE,GetWindowLong_(GadgetID(2), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(2)
SetGadgetState(2,1)
BringWindowToTop_(GadgetID(2))
Case 7
SetWindowLong_(GadgetID(0),#GWL_STYLE,GetWindowLong_(GadgetID(0), #GWL_STYLE)!#WS_CLIPSIBLINGS)
SetWindowLong_(GadgetID(1),#GWL_STYLE,GetWindowLong_(GadgetID(1), #GWL_STYLE)!#WS_CLIPSIBLINGS)
SetWindowLong_(GadgetID(2),#GWL_STYLE,GetWindowLong_(GadgetID(2), #GWL_STYLE)!#WS_CLIPSIBLINGS)
Case 8
Debug GetClassLongPtr_(GadgetID(0),#HWND_BOTTOM)
Debug GetClassLongPtr_(GadgetID(1),#HWND_TOPMOST)
Debug GetClassLongPtr_(GadgetID(2),#HWND_TOP)
EndSelect
EndSelect
Until event = #PB_Event_CloseWindowRe: Z-order (cross platform)
Code: Select all
OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonGadget(4, 250, 30, 100, 20, "1")
ButtonGadget(5, 250, 60, 100, 20, "2")
ButtonGadget(6, 250, 90, 100, 20, "3")
ButtonGadget(7, 250, 130, 100, 20, "reset")
ButtonGadget(8, 250, 160, 100, 20, "gettopgadget")
ButtonGadget(1, 10, 30, 100, 40, "1")
ButtonGadget(2, 50, 30, 100, 40, "2")
ButtonGadget(3, 100, 30, 100, 40, "3")
Procedure IsTopGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDFIRST) = GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDFIRST))
EndIf
EndProcedure
Procedure IsBottomGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDLAST) ;= GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDLAST))
EndIf
EndProcedure
Procedure IsNextGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDNEXT) ;= GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDNEXT))
EndIf
EndProcedure
Procedure IsPrevGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDPREV) ;= GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDPREV))
EndIf
EndProcedure
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 4
SetWindowLong_(GadgetID(1),#GWL_STYLE,GetWindowLong_(GadgetID(1), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(1)
SetGadgetState(1,1)
BringWindowToTop_(GadgetID(1))
Case 5
SetWindowLong_(GadgetID(2),#GWL_STYLE,GetWindowLong_(GadgetID(2), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(2)
SetGadgetState(2,1)
BringWindowToTop_(GadgetID(2))
Case 6
SetWindowLong_(GadgetID(3),#GWL_STYLE,GetWindowLong_(GadgetID(3), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(3)
SetGadgetState(3,1)
BringWindowToTop_(GadgetID(3))
Case 7
SetWindowLong_(GadgetID(1),#GWL_STYLE,GetWindowLong_(GadgetID(1), #GWL_STYLE)!#WS_CLIPSIBLINGS)
SetWindowLong_(GadgetID(2),#GWL_STYLE,GetWindowLong_(GadgetID(2), #GWL_STYLE)!#WS_CLIPSIBLINGS)
SetWindowLong_(GadgetID(3),#GWL_STYLE,GetWindowLong_(GadgetID(3), #GWL_STYLE)!#WS_CLIPSIBLINGS)
Case 8
Debug "-----"
Debug IsTopGadget(1)
Debug IsTopGadget(2)
Debug IsTopGadget(3)
Debug "-----"
Debug IsNextGadget(1)
Debug IsNextGadget(2)
Debug IsNextGadget(3)
Debug "-----"
Debug IsPrevGadget(1)
Debug IsPrevGadget(2)
Debug IsPrevGadget(3)
Debug "-----"
Debug IsBottomGadget(1)
Debug IsBottomGadget(2)
Debug IsBottomGadget(3)
EndSelect
EndSelect
Until event = #PB_Event_CloseWindowRe: Z-order (cross platform)
Code: Select all
OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonGadget(4, 250, 30, 100, 20, "1")
ButtonGadget(5, 250, 60, 100, 20, "2")
ButtonGadget(6, 250, 90, 100, 20, "3")
ButtonGadget(7, 250, 130, 100, 20, "reset")
ButtonGadget(8, 250, 160, 100, 20, "gettopgadget")
ButtonGadget(1, 10, 30, 100, 40, "1")
ButtonGadget(2, 50, 30, 100, 40, "2")
ButtonGadget(3, 100, 30, 100, 40, "3")
Procedure IsTopGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDFIRST) = GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDFIRST))
EndIf
EndProcedure
Procedure IsBottomGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDLAST) ;= GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDLAST))
EndIf
EndProcedure
Procedure IsNextGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDNEXT) ;= GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDNEXT))
EndIf
EndProcedure
Procedure IsPrevGadget(Gadget)
If GetWindow_(GadgetID(Gadget),#GW_HWNDPREV) ;= GadgetID(Gadget)
ProcedureReturn GetDlgCtrlID_(GetWindow_(GadgetID(Gadget),#GW_HWNDPREV))
EndIf
EndProcedure
Procedure IntersectGadgets(Gadget_1, Gadget_2)
If GadgetID < 9999 :Gadget_1=GadgetID(Gadget_1) :EndIf
If GadgetID < 9999 :Gadget_2=GadgetID(Gadget_2) :EndIf
Protected.RECT Frame, Frame_1, Frame_2
GetWindowRect_(Gadget_1, @Frame_1)
GetWindowRect_(Gadget_2, @Frame_2)
ProcedureReturn IntersectRect_(@Frame, @Frame_1, @Frame_2)
EndProcedure
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 4
SetWindowLong_(GadgetID(1),#GWL_STYLE,GetWindowLong_(GadgetID(1), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(1)
SetGadgetState(1,1)
BringWindowToTop_(GadgetID(1))
Case 5
SetWindowLong_(GadgetID(2),#GWL_STYLE,GetWindowLong_(GadgetID(2), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(2)
SetGadgetState(2,1)
BringWindowToTop_(GadgetID(2))
Case 6
SetWindowLong_(GadgetID(3),#GWL_STYLE,GetWindowLong_(GadgetID(3), #GWL_STYLE)|#WS_CLIPSIBLINGS)
SetActiveGadget(3)
SetGadgetState(3,1)
BringWindowToTop_(GadgetID(3))
Case 7
SetWindowLong_(GadgetID(1),#GWL_STYLE,GetWindowLong_(GadgetID(1), #GWL_STYLE)!#WS_CLIPSIBLINGS)
SetWindowLong_(GadgetID(2),#GWL_STYLE,GetWindowLong_(GadgetID(2), #GWL_STYLE)!#WS_CLIPSIBLINGS)
SetWindowLong_(GadgetID(3),#GWL_STYLE,GetWindowLong_(GadgetID(3), #GWL_STYLE)!#WS_CLIPSIBLINGS)
Case 8
If IntersectGadgets(1, 2)
Debug IsTopGadget(1)
Debug IsTopGadget(2)
Debug IsPrevGadget(1)
Debug IsPrevGadget(2)
Debug IsNextGadget(1)
Debug IsNextGadget(2)
Debug IsBottomGadget(1)
Debug IsBottomGadget(2)
EndIf
Debug "-----"
Debug IsTopGadget(1)
Debug IsTopGadget(2)
Debug IsTopGadget(3)
Debug "-----"
Debug IsNextGadget(1)
Debug IsNextGadget(2)
Debug IsNextGadget(3)
Debug "-----"
Debug IsPrevGadget(1)
Debug IsPrevGadget(2)
Debug IsPrevGadget(3)
Debug "-----"
Debug IsBottomGadget(1)
Debug IsBottomGadget(2)
Debug IsBottomGadget(3)
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
