DirectUIHwnd beta test

Share your advanced PureBasic knowledge/code with the community.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

DirectUIHwnd beta test

Post by localmotion34 »

Code updated for 5.20+

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

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

nice :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Hi LocalMotion,

your lib keeps getting better and better! I like what I saw so far.

Something to check out from your side:
- create a DUI box that contains more than three links/choices. Look at what happens with the white space between that DUI box and the next one below it. From the fourth link onwards, for each additional link in the box two additional lines of white space are created between that DUI box and the next one...

Once you have this ironed out, please consider dressing up the concept a bit by allowing bitmaps on the button that collapses/enlarges a DUI box.

Keep up the good work and thanks a lot for sharing it!
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Hi LocalMotion,

here's the code that shows the problem I described above:

Code: Select all

#duiup=$FF06 
#duidown=$FF07 

Structure inf 
  gadgethght.l 
  scrollgadget.l 
  parent.l 
  duinum.l[10] 
  State.l[10] 
  hwnd.l[10] 
  parenthwnd.l[10] 
  imagehwnd.l[10] 
  button.l[10] 
  buttonstate.l[10] 
  width.l 
  height.l[10] 
  hyperlink.l[50] 
  textgad.l[10] 
  yvalue.l[10] 
  scrollheight.l 
EndStructure 

Structure prop 
  width.l 
  
  hwnd.l 
EndStructure 
  
Procedure InitDUI() 
  NewList dui.inf() 
  Dim icon.l(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 lParam=GadgetID(dui()\textgad[a]) 
            SetTextColor_(wParam,#White) ;Text colour 
            SetBkColor_(wParam, #clnavy) ;Background colour 
          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()) 
  #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) 
  CreateGadgetList(dui()\hwnd[Position]) 
  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.l) 
  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,460,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"DirectUIhwnd") And CreateGadgetList(WindowID(0)) 
InitDUI() 
sg=DUIpane(0,10,10,150,420,0) 
AddDUIhwnd(0,0,"File Commands") 
AddDUIhwnd(0,1,"Disk Commands") 
AddDUIhwnd(0,2,"Printer Commands")
AddDUIhwnd(0,3,"Networking Commands") 
AddDUIhwnd(0,4,"Serial Port Commands")

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,0,3,"Hide Other DUI",$FF04) 
link5=addDUIlink(0,0,4,"Show Other DUI",$FF04) 

link6=addDUIlink(0,1,0,"Blah",$FF04) 
link7=addDUIlink(0,1,1,"More Blah",$FF04) 
link8=addDUIlink(0,1,2,"Some Stuff",$FF04)
link8=addDUIlink(0,1,3,"Yet More Blah",$FF04) 
link10=addDUIlink(0,1,4,"Yet More Stuff",$FF04)
 
link11=addDUIlink(0,2,0,"Blah",$FF04) 
link12=addDUIlink(0,2,1,"More Blah",$FF04) 
link13=addDUIlink(0,2,2,"Some Stuff",$FF04) 

Repeat 
  Select WindowEvent() 
    Case #PB_Event_Gadget 
      Select EventGadgetID() 
        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_EventCloseWindow 
      Quit=1 
  EndSelect 
Until Quit=1 
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Hey, you strike again.
The functionality is great, but the look of it is not . maybe some size and style customization would be nice.

I dont know if a programmer will understand this :P (nothing personal but we all know most programers cant even make something good out of paint). Again dont misunderstand me (ah my big mouth..). But its so win9x at the moment.

Maybe set font, style, size, color as well?
Set font ubication (placement)
DUIhwnd height (they might be too tall for some smaller fonts, etc).

But I bet everyone here a beer that this lib will kick ass
:)
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

crap. someone found a glitch in the algorithm that calulates the positions of the directui windows on the main window. its no surprise really, i am not the expert on algorithms. as a chemical engineer a while back, i could never ever get algorithms right to model gas dynamics. ill work on it some more. thanks.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Post Reply