Outlook Gadget

Share your advanced PureBasic knowledge/code with the community.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Outlook Gadget

Post by fsw »

Here my second approach to make a special Gadget simple.
(here the first one)

Don't know if this Gadget is a part of a WinOS DLL or Outlook itself.
What I know is that PureBasic doesn't have it.

Code: Select all

; OutlookGadget For PureBasic 
; (c) 2003 - Franco
; Uses my EventConnection Library :)
;
; works with PureBasic v3.7
;
; USAGE:
;
; OutlookGadget(id,x,y,w,h,max_groups) 
; AddOutlookGadgetGroup(id,position,String$) - don't mix the positions! 
; AddOutlookGadgetItem(id,position,image$,parent_group) - don't mix the positions! 
; ActivateOutlookGadgetGroup(group_position)
;
;
; Use max_groups in OutlookGadget as it should be used!
; If max_groups is < the actual number of groups = not all groups will be shown
; If max_groups is > the actual number of groups = ActivateOutlookGadgetGroup will crash
;
; Don't mix the positions with AddOutlookGadgetGroup and AddOutlookGadgetItem!
; Start always with 1 and than 2,3,4... and so on.
; You can't use -1 (as position value) for adding Groups or Items!
;
; FOR NOW YOU CAN'T RESIZE THE OUTLOOKGADGET 
;
;- Start Main

#MainWindow = 1

Outlook.l   = OnEvent(?EventType_LeftClick)

OutlookButton1.l = OnEvent(?Activate1)
ScrollArea1Button1 = OnEvent(?EventType_LeftClick)
ScrollArea1Button2 = OnEvent(?EventType_LeftClick)
ScrollArea1Button3 = OnEvent(?EventType_LeftClick)
ScrollArea1Button4 = OnEvent(?EventType_LeftClick)

OutlookButton2.l = OnEvent(?Activate2)
ScrollArea2Button1 = OnEvent(?EventType_LeftClick)
ScrollArea2Button2 = OnEvent(?EventType_LeftClick)
ScrollArea2Button3 = OnEvent(?EventType_LeftClick)
ScrollArea2Button4 = OnEvent(?EventType_LeftClick)

OutlookButton3.l = OnEvent(?Activate3)
ScrollArea3Button1 = OnEvent(?EventType_LeftClick)
ScrollArea3Button2 = OnEvent(?EventType_LeftClick)
ScrollArea3Button3 = OnEvent(?EventType_LeftClick)
ScrollArea3Button4 = OnEvent(?EventType_LeftClick)

OutlookButton4.l = OnEvent(?Activate4)
ScrollArea4Button1 = OnEvent(?EventType_LeftClick)
ScrollArea4Button2 = OnEvent(?EventType_LeftClick)
ScrollArea4Button3 = OnEvent(?EventType_LeftClick)
ScrollArea4Button4 = OnEvent(?EventType_LeftClick)

Procedure OutlookGadget(id,x,y,w,h,max)
  If max < 1 : ProcedureReturn 0 : EndIf
  
  Structure Gadget
    x.l  ;this is used for the main gadget
    StructureUnion 
      y.l  ;this is used for the main gadget
      uy.l ;this is used for the upper y of the groups
    EndStructureUnion 
    StructureUnion 
      w.l  ;this is used for the main gadget
      ly.l ;this is used for the lower y of the groups
    EndStructureUnion
    StructureUnion 
      h.l  ;this is used for the main gadget
      idg.l ;this is used for the id of the groups
    EndStructureUnion
    StructureUnion 
      m.l  ;this is used for the main gadget
      ids.l ;this is used for the id of the scrollarea
    EndStructureUnion
  EndStructure
  
  Dim Outlook.Gadget(max)
  ; ZERO is always the main OutlookGadget!
  ; >=1 is always used for OutlookGadgetGroups!
  Outlook(0)\x = x
  Outlook(0)\y = y
  If w < 90 : w = 90 : EndIf
  Outlook(0)\w = w
  If h < max * 25 + 75 : h = max * 25 + 75 : EndIf
  Outlook(0)\h = h
  Outlook(0)\m = max ; max positions
  
  hGadget = ContainerGadget(id,Outlook(0)\x,Outlook(0)\y,Outlook(0)\w,Outlook(0)\h,#PB_Container_Single)
  hBrush = CreateSolidBrush_(GetSysColor_(#COLOR_APPWORKSPACE ) ) 
  SetClassLong_(hGadget, #GCL_HBRBACKGROUND, hBrush) 
  ProcedureReturn hGadget
EndProcedure

Procedure AddOutlookGadgetGroup(id,pos,String$)
  If pos > Outlook(0)\m : ProcedureReturn 0 : EndIf
  x=0
  
  If pos = 1 : y=0 : EndIf
  Outlook(pos)\uy = y
  Outlook(pos)\ly = y
  
  ;calculate upper y for pos > 1
  If pos > 1 : y=pos*25+0-25 : EndIf
  Outlook(pos)\uy = y ;this is used to store the upper y of the button so we can move it...
  
  ;calculate lower y for pos > 1
  If pos > 1 : y=Outlook(0)\h - (((Outlook(0)\m-pos+1)*25)+1) : EndIf
  Outlook(pos)\ly = y ;this is not used for width info, but to store the lower y of the button so we can move it...
  
  w = Outlook(0)\w - 1
  
  ButtonGadget(id,x,y,w,25,String$)
  Outlook(pos)\idg = id ;this is not used for height info, but to store the id of the button so we can move it...

  y=pos*25+2
  ScrollArea.l = NoEvent()

; different values are possible...  
  Scroll.l = ScrollAreaGadget(ScrollArea, 6, y, Outlook(0)\w-12, Outlook(0)\h - ((Outlook(0)\m+1)*25)+15, Outlook(0)\w-32, Outlook(0)\h - ((Outlook(0)\m+1)*25)+15, 42,#PB_ScrollArea_BorderLess)

  Outlook(pos)\ids = ScrollArea ;this is not used for max info, but to store the id of the scrollarea so we can move it...
  HideGadget(ScrollArea,1)

  ;colorize all this stuff...
  Area.l = GetWindow_(Scroll, #GW_CHILD)
  hBrush = CreateSolidBrush_(GetSysColor_(#COLOR_APPWORKSPACE ) ) 
  SetClassLong_(Area, #GCL_HBRBACKGROUND, hBrush) 
  SetClassLong_(Scroll, #GCL_HBRBACKGROUND, hBrush) 

  ProcedureReturn ScrollArea
EndProcedure

Procedure AddOutlookGadgetItem(id,pos,image$,parent)
  If pos = 1 : y=10 : EndIf
  If pos > 1 : y=pos*52-42 : EndIf
  x=((Outlook(0)\w)/2-36)
  ButtonImageGadget(id,x,y,42,42,LoadImage(NoEvent(),image$))   ; Y is 2 = first one doesn't move
  scroll.l = GetWindow_(GadgetID(parent), #GW_CHILD)
  y=pos*52+10
  MoveWindow_(scroll, 0, 0, Outlook(0)\w-32, y, #TRUE)

  ;have to change the parent somehow, otherwise the scrollarea is not repaint...
  ResizeGadget(parent, -1, -1, -1, Outlook(0)\h - (Outlook(0)\m*25)+pos)
  ;now I bring the parent back to the 'normal' size...
  ResizeGadget(parent, -1, -1, -1, Outlook(0)\h - ((Outlook(0)\m+1)*25) +15)
EndProcedure


Procedure ActivateOutlookGadgetGroup(pos)
  
  ;move the buttons...
  For i.l = 1 To Outlook(0)\m
    If i < pos
      MoveWindow_(GadgetID(Outlook(i)\idg), 0,Outlook(i)\uy,Outlook(0)\w-1,25,#TRUE) 
    Else
      MoveWindow_(GadgetID(Outlook(i)\idg), 0,Outlook(i)\ly,Outlook(0)\w-1,25,#TRUE) 
    EndIf
  Next
  MoveWindow_(GadgetID(Outlook(pos)\idg), 0,Outlook(pos)\uy,Outlook(0)\w-1,25,#TRUE) 
  
  ;hide the scrollareas...
  For i.l = 1 To Outlook(0)\m
    HideGadget(Outlook(i)\ids, 1) 
  Next
  HideGadget(Outlook(pos)\ids, 0)
  
EndProcedure

;- start example

If OpenWindow(#MainWindow,100,200,320,320,#PB_Window_SystemMenu | #PB_Window_SizeGadget,"Test") = 0 : End : EndIf

CreateGadgetList(WindowID(1))

If OutlookGadget(Outlook,50,10,10,250,4)
  ScrollArea1 = AddOutlookGadgetGroup(OutlookButton1,1,"Button 1")
  If ScrollArea1
    AddOutlookGadgetItem(ScrollArea1Button1,1,"GeeBee2.bmp",ScrollArea1)
    AddOutlookGadgetItem(ScrollArea1Button2,2,"GeeBee2.bmp",ScrollArea1)
    AddOutlookGadgetItem(ScrollArea1Button3,3,"GeeBee2.bmp",ScrollArea1)
    AddOutlookGadgetItem(ScrollArea1Button4,4,"GeeBee2.bmp",ScrollArea1)
    CloseGadgetList() ; this closes the Gadgetlist of ScrollArea1
  EndIf

  ScrollArea2 = AddOutlookGadgetGroup(OutlookButton2,2,"Button 2")
  If ScrollArea2
    AddOutlookGadgetItem(ScrollArea2Button1,1,"GeeBee2.bmp",ScrollArea2)
    AddOutlookGadgetItem(ScrollArea2Button2,2,"GeeBee2.bmp",ScrollArea2)
    AddOutlookGadgetItem(ScrollArea2Button3,3,"GeeBee2.bmp",ScrollArea2)
    AddOutlookGadgetItem(ScrollArea2Button4,4,"GeeBee2.bmp",ScrollArea2)
    CloseGadgetList() ; this closes the Gadgetlist of ScrollArea2
  EndIf

  ScrollArea3 = AddOutlookGadgetGroup(OutlookButton3,3,"Button 3")
  If ScrollArea3
    AddOutlookGadgetItem(ScrollArea3Button1,1,"GeeBee2.bmp",ScrollArea3)
    AddOutlookGadgetItem(ScrollArea3Button2,2,"GeeBee2.bmp",ScrollArea3)
    AddOutlookGadgetItem(ScrollArea3Button3,3,"GeeBee2.bmp",ScrollArea3)
    AddOutlookGadgetItem(ScrollArea3Button4,4,"GeeBee2.bmp",ScrollArea3)
    CloseGadgetList() ; this closes the Gadgetlist of ScrollArea3
  EndIf

  ScrollArea4 = AddOutlookGadgetGroup(OutlookButton4,4,"Button 4")
  If ScrollArea4
    AddOutlookGadgetItem(ScrollArea4Button1,1,"GeeBee2.bmp",ScrollArea4)
    AddOutlookGadgetItem(ScrollArea4Button2,2,"GeeBee2.bmp",ScrollArea4)
    AddOutlookGadgetItem(ScrollArea4Button3,3,"GeeBee2.bmp",ScrollArea4)
    AddOutlookGadgetItem(ScrollArea4Button4,4,"GeeBee2.bmp",ScrollArea4)
    CloseGadgetList() ; this closes the Gadgetlist of ScrollArea4
  EndIf

  CloseGadgetList() ; this closes the Gadgetlist of the OutlookGadget
  ActivateOutlookGadgetGroup(1)
EndIf


Repeat
  Event.l = WaitWindowEvent()

  Select Event

    Case #PB_Event_Gadget
      CallEventFunction(EventGadgetID())
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow And EventWindowID() = #MainWindow

End

;- User Functions
Activate1:
  ActivateOutlookGadgetGroup(1)

Return

Activate2:
  ActivateOutlookGadgetGroup(2)
 
Return

Activate3:
  ActivateOutlookGadgetGroup(3)

Return

Activate4:
  ActivateOutlookGadgetGroup(4)
Return


EventType_LeftClick:
  Debug "#PB_EventType_LeftClick"
;  MessageRequester("Test PB_EventType_LeftClick", "Gadget #: " + Str(EventGadgetID()),0)
Return
This code should look good on Win2k and WinXP (didn't test it on Win9x).

Have fun with it and use it accordingly.

Forgot to mention: it uses my EventConnection library (you can change this though...).

I am to provide the public with beneficial shocks.
Alfred Hitshock
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

it uses my EventConnection library
Where can i get this from? :?
--Kale

Image
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Kale wrote:
it uses my EventConnection library
Where can i get this from? :?
here was the announcment:
viewtopic.php?t=6969

here is the direct link:
http://fsw.home.comcast.net/FSW_EventConnection.zip

or it's also in Andre's CodeArea (User Libs):
http://purearea.net

BTW:
I'm also working on a new version of this lib.
Now I can use normal-click and double-click on the same gadget at the same time.
Also right-click on treeview etc. is no problem :wink:

I am to provide the public with beneficial shocks.
Alfred Hitshock
Leo
User
User
Posts: 21
Joined: Sat Aug 02, 2003 8:48 pm
Location: Netherlands, Wijk bij Duurstede

Post by Leo »

With some simple coding an OutLookBar can be created in PureBasic. Here is an example. To run it replace the icons with your own 32*32 icons and replace the path of the calc.exe with the one on your computer.

Code: Select all

  strCompleteFilename.s="c:\windows\calc.exe" 
  
  lngRetValue = ExtractIcon_(0, strCompleteFilename, 0) 
  
  If lngRetValue 
    CreateImage(5,32,32) 
    StartDrawing(ImageOutput()) 
    Box(0,0,32,32,GetSysColor_(#COLOR_WINDOW)) 
    DrawImage(lngRetValue,0,0) 
    StopDrawing() 
  EndIf 
  
  
  Procedure ResizeProc(A.l)
    d=0
    For i=2 To 4
      HideGadget(i,1)
      If i-A=1
        d=200
      EndIf
      ResizeGadget(i,-1,20*i-10+d,-1,-1)
      HideGadget(i,0)
    Next
    HideGadget(5,1)
    ResizeGadget(5,-1,20*(A+1)-10,-1,-1)
    HideGadget(5,0)
    ClearGadgetItemList(5)
;    ChangeListIconGadgetDisplay(5, 0) 
    Select A
      Case 1
          AddGadgetItem(5,-1,"Picture 1",UseImage(0)) 
          AddGadgetItem(5,-1,"Picture 2",UseImage(1)) 
          AddGadgetItem(5,-1,"Picture 3",UseImage(2)) 
          AddGadgetItem(5,-1,"Picture 4",UseImage(3)) 
          AddGadgetItem(5,-1,"Picture 5",UseImage(1)) 
          AddGadgetItem(5,-1,"Picture 6",UseImage(2)) 
          AddGadgetItem(5,-1,"Picture 7",UseImage(5)) 
      Case 2
          AddGadgetItem(5,-1,"Picture 1",UseImage(1)) 
          AddGadgetItem(5,-1,"Picture 2",UseImage(1)) 
          AddGadgetItem(5,-1,"Picture 3",UseImage(1)) 
          AddGadgetItem(5,-1,"Picture 4",UseImage(0)) 
          AddGadgetItem(5,-1,"Picture 5",UseImage(2)) 
          AddGadgetItem(5,-1,"Picture 6",UseImage(3)) 
          AddGadgetItem(5,-1,"Picture 7",UseImage(1)) 
      Case 3
          AddGadgetItem(5,-1,"Picture 1",UseImage(2)) 
          AddGadgetItem(5,-1,"Picture 2",UseImage(1)) 
          AddGadgetItem(5,-1,"Picture 3",UseImage(0)) 
          AddGadgetItem(5,-1,"Picture 4",UseImage(2)) 
          AddGadgetItem(5,-1,"Picture 5",UseImage(2)) 
          AddGadgetItem(5,-1,"Picture 6",UseImage(3)) 
          AddGadgetItem(5,-1,"Picture 7",UseImage(2)) 
      Case 4
         AddGadgetItem(5,-1,"Picture 1",UseImage(3)) 
          AddGadgetItem(5,-1,"Picture 2",UseImage(0)) 
          AddGadgetItem(5,-1,"Picture 3",UseImage(1)) 
          AddGadgetItem(5,-1,"Picture 4",UseImage(2)) 
          AddGadgetItem(5,-1,"Picture 5",UseImage(3)) 
          AddGadgetItem(5,-1,"Picture 6",UseImage(3)) 
          AddGadgetItem(5,-1,"Picture 7",UseImage(3)) 
      Default
    EndSelect
  EndProcedure  
  
  If OpenWindow(0,0,0,430,300,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Outlook Bar Control") And CreateGadgetList(WindowID(0)) 
    ButtonGadget(1, 10, 10, 100, 20, "Area 1")
    ButtonGadget(2, 10, 230, 100, 20, "Area 2")
    ButtonGadget(3, 10, 250, 100, 20, "Area 3")
    ButtonGadget(4, 10, 270, 100, 20, "Area 4")
    ListIconGadget(5,10,30,100,200, "",200)
    ListViewGadget(6,120,10,300,280)
    ChangeListIconGadgetDisplay(5, 0) 
    LoadImage(0,"windowcat.ico")
    LoadImage(1,"winterwindow.ico")
    LoadImage(2,"hallwnwindow.ico")
    LoadImage(3,"xmaswindow.ico")
    Area=1
    ResizeProc(1)
    Repeat
      eid=WaitWindowEvent() 
      ;         Debug eid
      Select eid 
        Case #PB_Event_Gadget
          Select EventGadgetID()
            Case 1
              Area=1
              ResizeProc(1)
            Case 2
              Area=2
              ResizeProc(2)
            Case 3
              Area=3
              ResizeProc(3)
            Case 4
              Area=4
              ResizeProc(4)
            Case 5
              If GetGadgetState(5)>-1
                AddGadgetItem(6,-1,"Area "+Str(Area)+" Picture "+Str(GetGadgetState(5)+1))
                If Area=1 And GetGadgetState(5)=6
                  RunProgram("c:\windows\calc.exe")
                EndIf  
              EndIf  
          EndSelect    
      EndSelect
      
    Until eid=#PB_Event_CloseWindow 
  EndIf 
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Hi Leo,

just stumbled across your contribution above and tested it with 3.93. It works like advertised on NT-4.0 through XP. I didn't test it on Win 9x/ME nor am I going to, but a Linux test is scheduled for the coming week.
For Linux, it would be nice to get rid of ExtractIcon_ and GetSysColor_, but I expect that this won't be too difficult as they are used for demo purposes only.

I think it should be included in GUI editors like PureVsionXP and the like... hint, hint... Paul, are you listening? :D

Very nice, thank you for sharing it! Just what the doctor ordered!
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

dell_jockey wrote:I didn't test it on Win 9x/ME nor am I going to
I did and it works fine on Win98SE/ME
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Although.. they need some nifty animation to be like the newer real outlook gadgets :p

By the way has anyone got the officexp style of buttons and shadows working in PB ?
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

dagcrack wrote:Although.. they need some nifty animation to be like the newer real outlook gadgets :p

By the way has anyone got the officexp style of buttons and shadows working in PB ?
These animations are information overload anyway... Of course it's only my personal opinion, but I feel that user interfaces these days are too colourful, too overloaded, too much distracting from the core application.
I'm perfectly happy with Leo's contribution... Again a personal opinion here, but I feel Leo's gadget should be added to PB as a standard.
Last edited by dell_jockey on Mon Mar 28, 2005 2:20 pm, edited 1 time in total.
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 »

One thing is overloading and other is polishing, smoothing!.
Maybe a programmer feels excellent by using a logo made in MS Paint, we artists dont!.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Hi Dagcrack,

polished and smooth artwork, fine, I agree wholeheartedly!
I was merely referring to excessive use of colour and/or colour combinations and stuffing too many objects in too little space.
I'd rather have a minimal GUI built up with very high quality (polished, smooth, whatever) monochrome artwork, and use additional colour(s) only to give users hints as to what part of the application is active, what got selected, where the cursor currently is, etc. Use colour only to convey information, not just to provide eye candy. That's how I intend to set up a GUI for the app I'm working on right now.
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 »

Oh but with polished, etc. I meant to add some nifty animation to the gadget, even if it requires a lot more cpu processing than needed (of course it does) but hey depends on your tastes and the usage you'll give to the gadget! :P

Im against skinned applications.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Im against skinned applications.

so am I... Common ground after all ;)
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply