microsoft windows DirectUIhwnd 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

microsoft windows DirectUIhwnd test

Post by localmotion34 »

Code updated for 5.20+

here is a little version of the DirectUIhwnd class that microsoft uses in the control panel of Windows XP. its not finished yet, but i thought id get some input on it. try it out...

Code: Select all

Structure inf
  duinum.i
  State.i
  mainhandle.i
  hwnd.i
  imagehwnd.i
  button.i
  buttonstate.i
  width.i
  height.i
  hyperlink.i[50]
EndStructure 

Procedure InitDUI()
  Global NewList dui.inf() 
  Global Dim icon(50)
EndProcedure

Procedure buttonproc(hwnd,msg,wParam,lParam)
  Select msg
    Case #WM_LBUTTONUP
      imgparent=GetParent_(hwnd)
      parent=GetParent_(imgparent)
      ForEach dui()
        If parent=dui()\hwnd
          currentdui=dui()\duinum 
          SelectElement(dui(),currentdui)
          If dui()\State=1
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
            dui()\State=0
          ElseIf dui()\State=0
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
            dui()\State=1
          EndIf 
          Break 
        EndIf 
      Next 
      
  EndSelect 
  ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc1"),hwnd,msg,wParam,lParam)
EndProcedure

Procedure DirectUIhwnd(number,x,y,width,height,text.s,icon,parentid)
  AddElement(dui())
  SelectElement(dui(),number)
  dui()\duinum=number 
  dui()\width=width
  dui()\height=height
  dui()\mainhandle=OpenWindow(#PB_Any,x,y,width,height,"", #PB_Window_BorderLess   |#PB_Window_Invisible)
  dui()\hwnd=WindowID(dui()\mainhandle)
  SetWindowLong_(WindowID(dui()\mainhandle),#GWL_STYLE, #WS_CHILD |#WS_BORDER|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  ;RedrawWindow_(dui()\hwnd,0,0,7)
  SetParent_(WindowID(dui()\mainhandle),parentid)
  icon(number)=CreateImage(number+200,width,20)
  StartDrawing(ImageOutput(number+200))
    DrawImage(icon(0),0,0)
    #clnavy=$00800000
    Box(0,0,width,20,#clnavy)
  StopDrawing()
  dui()\imagehwnd=ImageGadget(#PB_Any,0,0,width,20,0)
  SetGadgetState(dui()\imagehwnd,icon(number))
  dui()\button=ButtonGadget(#PB_Any,width-18,2,16,16,"^")
  style = GetWindowLong_(GadgetID(dui()\button), #GWL_STYLE) 
  toggleStyle=style|$1083
  SetWindowLong_(GadgetID(dui()\button), #GWL_STYLE, toggleStyle) 
  SetParent_(GadgetID(dui()\button),GadgetID(dui()\imagehwnd))
  SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_CHECKED,0)
  SetProp_(GadgetID(dui()\button),"OldProc1",SetWindowLong_(GadgetID(dui()\button), #GWL_WNDPROC, @buttonproc()))
  SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
  SetWindowPos_(dui()\hwnd,parentid,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
  RedrawWindow_(WindowID(dui()\mainhandle),0,0,#RDW_ALLCHILDREN   )
  ShowWindow_(WindowID(dui()\mainhandle),#SW_SHOW)
  UpdateWindow_(WindowID(dui()\mainhandle))
  SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
  dui()\State=1
EndProcedure 

Procedure addDUIlink(numberDUI,Position,text.s,color)
  SelectElement(dui(),numberDUI)
  UseGadgetList(WindowID(dui()\mainhandle))
  hyperlink=HyperLinkGadget(#PB_Any, 5, Position*20 +25,dui()\width,20,Space(10)+ text, color)
  RedrawWindow_(WindowID(dui()\mainhandle),0,0,#RDW_ALLCHILDREN   )
  ShowWindow_(WindowID(dui()\mainhandle),#SW_SHOWNORMAL)
  UpdateWindow_(WindowID(dui()\mainhandle))
  dui()\hyperlink[Position]=hyperlink
  ProcedureReturn hyperlink 
EndProcedure 

OpenWindow(0,0,0,270,160,"DirectUIhwnd",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
InitDUI()
DirectUIhwnd(0,10,10,100,100,"test",0,WindowID(0))
DirectUIhwnd(1,130,10,100,100,"test2",0,WindowID(0))
link=addDUIlink(0,0,"test",$FF04)
link2=addDUIlink(0,1,"test 2",$FF04)
Repeat
  Select WindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case link
          Debug "it works"
        Case 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
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

It does "something" even with Win2000... But I don't know what to expect...
Could you post a screenshot of the XP version, or at least explain the DirectUIhwnd class? :)
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Seems to work, but, if you click the mouse button down on the button thingy and drag it away from the button before releasing it, then the order gets mixed up. So when it is supposed to be pressed it is actually depressed. Hope I explaned that so you could understand it hehe :)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

hehe. OK OK. i am trying to EMULATE the directUIhwnd class in windows XP.

here:

[img]
http://www.tune-up.com/images/?cat=scre ... height=532
[/img]

the LEFT of the screenshot is the directUIhwnd. it had the box with a titlebar around it, and has items like a listviewgadget, but they are HYPERLINKS. it is basically a listbox of hyperlinks and when you click the button, the hyperlinks get hidden. im just trying to make some cool gadgets.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Yeah I know what you mean.
It would be really cool if we could have something like that in PB :)
So keep it up m8
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

here is the beta test before i go ahead and make a PB library for this. let me know what you think and if youd like to see any other features with this gadget.

Code: Select all

Structure inf
  duinum.l
  State.l
  mainhandle.l
  hwnd.l
  imagehwnd.l
  button.l
  buttonstate.l
  width.l
  height.l
  hyperlink.l[50]
  textgad.l
EndStructure 

Procedure InitDUI()
  NewList dui.inf() 
  Dim icon.l(50)
EndProcedure

Procedure buttonproc(hwnd,msg,wParam,lParam)
  Select msg
    Case #WM_CTLCOLORSTATIC
      #clnavy=$00800000
      blue = CreateSolidBrush_(#clnavy) 
      ForEach dui()
        If lParam=GadgetID(dui()\textgad)
          SetTextColor_(wParam,#White) ;Text colour
          SetBkcolor_(wParam, #clnavy) ;Background colour
        EndIf 
      Next 
      ProcedureReturn blue
    Case #WM_COMMAND
      parent=GetParent_(hwnd)
      ForEach dui()
        If parent=dui()\hwnd
          currentdui=dui()\duinum 
          SelectElement(dui(),currentdui)
          If dui()\State=1
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
            dui()\State=0
          ElseIf dui()\State=0
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
            dui()\State=1
          EndIf 
          Break 
        EndIf 
      Next 
    Case #WM_LBUTTONDBLCLK
      parent=GetParent_(hwnd)
      ForEach dui()
        If parent=dui()\hwnd
          currentdui=dui()\duinum 
          SelectElement(dui(),currentdui)
          If dui()\State=1
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
            SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_UNCHECKED,0)
            dui()\State=0
          ElseIf dui()\State=0
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
            SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_CHECKED,0)
            dui()\State=1
          EndIf 
          Break 
        EndIf 
      Next 
  EndSelect 
  ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc1"),hwnd,msg,wParam,lParam)
EndProcedure

Procedure DirectUIhwnd(number,x,y,width,height,text.s,icon,parentid)
  AddElement(dui())
  SelectElement(dui(),number)
  dui()\duinum=number 
  dui()\width=width
  dui()\height=height
  dui()\mainhandle=OpenWindow(#PB_Any,x,y,width,height,#PB_Window_BorderLess	|#PB_Window_Invisible,"")
  dui()\hwnd=WindowID(dui()\mainhandle)
  SetWindowLong_(WindowID(dui()\mainhandle),#GWL_STYLE, #WS_CHILD|#WS_BORDER|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  SetParent_(WindowID(dui()\mainhandle),parentid)
  icon(number)=CreateImage(number+200,width,20)
  StartDrawing(ImageOutput())
  DrawImage(icon(0),0,0)
  #clnavy=$00800000
  Box(0,0,width,20,#clnavy)
  StopDrawing()
  CreateGadgetList(WindowID(dui()\mainhandle))
  dui()\imagehwnd=ImageGadget(#PB_Any,0,0,width,20,0)
  SetGadgetState(dui()\imagehwnd,icon(number))
  dui()\button=ButtonGadget(#PB_Any,width-18,2,16,16,"^")
  style = GetWindowLong_(GadgetID(dui()\button), #GWL_STYLE) 
  toggleStyle=style|$1083
  SetWindowLong_(GadgetID(dui()\button), #GWL_STYLE, toggleStyle) 
  SetParent_(GadgetID(dui()\button),GadgetID(dui()\imagehwnd))
  dui()\textgad=TextGadget(#PB_Any,0,2,width-26,20,text,#PB_Text_Center)
  SetParent_(GadgetID(dui()\textgad),GadgetID(dui()\imagehwnd))
  SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_CHECKED,0)
  SetProp_(GadgetID(dui()\imagehwnd),"OldProc1",SetWindowLong_(GadgetID(dui()\imagehwnd), #GWL_WNDPROC, @buttonproc()))
  SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
  SetWindowPos_(dui()\hwnd,parentid,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
  RedrawWindow_(WindowID(dui()\mainhandle),0,0,#RDW_ALLCHILDREN	)
  ShowWindow_(WindowID(dui()\mainhandle),#SW_SHOW)
  UpdateWindow_(WindowID(dui()\mainhandle))
  SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
  dui()\State=1
EndProcedure 

Procedure addDUIlink(numberDUI,Position,text.s,color.l)
  SelectElement(dui(),numberDUI)
    UseGadgetList(WindowID(dui()\mainhandle))
    hyperlink=HyperLinkGadget(#PB_Any, 5, Position*20 +25,dui()\width,20,text, color)
    RedrawWindow_(WindowID(dui()\mainhandle),0,0,#RDW_ALLCHILDREN	)
    ShowWindow_(WindowID(dui()\mainhandle),#SW_SHOWNORMAL)
    UpdateWindow_(WindowID(dui()\mainhandle))
    dui()\hyperlink[Position]=hyperlink
    ProcedureReturn hyperlink 
EndProcedure 

Procedure HideDUI(duinumber,State)
  If State=0
    If dui()\State=0
      SelectElement(dui(),duinumber)
      SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
      SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_CHECKED,0)
      dui()\State=1
  EndIf 
ElseIf State=1
  If dui()\State=1
    SelectElement(dui(),duinumber)
    SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
    SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_UNCHECKED,0)
    dui()\State=0
  EndIf
EndIf 
  ProcedureReturn 0
EndProcedure

  OpenWindow(0,0,0,270,160,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"DirectUIhwnd") And CreateGadgetList(WindowID(0))
  InitDUI()
  DirectUIhwnd(0,10,10,100,100,"Commands",0,WindowID(0))
  DirectUIhwnd(1,130,10,100,100,"test2",0,WindowID(0))
  link=addDUIlink(0,0,"Message Box",$FF04)
  link2=addDUIlink(0,1,"Hide Other DUI",$FF04)
  link3=addDUIlink(0,2,"Show Other DUI",$FF04)
  Repeat
    Select WindowEvent()
      Case #PB_Event_Gadget
        Select EventGadgetID()
          Case link
            MessageRequester("hi","It really works",#PB_MessageRequester_Ok)
          Case link2
            HideDUI(1,1)
          Case link3
            HideDUI(1,0)
        EndSelect
      Case #PB_EventCloseWindow
        Quit=1
    EndSelect
  Until Quit=1

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

I've an almost clean PB installation.
The debugger reports an error in line 26:
#Gadget object not initialized

Do I need some extra userlibrary?
(the first example worked well)
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

oops. forgot the IsGadget() function to test to see if the gadget exists before processing a message. try this:

Code: Select all

Structure inf
  duinum.l
  State.l
  mainhandle.l
  hwnd.l
  imagehwnd.l
  button.l
  buttonstate.l
  width.l
  height.l
  hyperlink.l[50]
  textgad.l
EndStructure

Procedure InitDUI()
  NewList dui.inf()
  Dim icon.l(50)
EndProcedure

Procedure buttonproc(hwnd,msg,wParam,lParam)
  Select msg
    Case #WM_CTLCOLORSTATIC
      #clnavy=$00800000
      blue = CreateSolidBrush_(#clnavy)
      ForEach dui()
        If IsGadget(dui()\textgad) And lParam=GadgetID(dui()\textgad)
          SetTextColor_(wParam,#White) ;Text colour
          SetBkcolor_(wParam, #clnavy) ;Background colour
        EndIf
      Next
      ProcedureReturn blue
    Case #WM_COMMAND
      parent=GetParent_(hwnd)
      ForEach dui()
        If parent=dui()\hwnd
          currentdui=dui()\duinum
          SelectElement(dui(),currentdui)
          If dui()\State=1
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
            dui()\State=0
          ElseIf dui()\State=0
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
            dui()\State=1
          EndIf
          Break
        EndIf
      Next
    Case #WM_LBUTTONDBLCLK
      parent=GetParent_(hwnd)
      ForEach dui()
        If parent=dui()\hwnd
          currentdui=dui()\duinum
          SelectElement(dui(),currentdui)
          If dui()\State=1
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
            SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_UNCHECKED,0)
            dui()\State=0
          ElseIf dui()\State=0
            SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
            SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_CHECKED,0)
            dui()\State=1
          EndIf
          Break
        EndIf
      Next
  EndSelect
  ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc1"),hwnd,msg,wParam,lParam)
EndProcedure

Procedure DirectUIhwnd(number,x,y,width,height,text.s,icon,parentid)
  AddElement(dui())
  SelectElement(dui(),number)
  dui()\duinum=number
  dui()\width=width
  dui()\height=height
  dui()\mainhandle=OpenWindow(#PB_Any,x,y,width,height,#PB_Window_BorderLess   |#PB_Window_Invisible,"")
  dui()\hwnd=WindowID(dui()\mainhandle)
  SetWindowLong_(WindowID(dui()\mainhandle),#GWL_STYLE, #WS_CHILD|#WS_BORDER|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  SetParent_(WindowID(dui()\mainhandle),parentid)
  icon(number)=CreateImage(number+200,width,20)
  StartDrawing(ImageOutput())
  DrawImage(icon(0),0,0)
  #clnavy=$00800000
  Box(0,0,width,20,#clnavy)
  StopDrawing()
  CreateGadgetList(WindowID(dui()\mainhandle))
  dui()\imagehwnd=ImageGadget(#PB_Any,0,0,width,20,0)
  SetGadgetState(dui()\imagehwnd,icon(number))
  dui()\button=ButtonGadget(#PB_Any,width-18,2,16,16,"^")
  style = GetWindowLong_(GadgetID(dui()\button), #GWL_STYLE)
  toggleStyle=style|$1083
  SetWindowLong_(GadgetID(dui()\button), #GWL_STYLE, toggleStyle)
  SetParent_(GadgetID(dui()\button),GadgetID(dui()\imagehwnd))
  dui()\textgad=TextGadget(#PB_Any,0,2,width-26,20,text,#PB_Text_Center)
  SetParent_(GadgetID(dui()\textgad),GadgetID(dui()\imagehwnd))
  SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_CHECKED,0)
  SetProp_(GadgetID(dui()\imagehwnd),"OldProc1",SetWindowLong_(GadgetID(dui()\imagehwnd), #GWL_WNDPROC, @buttonproc()))
  SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
  SetWindowPos_(dui()\hwnd,parentid,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
  RedrawWindow_(WindowID(dui()\mainhandle),0,0,#RDW_ALLCHILDREN   )
  ShowWindow_(WindowID(dui()\mainhandle),#SW_SHOW)
  UpdateWindow_(WindowID(dui()\mainhandle))
  SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
  dui()\State=1
EndProcedure

Procedure addDUIlink(numberDUI,Position,text.s,color.l)
  SelectElement(dui(),numberDUI)
  UseGadgetList(WindowID(dui()\mainhandle))
  hyperlink=HyperLinkGadget(#PB_Any, 5, Position*20 +25,dui()\width,20,text, color)
  RedrawWindow_(WindowID(dui()\mainhandle),0,0,#RDW_ALLCHILDREN   )
  ShowWindow_(WindowID(dui()\mainhandle),#SW_SHOWNORMAL)
  UpdateWindow_(WindowID(dui()\mainhandle))
  dui()\hyperlink[Position]=hyperlink
  ProcedureReturn hyperlink
EndProcedure

Procedure HideDUI(duinumber,State)
  If State=0
    If dui()\State=0
      SelectElement(dui(),duinumber)
      SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,dui()\height,#SWP_NOMOVE)
      SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_CHECKED,0)
      dui()\State=1
    EndIf
  ElseIf State=1
    If dui()\State=1
      SelectElement(dui(),duinumber)
      SetWindowPos_(dui()\hwnd,0,0,0,dui()\width,20,#SWP_NOMOVE)
      SendMessage_(GadgetID(dui()\button),#BM_SETCHECK,#BST_UNCHECKED,0)
      dui()\State=0
    EndIf
  EndIf
  ProcedureReturn 0
EndProcedure

OpenWindow(0,0,0,270,160,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"DirectUIhwnd") And CreateGadgetList(WindowID(0))
InitDUI()
DirectUIhwnd(0,10,10,100,100,"Commands",0,WindowID(0))
DirectUIhwnd(1,130,10,100,100,"test2",0,WindowID(0))
link=addDUIlink(0,0,"Message Box",$FF04)
link2=addDUIlink(0,1,"Hide Other DUI",$FF04)
link3=addDUIlink(0,2,"Show Other DUI",$FF04)
Repeat
  Select WindowEvent()
    Case #PB_Event_Gadget
      Select EventGadgetID()
        Case link
          MessageRequester("hi","It really works",#PB_MessageRequester_Ok)
        Case link2
          HideDUI(1,1)
        Case link3
          HideDUI(1,0)
      EndSelect
    Case #PB_EventCloseWindow
      Quit=1
  EndSelect
Until Quit=1 

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Nice work :)
Now I expect the sliding effect when two panel are in the same "column" as can seen in XP explorer ;)
Post Reply