Splitter separate and event resizing [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Splitter separate and event resizing [Resolved]

Post by Kwai chang caine »

Hello at all

Someone understand why when i resize the splitter separate to the left or right the event is not detected :shock:

Code: Select all

Enumeration
 #FormProgram
 #Splitter
 #Panel
 #Editor
 #Container 
EndEnumeration

Procedure WindowProc(hWnd,Msg,wParam,lParam)
 
 result = #PB_ProcessPureBasicEvents
     
 If Msg = #WM_SIZE  And hWnd = GadgetID(#Container)
  Debug "Event #Container"
  result = 0
 EndIf
  
 If Msg = #WM_SIZE  And HWnd = GadgetID(#Splitter)
  Debug "Event #Splitter"
  result = 0
 EndIf
  
 ProcedureReturn result
 
EndProcedure

OpenWindow(#FormProgram,0,0, 600, 300,"Split",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar)
EditorGadget(#Editor, 0,0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))
PanelGadget(#Panel, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))
 
 AddGadgetItem(#Panel, -1, "Panel") 
 
  ContainerGadget(#Container,0,0,WindowWidth(#FormProgram),WindowHeight(#FormProgram))
  CloseGadgetList()
  SetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE)|#WS_CLIPCHILDREN) ; <- important

CloseGadgetList()

SplitterGadget(#Splitter, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram), #Panel, #Editor, #PB_Splitter_Vertical|#PB_Splitter_Separator)
SetGadgetState(#Splitter, WindowWidth(#FormProgram) / 4)

SetWindowCallback(@WindowProc())

Repeat
 Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Have a good day
Last edited by Kwai chang caine on Mon Dec 29, 2025 7:51 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
BarryG
Addict
Addict
Posts: 4312
Joined: Thu Apr 18, 2019 8:17 am

Re: Splitter separate and event resizing

Post by BarryG »

I don't know why, but why use a callback? It supports events:

Code: Select all

Enumeration
  #FormProgram
  #Splitter
  #Panel
  #Editor
  #Container 
EndEnumeration

OpenWindow(#FormProgram,0,0, 600, 300,"Split",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar)
EditorGadget(#Editor, 0,0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))
PanelGadget(#Panel, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))

AddGadgetItem(#Panel, -1, "Panel") 

ContainerGadget(#Container,0,0,WindowWidth(#FormProgram),WindowHeight(#FormProgram))
CloseGadgetList()
SetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE)|#WS_CLIPCHILDREN) ; <- important

CloseGadgetList()

SplitterGadget(#Splitter, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram), #Panel, #Editor, #PB_Splitter_Vertical|#PB_Splitter_Separator)
SetGadgetState(#Splitter, WindowWidth(#FormProgram) / 4)

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget And EventGadget() = #Splitter
    Debug "Event #Splitter"
  EndIf
Until Event = #PB_Event_CloseWindow
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Splitter separate and event resizing

Post by Kwai chang caine »

Hello BarryG, thanks for your help 8)

You have right, i have even not thinking to use native event management
I use Callback because my code (given by CHI)

viewtopic.php?p=649199#p649199

is more complicated than that, and use callback to resizing some executables embedding, for be the most quicker possible
But when i have adding the splittergadget i see the callback not detect his event :shock:
It's the reason why i create a nex thread, with the most simple code (No embedding, no loops) for understand this strange behavior :wink:
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Splitter separate and event resizing

Post by Kwai chang caine »

I have put my question to the AI, and apparently it's IMPOSSIBLE to detect the moving of the bar inside a SpliterGadget by the WindowCallBack, the message is not sending to the windows, it is managed by the gadget in internal
Then we must use a Subclassing of the Splitter, and that works 8)

Code: Select all

Enumeration
 #FormProgram
 #Splitter
 #Panel
 #Editor
 #Container 
EndEnumeration

Global OldSplitterProc

Procedure SplitterProc(hWnd, Msg, wParam, lParam)
  Select Msg

    Case #WM_MOUSEMOVE
      ; Drag réel du séparateur
      If GetCapture_() = hWnd
        Debug "Resize en cours : " + Str(GetGadgetState(#Splitter))
      EndIf

    Case #WM_LBUTTONUP
      If GetCapture_() = hWnd
        Debug "Fin resize splitter"
      EndIf

  EndSelect

  ProcedureReturn CallWindowProc_(OldSplitterProc, hWnd, Msg, wParam, lParam)
EndProcedure

OpenWindow(#FormProgram,0,0, 600, 300,"Split",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar)
EditorGadget(#Editor, 0,0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))
PanelGadget(#Panel, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))
 
 AddGadgetItem(#Panel, -1, "Panel") 
 
  ContainerGadget(#Container,0,0,WindowWidth(#FormProgram),WindowHeight(#FormProgram))
  CloseGadgetList()
  SetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE)|#WS_CLIPCHILDREN) ; <- important

CloseGadgetList()

SplitterGadget(#Splitter, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram), #Panel, #Editor, #PB_Splitter_Vertical|#PB_Splitter_Separator)
SetGadgetState(#Splitter, WindowWidth(#FormProgram) / 4)

OldSplitterProc = SetWindowLongPtr_(GadgetID(#Splitter), #GWL_WNDPROC, @SplitterProc())

Repeat
 Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6512
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Splitter separate and event resizing [Resolved]

Post by mk-soft »

Completely without API
Works well on Windows and Linux. With macOS, the events only appear when you release them.

Code: Select all

;-TOP mk-soft, v1.01.0, 29.12.2025

; Global Gadget Events

Procedure DoEventGadgets()
  Protected Gadget, Position
  
  Gadget = EventGadget()
  Select GadgetType(Gadget)
    Case #PB_GadgetType_Splitter
      Position = GetGadgetState(Gadget)
      If Position <> GetGadgetData(Gadget)
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Change, Position)
        SetGadgetData(Gadget, Position)
      EndIf
  EndSelect
  
EndProcedure

; Splitter Gadget Events

Procedure DoEventSplitterGadget()
  Select EventType()
    Case #PB_EventType_Change
      Debug "Splitter Position: " + EventData()
      
  EndSelect
  
EndProcedure

If OpenWindow(0, 0, 0, 230, 180, "SplitterGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  #Button1  = 0
  #Button2  = 1
  #Splitter = 2
  
  ButtonGadget(#Button1, 0, 0, 0, 0, "Button 1") ; No need to specify size or coordinates
  ButtonGadget(#Button2, 0, 0, 0, 0, "Button 2") ; as they will be sized automatically
  SplitterGadget(#Splitter, 5, 5, 220, 120, #Button1, #Button2, #PB_Splitter_Separator)
  ; Save current Splitter position
  SetGadgetData(#Splitter, GetGadgetState(#Splitter))
  
  TextGadget(3, 10, 135, 210, 40, "Above GUI part shows two automatically resizing buttons inside the 220x120 SplitterGadget area.",#PB_Text_Center )
  
  ; Bind Global Gadget Events
  BindEvent(#PB_Event_Gadget, @DoEventGadgets())
  
  ; Bind Splitter Event
  BindGadgetEvent(#Splitter, @DoEventSplitterGadget())
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Splitter
            Select EventType()
              Case #PB_EventType_Change
                ;Debug "Splitter Position: " + EventData()
                
            EndSelect
        EndSelect
        
    EndSelect
  ForEver
        
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Michael Vogel
Addict
Addict
Posts: 2837
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Splitter separate and event resizing [Resolved]

Post by Michael Vogel »

Not from an AI... (and also not as good as done by mksoft):

Code: Select all


Enumeration
	#FormProgram
	#Splitter
	#Panel
	#Editor
	#Container
EndEnumeration

Structure SplitterType
	ID.i
	Width.i
EndStructure

Global Splitter.SplitterType

Procedure WindowProc(hWnd,Msg,wParam,lParam)

	Protected width 

	With Splitter
		If hWnd=\ID
			If msg=#WM_PRINTCLIENT
				width=GetGadgetState(#Splitter)
				If width<>\Width
					\Width=width
					Debug "Splitter position "+Str(width)
				EndIf
			EndIf
		EndIf

	EndWith

	ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure

OpenWindow(#FormProgram,0,0, 600, 300,"Split",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar)
EditorGadget(#Editor, 0,0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))
PanelGadget(#Panel, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))

AddGadgetItem(#Panel, -1, "Panel")

ContainerGadget(#Container,0,0,WindowWidth(#FormProgram),WindowHeight(#FormProgram))
CloseGadgetList()
SetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE)|#WS_CLIPCHILDREN) ; <- important

CloseGadgetList()

Splitter\ID=SplitterGadget(#Splitter, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram), #Panel, #Editor, #PB_Splitter_Vertical|#PB_Splitter_Separator)
SetGadgetState(#Splitter, WindowWidth(#FormProgram) / 4)

SetWindowCallback(@WindowProc())

Repeat
	Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Splitter separate and event resizing [Resolved]

Post by Kwai chang caine »

Thanks to you two 8)

@MkSoft
That works, i have already see this solution with BindEvent(), but i searched with CallBack :wink:

@MichaelVogel
A long time i have not see your nice green duck 8)
I have try your code and not debug appear :|
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Michael Vogel
Addict
Addict
Posts: 2837
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Splitter separate and event resizing [Resolved]

Post by Michael Vogel »

Hm, seems to work here (Win 11, PB6.21/64)...
...have added a debugging window to check if messages are seen:

Code: Select all


Enumeration
	#FormProgram
	#Splitter
	#Panel
	#Editor
	#Container
	#DebugWin
	#DebugMessages
EndEnumeration

Structure SplitterType
	ID.i
	Width.i
	Container.i
EndStructure

Global Splitter.SplitterType

Global Dim Messages.i(2,30)
Global Lock

Procedure AddMessage(hWnd,Msg)

	Protected c,n

	Select hWnd
	Case Splitter\ID
		c=0
	Case Splitter\Container
		c=1
	Default
		c=2
	EndSelect

	n=19
	While n
		SetGadgetItemText(#DebugMessages,n,GetGadgetItemText(#DebugMessages,n-1,c),c)
		n-1
	Wend

	If c<2
		SetGadgetItemText(#DebugMessages,0,Str(Msg),c)
	Else
		SetGadgetItemText(#DebugMessages,0,Str(Msg)+" ("+Str(hwnd)+")",c)
	EndIf

EndProcedure

Procedure WindowProc(hWnd,Msg,wParam,lParam)

	Protected width

	If Msg And Lock=0
		Lock=1
		AddMessage(hwnd,Msg)
		Lock=0
	EndIf

	With Splitter
		If hWnd=\ID
			If msg=#WM_PRINTCLIENT
				width=GetGadgetState(#Splitter)
				If width<>\Width
					\Width=width
					Debug "Splitter position "+Str(width)
				EndIf
			EndIf
		EndIf

	EndWith

	ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure

OpenWindow(#DebugWin,640,0,420,600,"Messages")
ListIconGadget(#DebugMessages,0,0,420,600,"Splitter",100)
AddGadgetColumn(#DebugMessages,1,"Container",100)
AddGadgetColumn(#DebugMessages,2,"Others",200)
For i=0 To 19
	AddGadgetItem(#DebugMessages,i,"-"+#LF$+"-"+#LF$+"-")
Next i

OpenWindow(#FormProgram,0,0, 600, 300,"Split",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar)
EditorGadget(#Editor, 0,0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))
PanelGadget(#Panel, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram))

AddGadgetItem(#Panel, -1, "Panel")

Splitter\Container=ContainerGadget(#Container,0,0,WindowWidth(#FormProgram),WindowHeight(#FormProgram))
CloseGadgetList()
SetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Container), #GWL_STYLE)|#WS_CLIPCHILDREN) ; <- important

CloseGadgetList()

Splitter\ID=SplitterGadget(#Splitter, 0, 0, WindowWidth(#FormProgram), WindowHeight(#FormProgram), #Panel, #Editor, #PB_Splitter_Vertical|#PB_Splitter_Separator)
SetGadgetState(#Splitter, WindowWidth(#FormProgram) / 4)

SetWindowCallback(@WindowProc())

Repeat
	Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Lock=1

User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5614
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Splitter separate and event resizing [Resolved]

Post by Kwai chang caine »

Hello nice green duck

Thanks for this 2e version of your nice code 8)
But in your window message no information about the resizing and always no debug :shock:

And all of a sudden...i remember there are a long time, all the time the kind RASHAD lost with me, because his code not working only with KCC :oops:
Finally, it's because i believe, my windows configuration is a little bit like "Windows 95", no graphic effects, desktop black, no taskbar effect, the saddest in the world what :lol:
And for that, i don't understand why, several PB code, not work on my machine

Image

But FRED the great

Image

in all his power, it even thought of idiots like me, who hate flashing computer lights (even at Christmas).
And create "Just for KCC :mrgreen: " with a single blow of his vengeful arm

Image

this check box in his powerfull compilator
"Activate the visual theme support of XP and after"

Image

And like with RASHAD codes...yours work too..like in christmas miracle :shock:

You guys are too clever, because Microsoft hadn't planned to detect this event, and since you can't get in through the door, well, the great Michael Vogel comes in through the WINDOW(S) (KCC is too funny, with that "pun" :lol:)

Thanks a lot MASTER for this nice tips 8)
I was very happy to speak to one of the oldest members of "PB's" family.

Have the very best end of year

Image

Splendid green duck
which always made me laugh whenever I saw it, during all this numerous years :wink:
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
Post Reply