Post by Walt Decker on Feb 1, 2021 14:08:46 GMT -5
The snippet below is the only way I have found to create multiple instances of the same control on a window without having to hard code each one.
The attached zip file has a main module, a mixer module and the below module (slightly modified) plus the DLLs you will need to make it work.
MULTI_CTRL.ZIP (45.37 KB)
There is are at least two problems with the code in the zip.
1) When it closes I get an "invalid branch label: [Finshed]" error.
2) WS.EX.TOPMOST style is supposed to keep the mixer in view; however, it fails to do so.
You will notice that there are only 4 controls on the "palette" module. The reason is to reduce the number of handles listed when closing. If you want more change the followin sequence to the numbers you want but not more than 15.
I apologize for the mish-mash code. I have not worked with spaghetti code for 30 years.
Elms = -1
FOR I = 0 TO 1'5
FOR J = 0 TO 1'5
Elms = Elms + 1
Hndl = 0
Names$ = ""
GfxHndls(Elms) = FN.CreateGfx(Elms, Hndl, Names$)
GfxNames$(Elms) = Names$
CtlHndls(Elms) = Hndl
NEXT J
NEXT I
Elms = -1
FOR I = 0 TO 1'5
FOR J = 0 TO 1'5
Elms = Elms + 1
Hndl = GfxHndls(Elms)
Ok = FN.SetParent(WinHndl, Hndl, StartX, StartY, GfxWide, GfxHigh)
StartX = StartX + GfxWide + Offs
NEXT J
StartX = Offs
StartY = StartY + GfxHigh + Offs
NEXT I
The attached zip file has a main module, a mixer module and the below module (slightly modified) plus the DLLs you will need to make it work.
MULTI_CTRL.ZIP (45.37 KB)
There is are at least two problems with the code in the zip.
1) When it closes I get an "invalid branch label: [Finshed]" error.
2) WS.EX.TOPMOST style is supposed to keep the mixer in view; however, it fails to do so.
You will notice that there are only 4 controls on the "palette" module. The reason is to reduce the number of handles listed when closing. If you want more change the followin sequence to the numbers you want but not more than 15.
I apologize for the mish-mash code. I have not worked with spaghetti code for 30 years.
Elms = -1
FOR I = 0 TO 1'5
FOR J = 0 TO 1'5
Elms = Elms + 1
Hndl = 0
Names$ = ""
GfxHndls(Elms) = FN.CreateGfx(Elms, Hndl, Names$)
GfxNames$(Elms) = Names$
CtlHndls(Elms) = Hndl
NEXT J
NEXT I
Elms = -1
FOR I = 0 TO 1'5
FOR J = 0 TO 1'5
Elms = Elms + 1
Hndl = GfxHndls(Elms)
Ok = FN.SetParent(WinHndl, Hndl, StartX, StartY, GfxWide, GfxHigh)
StartX = StartX + GfxWide + Offs
NEXT J
StartX = Offs
StartY = StartY + GfxHigh + Offs
NEXT I
WS.CHILD = HEXDEC("&H40000000")
WS.VISIBLE = HEXDEC("&H10000000")
WS.BORDER = HEXDEC("&H00800000")
WS.THICKFRAME = HEXDEC("&H00040000")
WS.SYSMENU = HEXDEC("&H00080000")
WS.MINIMIZEBOX = HEXDEC("&H00020000")
WS.MAXIMIZEBOX = HEXDEC("&H00010000")
STRUCT tRect, _
X AS LONG, _
Y AS LONG, _
X1 AS LONG, _
Y1 AS LONG
OPEN "User32" FOR DLL AS #USER
OPEN "gdi32" FOR DLL AS #GDI
StartX = 2
StartY = 2
GfxWide = 15
GfxHigh = 15
Offs = 2
Elms = -1
Hndl = 0
HiLite = 0
LstHiLite = 0
Colour = 0
I = 0
J = 0
X = 0
Y = 0
X1 = 0
Y1 = 0
Names$ = ""
DIM GfxHndls(255)
DIM GfxNames$(255)
DIM CtlHndls(255)
DIM CtlColor(255)
UpperLeftX = 100
UpperLeftY = 100
WindowWidth = (GfxWide * 16) + (Offs * 16) + 16
WindowHeight = (GfxHigh * 16) + (Offs * 16) + 42
OPEN "PALETTE" FOR WINDOW AS #PAL
PRINT #PAL, "TRAPCLOSE [Finished]"
WinHndl = HWND(#PAL)
CALLDLL #USER, "ShowWindow", WinHndl AS ULONG, 0 AS ULONG, RetVal AS VOID
Elms = -1
FOR I = 0 TO 15
FOR J = 0 TO 15
Elms = Elms + 1
Hndl = 0
Names$ = ""
GfxHndls(Elms) = FN.CreateGfx(Elms, Hndl, Names$)
GfxNames$(Elms) = Names$
CtlHndls(Elms) = Hndl
NEXT J
NEXT I
Elms = -1
FOR I = 0 TO 15
FOR J = 0 TO 15
Elms = Elms + 1
Hndl = GfxHndls(Elms)
Ok = FN.SetParent(WinHndl, Hndl, StartX, StartY, GfxWide, GfxHigh)
StartX = StartX + GfxWide + Offs
NEXT J
StartX = Offs
StartY = StartY + GfxHigh + Offs
NEXT I
WinStyle = 0
CALLDLL #USER, "GetWindowLongA", WinHndl AS ULONG, _GWL_STYLE AS LONG, _
WinStyle AS ULONG
WinStyle = WinStyle XOR WS.THICKFRAME
CALLDLL #USER, "SetWindowLongA", WinHndl AS ULONG, _GWL_STYLE AS LONG, _
WinStyle AS ULONG, RetVal AS VOID
CALLDLL #USER, "ShowWindow", WinHndl AS ULONG, 1 AS ULONG, RetVal AS VOID
PRINT #PAL, "REFRESH"
Hndl = CtlHndls(LstHiLite)
Names$ = GfxNames$(LstHiLite)
Colour = CtlColor(LstHiLite)
'RetVal = FN.UnHiLite(Hndl, Colour, Names$)
'LstHiLite = FN.SetHiLite(Hndl, Colour, HiLite, Names$)
[WAIT.FOR.IT]
WAIT
END
[Finished]
FOR I = 0 TO 255
NewName$ = GfxNames$(I)
IF NewName$ = "" THEN GOTO [InitFor]
CLOSE #NewName$
[InitFor]
NEXT I
CLOSE #PAL
CLOSE #USER
CLOSE #GDI
END
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
FUNCTION FN.CreateGfx(Elms, BYREF CtlHndl, BYREF NewName$)
UpperLeftX = 2
UpperLeftY = 2
WindowWidth = 15
WindowHeight = 15
WinHndl = 0
GRAPHICBOX #GFX.GFX, 0, 0, 13, 13
OPEN "" FOR WINDOW AS #GFX
WinHndl = HWND(#GFX)
CtlHndl = HWND(#GFX.GFX)
CALLDLL #USER, "ShowWindow", WinHndl AS ULONG, 0 AS ULONG, RetVal AS VOID
PRINT #GFX.GFX, "home"
PRINT #GFX.GFX, "down"
PRINT #GFX.GFX, "fill black"
PRINT #GFX.GFX, "flush"
NewName$ = "GFX" + TRIM$(STR$(Elms))
MAPHANDLE #GFX, NewName$
FN.CreateGfx = WinHndl
END FUNCTION
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
FUNCTION FN.SetParent(WinHndl, ChildHndl, StartX, StartY, KidWide, KidHigh)
WS.CHILD = HEXDEC("&H40000000")
WS.VISIBLE = HEXDEC("&H10000000")
WS.BORDER = HEXDEC("&H00800000")
STRUCT tRect, _
X AS LONG, _
Y AS LONG, _
X1 AS LONG, _
Y1 AS LONG
STYLE = 0
RetVal = 0
Brush = 0
KidDc = 0
CALLDLL #USER, "SetParent", ChildHndl AS ULONG, WinHndl AS ULONG, RetVal AS ULONG
Value = 0
STYLE = WS.CHILD OR WS.VISIBLE' OR WS.BORDER
CALLDLL #USER, "SetWindowLongA", ChildHndl AS ULONG, _GWL_STYLE AS LONG, _
STYLE AS ULONG, Value AS ULONG
CALLDLL #USER, "MoveWindow", ChildHndl AS ULONG, StartX AS LONG, StartY AS LONG, _
KidWide AS LONG, KidHigh AS LONG, 1 AS BOOLEAN, RetVal AS VOID
FN.SetParent = Value
END FUNCTION
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------