This is updated code...
It uses InnerWindowMouseX() and InnerWindowMouseY() - see procedures.
Thanks goes to Berikco for the hint.
Code changed on Win2k-Sp3. Have to test it under WinXP though.
Hope it's useful for some of you.
Any questions or suggestions are welcome

Code: Select all
; (c) 2003 - Franco's template - absolutely freeware
; This is a Gadget Splitter
; Should work fine on all Windows Operating Systems
;
; Normally if you have 2 ListViews (or TreeViews etc.) and you want
; change the width of both (one decreases the other increases) you
; use mouse hot spots between the Gadgets.
; Negative about this is the manually setting of this hotspot.
; Every time you change the position of your ListViews, you have to
; adapt the hotspot.
; Also sometimes it doesn't work properly...
; (see PureBasic Editor while the Procedure Browser is on the left,
; the Arrow Cursor appears also inside the RichEdit Gadget.
; Also the Gadgets Splitter example in PureBasic v3.00 - nowadays disappeared...)
;
; Now here this "hotspot" works different.
; It is realized as a Gadget = SplitterGadget(...)
; No adaptation is required!
; How is this done?
;
; You create two gadgets which you want to incorporate in your
; splitter function. Example:
; ListViewGadget(1, 10, 10, 88, 200)
; or
; ListViewGadget(2, 0, 0, 0, 0) ; I talk about the zeros later...
;
; After that, you have to create the SplitterGadget with:
; SplitterGadget(GadgetNumber.l, PositionX.l, PositionY.l, Width.l, Height.l, LeftGadget.l, RightGadget.l)
;
; The PositionX, PositionY, Width and Height are the maximum area
; of all incorporated Gadgets. That's why it's possible to do:
; ListViewGadget(2, 0, 0, 0, 0).
; This values are changed when you call the SplitterGadget.
; For this you have to tell the SplitterGadget which Gadgets to work with.
; This can be done with the parameters LeftGadget and RightGadget.
; That's it!
;
; As you can see, you have to click the toggle button on the SplitterGadget
; and than you can move it. A second click will freeze it at the actual position.
; I know, the use is different than normal hotspots, but I think this approach
; is more elegant - and personally I don't care if I have to click twice.
;
; The Procedures SetSplitterGadget() and WatchSplitterGadget() must be
; incorporated in the event handler as seen in this example.
;
; The return value of SplitterGadget is the Windows-OS handle of this Gadget.
;
; BTW:
; The cursor changes with the action... nice isn't it?
; And only if it is over the SplitterGadget, nowhere else !
;
; Also this is the newest version with compensation of the Windows Border/Theme.
; Thanks to Berikco for the hint :)
;
; And here it goes:
Procedure DualSplitterGadget(GadgetNumber.l, PositionX.l, PositionY.l, Width.l, Height.l, LeftGadget.l, RightGadget.l)
Shared Splitter_Toggle, Splitter_HandCursor.l, Splitter_ArrowCursor.l
Shared Splitter_GadgetX1, Splitter_GadgetX2
RoomBetweenGadgets.l = 4
SplitterGadgetWidth.l = 4
SplitterGadgetHeight.l = Height - (RoomBetweenGadgets * 2)
SplitterGadgetX.l = PositionX + Width/2 - SplitterGadgetWidth/2
SplitterGadgetY.l = PositionY + 4
LeftGadgetWidth.l = SplitterGadgetX - 4 - PositionX
ResizeGadget(LeftGadget, PositionX, PositionY, LeftGadgetWidth, Height)
RightGadgetX.l = SplitterGadgetX + SplitterGadgetWidth + RoomBetweenGadgets
RightGadgetWidth.l = PositionX + Width - RightGadgetX
ResizeGadget(RightGadget, RightGadgetX, PositionY, RightGadgetWidth, Height)
SplitterID.l = ButtonGadget(GadgetNumber, SplitterGadgetX, SplitterGadgetY, SplitterGadgetWidth, SplitterGadgetHeight,"",#PB_Button_Toggle)
SetClassLong_(SplitterID,#GCL_HCURSOR,0)
Splitter_ArrowCursor = LoadCursor_(0, #IDC_SIZEWE)
Splitter_HandCursor = LoadCursor_(0, 32649); #IDC_HAND not recognized by PureBasic
Splitter_Toggle = 0
Splitter_GadgetX1.l = PositionX
Splitter_GadgetX2.l = PositionX + Width
ProcedureReturn SplitterID
EndProcedure
Procedure SetDualSplitterGadget()
Shared Splitter_Toggle
If Splitter_Toggle = 0
Splitter_Toggle = 1
ElseIf Splitter_Toggle = 1
Splitter_Toggle = 0
EndIf
EndProcedure
Procedure InnerWindowMouseX()
ProcedureReturn WindowMouseX() - GetSystemMetrics_(#SM_CYSIZEFRAME)
EndProcedure
Procedure InnerWindowMouseY()
ProcedureReturn WindowMouseY() - GetSystemMetrics_(#SM_CYCAPTION) - GetSystemMetrics_(#SM_CYSIZEFRAME)
EndProcedure
Procedure WatchDualSplitterGadget()
Shared Splitter_HandCursor, Splitter_ArrowCursor, Splitter_Toggle
Shared Splitter_GadgetX1, Splitter_GadgetX2
If Splitter_Toggle = 0 And ChildWindowFromPoint_(WindowID(),InnerWindowMouseX(),InnerWindowMouseY()) = GadgetID(2)
SetCursor_(Splitter_HandCursor)
ElseIf Splitter_Toggle = 1 And InnerWindowMouseX() > Splitter_GadgetX1 And InnerWindowMouseX()