Outlook gadget Alpha - back from the dead

Developed or developing a new product in PureBasic? Tell the world about it.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Outlook gadget Alpha - back from the dead

Post by localmotion34 »

so after my 21 days in Hurricane Katrina areas, 6 weeks of my PHD qualifying exams, and 1 week at the Society for Neuroscience conference in Washington DC, I am back in full force with this Alpha release.

There was a similar gadget posted based on the eventconnection LIB, but a while back i coded a DirectUI Hwnd library that operates almost exactly on the principles of the Outlook gadget. So i ported the DUI Hwnd code over and created this gadget.

NOTE: in the code i did ALOT of copying and pasting, so the VARIABLE names i use still are named for the DUI Hwnd library. Ill have to do a search and replace later. this release is just to give a look and get suggestions of what the final release should look like.

The whole concept of this LIB is that it looks and acts like an outlook gadget, but the actual buttons of each outlook group are created with #pb_any, and the procedure to add a button to a group returns the actual PB numeric identifier. hence, you can add a button, and take the result and perform an action in the event loop EX:

button=AddOLButton(0,1,2,"text",0,0)

Repeat
Select WindowEvent()
Case #PB_Event_Gadget
Select EventGadgetID()
case button
DO WHATTEVER YOU WANT HERE
EndSelect
Case #PB_EventCloseWindow
Quit=1
EndSelect
Until Quit=1

so here is the code: suggestions are always welcome

Code: Select all

ProcedureDLL InitOutlook() 
  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
    type.l 
  EndStructure
  NewList OL.inf()
  Dim icon.l(100)
EndProcedure

ProcedureDLL HideOL(DUIpane,DuiHwnd,State);Hide Or Show And Individial DUIhwnd
  SelectElement(OL(),DUIpane)
  If State=0
    If OL()\State[DuiHwnd]=0
      SelectElement(OL(),DUIpane)
      parent=GetParent_(OL()\hwnd[DuiHwnd])
      SetWindowPos_(OL()\hwnd[DuiHwnd],0,0,0,OL()\width,OL()\height[DuiHwnd],#SWP_NOMOVE)
      OL()\State[DuiHwnd]=1
      PostMessage_(parent,#duidown,DuiHwnd,ListIndex(OL()))
    EndIf
  ElseIf State=1
    If OL()\State[DuiHwnd]=1
      SelectElement(OL(),DUIpane)
      parent=GetParent_(OL()\hwnd[DuiHwnd])
      SetWindowPos_(OL()\hwnd[DuiHwnd],0,0,0,OL()\width,20,#SWP_NOMOVE)
      OL()\State[DuiHwnd]=0
      PostMessage_(parent,#duiup,DuiHwnd,ListIndex(OL()))
    EndIf
  EndIf
EndProcedure

Procedure OLmoveproc(hwnd,msg,wParam,lParam)
  Select msg
    Case #duiup
      SelectElement(OL(),lParam)
      heighttomove=OL()\height[wParam]-20
      For a=wParam+1 To 9
        height=OL()\height[a]-20
        yval=OL()\yvalue[a]-heighttomove
        SetWindowPos_(OL()\hwnd[a],0,0,yval,0,0,#SWP_NOSIZE)
        OL()\yvalue[a]=yval
      Next
      ProcedureReturn 0
    Case #duidown
      SelectElement(OL(),lParam)
      heighttomove=OL()\height[wParam]-20
      For a=wParam+1 To 9
        height=OL()\height[a]
        yval=OL()\yvalue[a]+heighttomove
        SetWindowPos_(OL()\hwnd[a],0,0,yval,0,0,#SWP_NOSIZE)
        OL()\yvalue[a]=yval
      Next
      ProcedureReturn 0
    Case #WM_COMMAND
      parent=GetParent_(hwnd)
      ForEach OL()
        For a=0 To 9
          If OL()\hwnd[a]=hwnd
            currentdui=ListIndex(OL())
            scrollparent=GetParent_(OL()\hwnd[a])
            If OL()\State[a]=1
              SetWindowPos_(OL()\hwnd[a],0,0,0,OL()\width,22,#SWP_NOMOVE)
              OL()\State[a]=0
              PostMessage_(scrollparent,#duiup,a,ListIndex(OL()))
            ElseIf OL()\State[a]=0
              SetWindowPos_(OL()\hwnd[a],0,0,0,OL()\width,OL()\height[a],#SWP_NOMOVE)
              OL()\State[a]=1
              PostMessage_(scrollparent,#duidown,a,ListIndex(OL()))
            EndIf
            Break 2
          EndIf 
        Next
      Next
      ProcedureReturn 0
  EndSelect
  ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc2"),hwnd,msg,wParam,lParam)
  
EndProcedure

Procedure OLclickproc(hwnd,msg,wParam,lParam)
  Select msg
    Case #WM_COMMAND
      ForEach OL()
        For a=0 To 9
          If hwnd=OL()\hwnd[a]
            currentdui=ListIndex(OL())
            scrollparent=GetParent_(hwnd)
            If OL()\State[a]=1
              SetWindowPos_(OL()\hwnd[a],0,0,0,OL()\width,22,#SWP_NOMOVE)
              OL()\State[a]=0
              PostMessage_(scrollparent,#duiup,a,ListIndex(OL()))
            ElseIf OL()\State[a]=0
              SetWindowPos_(OL()\hwnd[a],0,0,0,OL()\width,OL()\height[a],#SWP_NOMOVE)
              OL()\State[a]=1
              PostMessage_(scrollparent,#duidown,a,ListIndex(OL()))
            EndIf
            Break
          EndIf
        Next
      Next
  EndSelect
  ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc3"),hwnd,msg,wParam,lParam)
EndProcedure

Procedure olbuttonproc(hwnd,msg,wParam,lParam)
  Select msg 
    Case #WM_LBUTTONDOWN
      parent=GetParent_(hwnd)
      ForEach OL()
        For a=0 To 9
          If parent=OL()\hwnd[a]
            currentdui=ListIndex(OL())
            scrollparent=GetParent_(OL()\hwnd[a])
            If OL()\State[a]=1
              SetWindowPos_(OL()\hwnd[a],0,0,0,OL()\width,20,#SWP_NOMOVE)
              OL()\State[a]=0
              PostMessage_(scrollparent,#duiup,a,ListIndex(OL()))
            ElseIf OL()\State[a]=0
              For b=0 To 9
                If OL()\State[b]=1
                  SetWindowPos_(OL()\hwnd[b],0,0,0,OL()\width,20,#SWP_NOMOVE)
                  OL()\State[b]=0
                  PostMessage_(scrollparent,#duiup,b,ListIndex(OL()))
                  Break 
                EndIf 
              Next
              SetWindowPos_(OL()\hwnd[a],0,0,0,OL()\width,OL()\height[a],#SWP_NOMOVE)
              PostMessage_(scrollparent,#duidown,a,ListIndex(OL()))
              OL()\State[a]=1
            EndIf
            Break
          EndIf
        Next
      Next
  EndSelect
  ProcedureReturn CallWindowProc_(GetProp_(hwnd,"OldProc1"),hwnd,msg,wParam,lParam)
EndProcedure

ProcedureDLL OutlookPane(number,x,y,panewidth,height,DUItype); Creates A Pane To House DUIhwnd's
  border=#PB_ScrollArea_Single
  AddElement(OL())
  SelectElement(OL(),number)
  OL()\gadgethght=height
  OL()\width=panewidth-3
  scroll=ScrollAreaGadget(#PB_Any,x,y,panewidth,height,panewidth-3,height-20,30,border )
  OL()\scrollgadget=scroll
  OL()\scrollheight=height-20
  child=GetWindow_(GadgetID(scroll),#GW_CHILD)
  OL()\parent=child
  SetProp_(child,"OldProc2",SetWindowLong_(child, #GWL_WNDPROC, @OLmoveproc()))
  ProcedureReturn scroll
EndProcedure

ProcedureDLL OutlookGroup(Outlookpane,Position,text.s); Add A DUIhwnd that Can Contain Links To Commands
  SelectElement(OL(),Outlookpane)
  OL()\duinum[Position]=Position
  OL()\height[Position]=80
  ;totalheight=60
  If Position=0
    OL()\yvalue[Position]=0
    height=80 
    OL()\State[Position]=1
  ElseIf Position<>0
    For a=0 To Position-1
      If OL()\State[a]=1
        totalheight+OL()\height[a]
      Else
        totalheight=totalheight+20;OL()\height[a]
      EndIf 
    Next
    OL()\yvalue[Position]=totalheight
    height=20
    OL()\State[Position]=0
  EndIf
  mainhandle=OpenWindow(#PB_Any,0,OL()\yvalue[Position],OL()\width,height,#PB_Window_Invisible,"")
  OL()\hwnd[Position]=WindowID(mainhandle)
  SetWindowLong_(OL()\hwnd[Position],#GWL_STYLE, #WS_CHILD|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  SetParent_(OL()\hwnd[Position],OL()\parent)
  hBrush = CreateSolidBrush_(GetSysColor_(#COLOR_APPWORKSPACE ) ) 
  SetClassLong_(OL()\hwnd[Position], #GCL_HBRBACKGROUND, hBrush) 
  ;SetClassLong_(scroll, #GCL_HBRBACKGROUND, hBrush)
  ;SetProp_(WindowID(mainhandle),"OldProc3",SetWindowLong_(WindowID(mainhandle), #GWL_WNDPROC, @OLclickproc()))
  CreateGadgetList(OL()\hwnd[Position])
  OL()\imagehwnd[Position]=ButtonGadget(#PB_Any,0,0,OL()\width,20,text)
  SetProp_(GadgetID(OL()\imagehwnd[Position]),"OldProc1",SetWindowLong_(GadgetID(OL()\imagehwnd[Position]), #GWL_WNDPROC, @olbuttonproc()))
  ShowWindow_(OL()\hwnd[Position],#SW_SHOW)
  SetWindowPos_(OL()\hwnd[Position],0,0,0,OL()\width,height,#SWP_NOMOVE)
  RedrawWindow_(OL()\hwnd[Position],0,0,#RDW_ALLCHILDREN   )
  UpdateWindow_(OL()\hwnd[Position])
  
EndProcedure

ProcedureDLL AddOLButton(DUIpane,DuiHwnd,Position,text.s,color.l,image.l); Add A Link To Execute A Command Or List An Item You Want To Display
  SelectElement(OL(),DUIpane)
  UseGadgetList(OL()\hwnd[DuiHwnd])
  If Position=0
    y=25
  Else
    y=(Position*45 +25)
  EndIf 
  newheight=(Position*45)+70
  oldheight=OL()\height[DuiHwnd]
  hyperlink=ButtonGadget(#PB_Any, 25, y,OL()\width/2,40,text)
  If Position =0
    OL()\height[DuiHwnd]=80
  ElseIf Position>0
    OL()\height[DuiHwnd]=newheight
    If OL()\State[DuiHwnd]=1
      SetWindowPos_(OL()\hwnd[DuiHwnd],0,0,0,OL()\width,OL()\height[DuiHwnd],#SWP_NOMOVE)
      For a=DuiHwnd+1 To 9
        SetWindowPos_(OL()\hwnd[a],0,5,OL()\yvalue[a]+(newheight-oldheight),0,0,#SWP_NOSIZE)
        OL()\yvalue[a]=OL()\yvalue[a]+(newheight-oldheight)
      Next
    Else
      
    EndIf 
      
    EndIf
    RedrawWindow_(OL()\hwnd[DuiHwnd],0,0,#RDW_ALLCHILDREN   )
    ShowWindow_(OL()\hwnd[DuiHwnd],#SW_SHOWNORMAL)
    UpdateWindow_(OL()\hwnd[DuiHwnd])
  ProcedureReturn hyperlink
EndProcedure

OpenWindow(0,0,0,470,460,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Outlook Example") And CreateGadgetList(WindowID(0))
InitOutlook()
pane=OutlookPane(0,10,10,100,420,#DUI_Classic)
OutlookGroup(0,0,"New Mail")
AddOLButton(0,0,0,"Export",0,0)
AddOLButton(0,0,1,"text",0,0)
AddOLButton(0,0,2,"text",0,0)
OutlookGroup(0,1,"Sent Mail")
AddOLButton(0,1,0,"text",0,0)
AddOLButton(0,1,1,"text",0,0)
AddOLButton(0,1,2,"text",0,0)
AddOLButton(0,1,3,"text",0,0)
OutlookGroup(0,2,"Trash")
OutlookGroup(0,3,"Another Group")
OutlookGroup(0,4,"Blah")
OutlookGroup(0,5,"Last Group")

Repeat
  Select WindowEvent()
    Case #PB_Event_Gadget
      Select EventGadgetID()
        
      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
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

#duidown not found
Can you include the constants ? I cna't try without them :)
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

#DUI_Classic= $FF08
#DUI_XPstyle=$FF09
#duiup=$FF06
#duidown=$FF07
#WM_MOUSEHOVER = $2A1
#WM_MOUSELEAVE = $2A3
#BS_FLAT=$8000
#TME_HOVER = 1
#TME_LEAVE = 2
#clnavy=$00800000

oops--sorry

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

Very Cool! Thanks.
Post Reply