ok here is a beta test version of my DUI hwnd library. this took ALOT of work to get working just right, complete with auto-moving and scrollbar hiding and showing. this code will also serve as a template to create an "oulook gadget" that is a complete standalone gadget that will be recognized as a single entity, totally subclassed and not interfering with ANY window callback. any comments ot suggestions are welcome.
Code: Select all
#duiup=$FF06
#duidown=$FF07
Structure inf
gadgethght.i
scrollgadget.i
parent.i
duinum.i[10]
State.i[10]
hwnd.i[10]
parenthwnd.i[10]
imagehwnd.i[10]
button.i[10]
buttonstate.i[10]
width.i
height.i[10]
hyperlink.i[50]
textgad.i[10]
yvalue.i[10]
scrollheight.i
EndStructure
Structure prop
width.i
hwnd.i
EndStructure
Procedure InitDUI()
Global NewList dui.inf()
Global Dim icon(100)
EndProcedure
Procedure checkscrollheight(DUIpane)
scrollmax=20
SelectElement(dui(),DUIpane)
For a=0 To 9
If dui()\height[a]=0
scrollmax=dui()\yvalue[a-1]+dui()\height[a-1]
Break
EndIf
Next
If scrollmax>dui()\scrollheight
SetGadgetAttribute(dui()\scrollgadget,#PB_ScrollArea_InnerHeight,scrollmax+10)
SetWindowPos_(GadgetID(dui()\scrollgadget),0,0,0,dui()\width+30,dui()\gadgethght,#SWP_NOMOVE)
RedrawWindow_(GadgetID(dui()\scrollgadget),0,0,#RDW_ALLCHILDREN)
Else
SetGadgetAttribute(dui()\scrollgadget,#PB_ScrollArea_InnerHeight,dui()\scrollheight)
SetWindowPos_(GadgetID(dui()\scrollgadget),0,0,0,dui()\width+10,dui()\gadgethght,#SWP_NOMOVE)
RedrawWindow_(GadgetID(dui()\scrollgadget),0,0,#RDW_ALLCHILDREN)
EndIf
EndProcedure
Procedure moveproc(hwnd,msg,wParam,lParam)
Select msg
Case #duiup
SelectElement(dui(),lParam)
heighttomove=dui()\height[wParam]-20
For a=wParam+1 To 9
height=dui()\height[a]-20
yval=dui()\yvalue[a]-heighttomove
SetWindowPos_(dui()\hwnd[a],0,5,yval,0,0,#SWP_NOSIZE)
dui()\yvalue[a]=yval
Next
checkscrollheight(lParam)
ProcedureReturn 0
Case #duidown
SelectElement(dui(),lParam)
heighttomove=dui()\height[wParam]-20
For a=wParam+1 To 9
height=dui()\height[a]
yval=dui()\yvalue[a]+heighttomove
SetWindowPos_(dui()\hwnd[a],0,5,yval,0,0,#SWP_NOSIZE)
dui()\yvalue[a]=yval
Next
checkscrollheight(lParam)
ProcedureReturn 0
EndSelect
ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc2"),hwnd,msg,wParam,lParam)
EndProcedure
Procedure buttonproc(hwnd,msg,wParam,lParam)
Select msg
Case #WM_CTLCOLORSTATIC
#clnavy=$00800000
blue = CreateSolidBrush_(#clnavy)
ForEach dui()
For a=0 To 9
If IsGadget(dui()\textgad[a])
If lParam=GadgetID(dui()\textgad[a])
SetTextColor_(wParam,#White) ;Text colour
SetBkColor_(wParam, #clnavy) ;Background colour
EndIf
EndIf
Next
Next
ProcedureReturn blue
Case #WM_COMMAND
parent=GetParent_(hwnd)
ForEach dui()
For a=0 To 9
If parent=dui()\hwnd[a]
currentdui=ListIndex(dui())
scrollparent=GetParent_(dui()\hwnd[a])
If dui()\State[a]=1
SetWindowPos_(dui()\hwnd[a],0,0,0,dui()\width,20,#SWP_NOMOVE)
dui()\State[a]=0
PostMessage_(scrollparent,#duiup,a,ListIndex(dui()))
ElseIf dui()\State[a]=0
SetWindowPos_(dui()\hwnd[a],0,0,0,dui()\width,dui()\height[a],#SWP_NOMOVE)
dui()\State[a]=1
PostMessage_(scrollparent,#duidown,a,ListIndex(dui()))
EndIf
Break
EndIf
Next
Next
ProcedureReturn 0
Case #WM_LBUTTONDBLCLK
parent=GetParent_(hwnd)
ForEach dui()
For a=0 To 9
If parent=dui()\hwnd[a]
currentdui=ListIndex(dui())
scrollparent=GetParent_(dui()\hwnd[a])
If dui()\State[a]=1
SetWindowPos_(dui()\hwnd[a],0,0,0,dui()\width,20,#SWP_NOMOVE)
SendMessage_(GadgetID(dui()\button[a]),#BM_SETCHECK,#BST_UNCHECKED,0)
dui()\State[a]=0
PostMessage_(scrollparent,#duiup,a,ListIndex(dui()))
ElseIf dui()\State[a]=0
SetWindowPos_(dui()\hwnd[a],0,0,0,dui()\width,dui()\height[a],#SWP_NOMOVE)
SendMessage_(GadgetID(dui()\button[a]),#BM_SETCHECK,#BST_CHECKED,0)
PostMessage_(scrollparent,#duidown,a,ListIndex(dui()))
dui()\State[a]=1
EndIf
Break
EndIf
Next
Next
EndSelect
ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc1"),hwnd,msg,wParam,lParam)
EndProcedure
Procedure DUIpane(number,x,y,panewidth,height,border)
AddElement(dui())
SelectElement(dui(),number)
dui()\gadgethght=height
dui()\width=panewidth-10
scroll=ScrollAreaGadget(#PB_Any,x,y,panewidth,height,panewidth-5,height-20,30,#PB_ScrollArea_Flat )
dui()\scrollgadget=scroll
dui()\scrollheight=height-20
child=GetWindow_(GadgetID(scroll),#GW_CHILD)
dui()\parent=child
SetProp_(child,"OldProc2",SetWindowLong_(child, #GWL_WNDPROC, @moveproc()))
icon(number)=CreateImage(number+200,dui()\width,20)
StartDrawing(ImageOutput(number+200))
#clnavy=$00800000
Box(0,0,dui()\width,20,#clnavy)
StopDrawing()
ProcedureReturn scroll
EndProcedure
Procedure AddDUIhwnd(DUIpane,Position,text.s)
SelectElement(dui(),DUIpane)
dui()\duinum[Position]=Position
dui()\height[Position]=50
totalheight=20
For a=0 To Position-1
totalheight=totalheight+dui()\height[a]+10
Next
If Position=0
dui()\yvalue[Position]=20
ElseIf Position<>0
dui()\yvalue[Position]=totalheight
EndIf
mainhandle=OpenWindow(#PB_Any,5,dui()\yvalue[Position],dui()\width,50,"",#PB_Window_Invisible)
dui()\hwnd[Position]=WindowID(mainhandle)
SetWindowLong_(dui()\hwnd[Position],#GWL_STYLE, #WS_CHILD|#WS_BORDER|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
SetParent_(dui()\hwnd[Position],dui()\parent)
dui()\imagehwnd[Position]=ImageGadget(#PB_Any,0,0,dui()\width,20,0)
SetGadgetState(dui()\imagehwnd[Position],icon(DUIpane))
dui()\button[Position]=ButtonGadget(#PB_Any,dui()\width-18,2,16,16,"^")
style = GetWindowLong_(GadgetID(dui()\button[Position]), #GWL_STYLE)
toggleStyle=style|$1083
SetWindowLong_(GadgetID(dui()\button[Position]), #GWL_STYLE, toggleStyle)
SetParent_(GadgetID(dui()\button[Position]),GadgetID(dui()\imagehwnd[Position]))
dui()\textgad[Position]=TextGadget(#PB_Any,0,2,dui()\width-19,20,text,#PB_Text_Center)
SetParent_(GadgetID(dui()\textgad[Position]),GadgetID(dui()\imagehwnd[Position]))
SendMessage_(GadgetID(dui()\button[Position]),#BM_SETCHECK,#BST_CHECKED,0)
SetProp_(GadgetID(dui()\imagehwnd[Position]),"OldProc1",SetWindowLong_(GadgetID(dui()\imagehwnd[Position]), #GWL_WNDPROC, @buttonproc()))
ShowWindow_(dui()\hwnd[Position],#SW_SHOW)
SetWindowPos_(dui()\hwnd[Position],0,0,0,dui()\width,50,#SWP_NOMOVE)
RedrawWindow_(dui()\hwnd[Position],0,0,#RDW_ALLCHILDREN )
UpdateWindow_(dui()\hwnd[Position])
dui()\State[Position]=1
checkscrollheight(DUIpane)
EndProcedure
Procedure addDUIlink(DUIpane,DuiHwnd,Position,text.s,color)
SelectElement(dui(),DUIpane)
UseGadgetList(dui()\hwnd[DuiHwnd])
hyperlink=HyperLinkGadget(#PB_Any, 5, (Position*20) +25,dui()\width,20,text, color)
RedrawWindow_(dui()\hwnd[DuiHwnd],0,0,#RDW_ALLCHILDREN )
ShowWindow_(dui()\hwnd[DuiHwnd],#SW_SHOWNORMAL)
UpdateWindow_(dui()\hwnd[DuiHwnd])
If Position =0
dui()\height[DuiHwnd]=50
ElseIf Position>0
dui()\height[DuiHwnd]=50+(Position*20)
SetWindowPos_(dui()\hwnd[DuiHwnd],0,0,0,dui()\width,dui()\height[DuiHwnd],#SWP_NOMOVE)
If Position>1
For a=DuiHwnd+1 To 9
SetWindowPos_(dui()\hwnd[a],0,5,dui()\yvalue[a]+(Position*20),0,0,#SWP_NOSIZE)
dui()\yvalue[a]=dui()\yvalue[a]+(Position*20)
Next
EndIf
EndIf
checkscrollheight(DUIpane)
ProcedureReturn hyperlink
EndProcedure
Procedure HideDUI(DUIpane,DuiHwnd,State)
If State=0
If dui()\State[DuiHwnd]=0
SelectElement(dui(),DUIpane)
parent=GetParent_(dui()\hwnd[DuiHwnd])
SetWindowPos_(dui()\hwnd[DuiHwnd],0,0,0,dui()\width,dui()\height[DuiHwnd],#SWP_NOMOVE)
SendMessage_(GadgetID(dui()\button[DuiHwnd]),#BM_SETCHECK,#BST_CHECKED,0)
dui()\State[DuiHwnd]=1
PostMessage_(parent,#duidown,DuiHwnd,ListIndex(dui()))
EndIf
ElseIf State=1
If dui()\State[DuiHwnd]=1
SelectElement(dui(),DUIpane)
parent=GetParent_(dui()\hwnd[DuiHwnd])
SetWindowPos_(dui()\hwnd[DuiHwnd],0,0,0,dui()\width,20,#SWP_NOMOVE)
SendMessage_(GadgetID(dui()\button[DuiHwnd]),#BM_SETCHECK,#BST_UNCHECKED,0)
dui()\State[DuiHwnd]=0
PostMessage_(parent,#duiup,DuiHwnd,ListIndex(dui()))
EndIf
EndIf
EndProcedure
Procedure GetDUIstate(duinumber)
SelectElement(dui(),duinumber)
returnvalue=dui()\State[duinumber]
ProcedureReturn returnvalue
EndProcedure
OpenWindow(0,0,0,270,260,"DirectUIhwnd",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
InitDUI()
sg=DUIpane(0,10,10,150,220,0)
AddDUIhwnd(0,0,"Commands")
AddDUIhwnd(0,1,"test2")
AddDUIhwnd(0,2,"test3")
link=addDUIlink(0,0,0,"Message Box",$FF04)
link2=addDUIlink(0,0,1,"Hide Other DUI",$FF04)
link3=addDUIlink(0,0,2,"Show Other DUI",$FF04)
link4=addDUIlink(0,1,0,"Blah",$FF04)
link5=addDUIlink(0,1,1,"More Blah",$FF04)
link6=addDUIlink(0,1,2,"Some Stuff",$FF04)
Repeat
Select WindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case link
MessageRequester("hi","It really works",#PB_MessageRequester_Ok)
Case link2
HideDUI(0,1,1)
Case link3
HideDUI(0,1,0)
EndSelect
Case #PB_Event_CloseWindow
Quit=1
EndSelect
Until Quit=1