'Drag the controls, clicking on them. Resize them clicking the little square
'at the bottom of each control. Right click deletes the control below the
'cursor.
app$= "Liberty Composer v111"
' (Previously named: Super simple visual designer)
' (c) 2016 by cundo
' Find discussion and updates if any at : libertybasic.conforums.com
global control, grid, avoidList$
dim controlType$(100)
grid=24
WindowWidth = 640 : WindowHeight = 480
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
width=WindowWidth-150 : height=WindowHeight-150
stylebits #main.gbx,_WS_SIZEBOX OR _WS_BORDER or _WS_CAPTION, 0, 0, 0
graphicbox #main.gbx, WindowWidth/2-width/2, WindowHeight/2-height/2, width, height
stylebits #main.add, 0, 0, 0, 0
button #main.add,"&Menu",[addControl],ul,1,1,50,28
button #main.en,"&Enable all",[enableControls],ul,100,1,75,28
button #main.code,"&Produce Code", [code],ul,176,1,150,28
Open app$ For window As #main
call DrawGrid "#main.gbx",width*2,height*2
#main "trapclose quit"
wait
[code]
cls
Call GetRect hWnd(#main.gbx),winx,winy,winwidth,winheight
Print "NoMainWin"
Print "WindowWidth = ";winwidth ;" : WindowHeight = " ;winheight
Print "UpperLeftX = INT((DisplayWidth-WindowWidth)/2)"
Print "UpperLeftY = INT((DisplayHeight-WindowHeight)/2)"
Print
for i = 1 to control
if instr(avoidList$,";#";i)=0 then
h$= "#";i;".b1"
call GetRect hWnd(#h$),nul , nul , codewidth ,codeheight
h = hWnd(#main.gbx)
Calldll #user32, "ScreenToClient",h As ulong,Rect As struct,result as void
codex=Rect.x1.struct
codey=Rect.y1.struct
print controlType$(i);",";str$(codex);",";str$(codey);_
",";str$(codewidth);",";str$(codeheight)
' print controlType$(i);",";str$(px);",";str$(py);_
' ",";str$(controlWidth);",";str$(controlHeight)
end if
next i
Print
Print "Open ";chr$(34);"Window";chr$(34);" for Window as #main"
Print "#main ";chr$(34);"trapclose [quit]";chr$(34)
Print "wait"
Print
Print "[quit]"
Print "close #main"
Print "End"
wait
[enableControls]
if control then
#main.en word$("&Disable all; &Enable all",areOn+1,";")
areOn = abs(not(areOn))
for i = 1 to control
EnableThisHandle$ = "#";i;".b1"
EnableThisWHandle$= "#";i
call EnableWindow hWnd(#EnableThisHandle$), areOn
next
end if
wait
[addControl]
color$="BUTTONFACE"
controlWidth=100 : controlHeight=30
px= int(rnd(0)*(400-controlWidth))
py= int(rnd(0)*(300-controlHeight-30))
WindowWidth =controlWidth : WindowHeight = controlHeight
dim array$(10)
for i = 1 to 10
array$(i)="Drag me please"
next
stylebits #101.gfx, 0, _WS_BORDER, 0, 0
stylebits #101.b1, _WS_DISABLED, 0, 0, 0
gfxw=controlWidth : gfxh=controlHeight
graphicBox #101.gfx, px,py,gfxw+9,gfxh+9
popupmenu "add button",[buttonCode],"add textbox",[txtCode],_
"add listbox",[listCode],"add static",[staticCode],_
"add combobox",[comboCode],"add radiobutton",[radioCode],_
"add texteditor",[edCode],"add checkbox",[chkCode],_
"add graphicbox",[blank]
wait
[buttonCode]
type$="button #main.b";control+1;",";chr$(34);"Button";chr$(34);_
", [quit],ul"
button #101.b1,"Drag me ";control+1,dummy,ul,_
0,0,controlWidth,controlHeight :goto [createWindow]
[txtCode]
type$="textbox #main.tb";control+1
textbox #101.b1,0,0,controlWidth,controlHeight : goto [createWindow]
[listCode]
type$="listbox #main.lbx";control+1;",ar$(,dummy"
listbox #101.b1, array$(), dummy,_
0, 0, controlWidth, controlHeight : goto [createWindow]
[staticCode]
type$="statictext #main.st";control+1;",";chr$(34);"static";chr$(34)
statictext #101.b1,"Drag me",_
0,0,controlWidth,controlHeight : goto [createWindow]
[comboCode]
type$="combobox #main.combo";control+1;",ar$(,dummy"
combobox #101.b1, array$(), dummy,_
0, 0, controlWidth, controlHeight : goto [createWindow]
[radioCode]
type$="radiobutton #main.rb";control+1;",";chr$(34);"Radio";chr$(34);_
",dummy,dummy"
radiobutton #101.b1, "Drag me", dummy, dummy,_
0, 0, controlWidth, controlHeight : goto [createWindow]
[edCode]
type$="texteditor #main.txt";control+1
texteditor #101.b1, 0, 0,_
controlWidth, controlHeight : goto [createWindow]
[chkCode]
type$="checkbox #main.rb";control+1;",";chr$(34);"Radio";chr$(34);_
",dummy,dummy"
checkbox #101.b1, "Drag me", dummy, dummy,_
0, 0, controlWidth, controlHeight : goto [createWindow]
[blank]
type$="graphicbox #main.gbx";control+1
stylebits #101.b1, _WS_BORDER OR _WS_DISABLED, 0, 0, 0
' dummy control, I just need a 'b1' control
statictext #101.b1,"",0,0,controlWidth,controlHeight
' stylebits #101.gfx, 0,0,0,0 : color$="WHITE;|";chr$(13);"hello"
[createWindow]
' needs a menu supported window to avoid an error.log entry
' 'Kill BASIC Apps'
stylebits #101, _WS_SYSMENU, _WS_VISIBLE,0, 0
Open "" For window_popup As #101
#101.gfx "down;fill ";color$
#101.gfx "place ";gfxw;" ";gfxh
call Draw "#101.gfx", gfxw, gfxh
#101.gfx "When leftButtonMove lbm"
#101.gfx "When rightButtonDown delete"
call setParent hWnd(#101.gfx),hWnd(#101.b1)
call setParent hWnd(#main.gbx),hWnd(#101.gfx)
control=control+1
controlType$(control)=type$
newHandle$="#";control
maphandle #101,newHandle$
Wait
Sub quit h$
for i = 1 to control
newHandle$="#";i
if instr(avoidList$,newHandle$)=0 then
close #newHandle$
end if
next
close #main
End
End Sub
Sub lbm h$, X, Y
handler$ = Word$(h$, 1, ".")
hWnd = hWnd(#h$)
'print h$,handler$
CallDll #user32, "ReleaseCapture",r As void
Call GetRect hWnd, nul , nul , w ,h
q=_HTCAPTION 'by default, grab the window
if abs(w-X)<=10 AND abs(h-Y)<=10 then
' the lower right corner
' means a resize event
q=_HTBOTTOMRIGHT
end if
CallDLL #user32, "SendMessageA", _
hWnd As ULong, _
_WM_NCLBUTTONDOWN As ULong, _
q As uLong, _
0 As Long, _
r As void
'also resize the control inside the graphicbox
if q=_HTBOTTOMRIGHT then
Call GetRect hWnd, nul , nul , w ,h
w=w-9 : h = h-9
b1h$ = handler$;".b1"
b1h = hwnd(#b1h$)
call MoveWindow b1h,0,0,w,h
call Draw h$,w,h
end if
' align to grid
Call GetRect hWnd, nul , nul , w ,h
main = hWnd(#main.gbx)
Calldll #user32, "ScreenToClient",main As ulong,Rect As struct,result as void
x1 = int(Rect.x1.struct/grid)*grid
y1 = int(Rect.y1.struct/grid)*grid
Call MoveWindow hWnd,x1,y1, w, h
End Sub
Sub delete h$,x,y
win$ = word$(h$,1,".")
n$=word$(h$,2,".")
confirm "Delete this control?"; responseVar$
If responseVar$="yes" Then
close #win$
avoidList$=avoidList$;";";win$
End if
End Sub
Sub dummy h$
End Sub
Sub setParent parent,child
calldll #user32, "SetParent",_
child as ulong,_
parent as ulong,_
r as void
End Sub
Sub ShowWindow hWnd, flag
CallDLL #user32, "ShowWindow",_
hWnd as uLong, flag As uLong,_
r As void
End Sub
Sub EnableWindow hWnd, flag
CallDLL #user32, "EnableWindow",_
hWnd as uLong, flag As uLong,_
r As void
End Sub
Sub GetWindowRect hW
struct Rect, x1 As Long, y1 As Long, x2 As Long, y2 As Long
CallDLL #user32, "GetWindowRect",_
hW as uLong,Rect As struct, result As void
End Sub
Sub Draw h$,x,y
#h$ "cls;fill buttonface;";_
"place ";x-1;" ";y-1
#h$ "color buttonface"
#h$ "backcolor buttonface"
#h$ "rule ";_R2_NOT
#h$ "boxfilled ";x+5;" ";y+5
#h$ "line ";x;" ";y+2;" ";x+5;" ";y+2
#h$ "line ";x+2;" ";y;" ";x+2;" ";y+5
#h$ "flush"
End sub
Sub DrawGrid h$,width,height
#h$ "cls"
#h$ "down;fill buttonface ;flush"
#h$ "size 1;color BLACK"
for x = 0 to width step grid
for y = 0 to height step grid
#h$ "set ";x;" ";y
next:next
#h$ "flush;up"
#h$ "setfocus"
End Sub
Sub MoveWindow hnd,x,y,w,h
calldll #user32, "MoveWindow",_
hnd as ulong, _ 'window handle
x as long,_ 'x location of gfx window
y as long,_ 'y location of gfx window
w as long,_ 'desired width of window
h as long,_ 'desired height of window
1 as long,_ 'repaint flag,0=false,1=true
ret as void 'nonzero=success
End Sub
Sub GetRect hnd, byref x , byref y , byref w ,byref h
call GetWindowRect hnd
x= Rect.x1.struct
y= Rect.y1.struct
w= Rect.x2.struct-Rect.x1.struct
h= Rect.y2.struct-Rect.y1.struct
End SUb
'include lb45func.bas