OOP/COM Programming with PB -- Taskbar

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

OOP/COM Programming with PB -- Taskbar

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Danilo.

Good Morning !!

Some people asked about using the CallCOM() command
for Object Oriented Programming (OOP).
Now here is a little (easy to understand) example
that hides the Application from the Windows taskbar.

Its only for demonstrating how OOP
works with PureBasic.

Code: Select all

;EXAMPLE UPDATE NOTE: As the CallCOM() function library cannot
;be located, and the topic is not specific to CallCOM(), the 
;example has been adapted to utilise PureBasic's built-in
;ITaskbarList interface, which provides the same functionality.

OpenWindow(0, 100, 100, 400, 200, "Window in Taskbar",
           #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 260, 20, 120, 30, "hide from taskbar")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          If Not coInit
            tb.ITaskbarList
            CoInitialize_(0)
            If CoCreateInstance_(?CLSID_TaskbarList, 0, 1,
                                 ?IID_ITaskbarList, @tb)
              MessageRequester("Object Creation Error:",
                               "Unable to initialise COM.")
            Else
              tb\HrInit()
              coInit = 1
            EndIf
          EndIf
          If coInit
            If show
              tb\AddTab(WindowID(0))
              SetGadgetText(0, "hide from taskbar")
              show = 0
            Else  
              tb\DeleteTab(WindowID(0))
              SetGadgetText(0, "show in taskbar")
              show = 1
            EndIf
          EndIf
      EndSelect
  EndSelect
Until appQuit = 1

If coInit
  tb\Release() 
EndIf
CoUninitialize_()
End

DataSection
  CLSID_TaskbarList:
    Data.i $56FDF344
    Data.w $FD6D, $11D0
    Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
  IID_ITaskbarList:
    Data.i $56fdf342
    Data.w $FD6D, $11D0
    Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
EndDataSection
Its easy...

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Thanks, Danilo! I didn't know how to create COM objects, this is a start .

Bye,

El_Choni
Post Reply