March 28, 2024, 12:35:38 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Taskbar Thumbnail Toolbar

Started by jalih, November 21, 2017, 12:16:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jalih

November 21, 2017, 12:16:19 PM Last Edit: November 21, 2017, 12:21:10 PM by jalih
Here is how to use Taskbar Thumbnail Toolbar on IWB.

To test the demo program, point the mouse cursor over the program icon on toolbar and there should be two buttons visible at the bottom of the preview thumbnail. These buttons let you control playback of the .mid file.

Get the source with needed support files from here


$INCLUDE "windowssdk.inc"
$INCLUDE "Shlobj.inc"


enum THUMBBUTTONMASK
  THB_BITMAP   = 0x00000001
  THB_ICON     = 0x00000002
  THB_TOOLTIP  = 0x00000004
  THB_FLAGS    = 0x00000008
endenum

enum THUMBBUTTONFLAGS
  THBF_ENABLED         = 0x00000000
  THBF_DISABLED        = 0x00000001
  THBF_DISMISSONCLICK  = 0x00000002
  THBF_NOBACKGROUND    = 0x00000004
  THBF_HIDDEN          = 0x00000008
  THBF_NONINTERACTIVE  = 0x00000010
endenum

type THUMBBUTTON
  THUMBBUTTONMASK  dwMask
  UINT             iId
  UINT             iBitmap
  HICON            hIcon
  iwstring         szTip[260]
  THUMBBUTTONFLAGS dwFlags
endtype


const TBPF_NOPROGRESS        = 0
const TBPF_INDETERMINATE     = 1
const TBPF_NORMAL            = 2
const TBPF_ERROR             = 4
const TBPF_PAUSED            = 8


GUID CLSID_TaskbarList
GUID IID_ITaskbarList3

DEFINE_GUID(CLSID_TaskbarList,0x56FDF344,0xFD6D,0x11D0,0x95,0x8A,0x00,0x60,0x97,0xC9,0xA0,0x90)
DEFINE_GUID(IID_ITaskbarList3,0xEA1AFB91,0x9E28,0x4B86,0x90,0xE9,0x9E,0x9F,0x8A,0x5E,0xEF,0xAF)

def pTaskBar as ITaskbarList3

HICON hPlay_icon = ExtractIconA(0,"shell32.dll",137)
HICON hStop_icon = ExtractIconA(0,"shell32.dll",109)

THUMBBUTTON buttons[2]
'play button
buttons[0].dwMask = THB_ICON | THB_TOOLTIP | THB_FLAGS
buttons[0].iId = 1
buttons[0].iBitmap = 0
buttons[0].hIcon = hPlay_icon
buttons[0].szTip = L"Play"
buttons[0].dwFlags = THBF_ENABLED
' stop button
buttons[1].dwMask = THB_ICON | THB_TOOLTIP | THB_FLAGS
buttons[1].iId = 2
buttons[1].iBitmap = 0
buttons[1].hIcon = hStop_icon
buttons[1].szTip = L"Stop"
buttons[1].dwFlags = THBF_ENABLED

uint WM_TASKBARBUTTONCREATED = RegisterWindowMessage("TaskbarButtonCreated")

string cmd
HICON myicon = LOADIMAGE(GETSTARTPATH + "\heart.ico", @IMGICON)


DEF w as window
OPENWINDOW w,0,0,320,120,@MINBOX,NULL,"Simple Window",&whandler
centerwindow w
seticon w, myicon
move w, 10, 10: PRINT w,"Turn up the volume."
move w, 10, 40: PRINT w,"Test the taskbar thumbnail toolbar."
WAITUNTIL w = 0
END


SUB whandler(),INT
static BOOL TaskBarButtonCreated = FALSE

select @MESSAGE
case WM_TASKBARBUTTONCREATED
TaskBarButtonCreated = TRUE
CoInitialize(NULL)
HRESULT result = CoCreateInstance(CLSID_TaskbarList,0, 1, IID_ITaskbarList3, &pTaskBar)
if result = S_OK
pTaskBar->HrInit()
pTaskBar->ThumbBarAddButtons(w.hwnd,2,&buttons)
else
MessageBox(w,"Could not init TaskBarList!","Demo Application")
deleteimage myicon, @IMGICON
DestroyIcon(hPlay_icon)
DestroyIcon(hStop_icon)
pTaskBar->Release()
CoUninitialize()
CLOSEWINDOW w
endif
case @IDCONTROL
select @CONTROLID
case 1
cmd = "open \""  + GETSTARTPATH + "mv.mid" + "\" type sequencer alias mymidi"
mciSendStringA(cmd,"",0,0)
cmd = "play mymidi from 0"
mciSendStringA(cmd,"",0,0)
HICON hPlaying_icon = ExtractIconA(0,"shell32.dll",241)
pTaskBar->SetOverlayIcon(w.hwnd, hPlaying_icon, L"")
DestroyIcon(hPlaying_icon)
case 2
cmd = "stop mymidi"
mciSendStringA(cmd,"",0,0)
pTaskBar->SetOverlayIcon(w.hwnd, 0, L"")
endselect
case @IDCLOSEWINDOW
deleteimage myicon, @IMGICON
DestroyIcon(hPlay_icon)
DestroyIcon(hStop_icon)
cmd = "close mymidi"
mciSendStringA(cmd,"",0,0)
CLOSEWINDOW w
endselect
RETURN 0
ENDSUB

jalih

Don't know if someone needs this stuff or not, but next example shows how to use taskbar progress bar and how create overlay icon programmatically.


$INCLUDE "windowssdk.inc"
$INCLUDE "Shlobj.inc"


const TBPF_NOPROGRESS        = 0
const TBPF_INDETERMINATE     = 1
const TBPF_NORMAL            = 2
const TBPF_ERROR             = 4
const TBPF_PAUSED            = 8


GUID CLSID_TaskbarList
GUID IID_ITaskbarList3

DEFINE_GUID(CLSID_TaskbarList,0x56FDF344,0xFD6D,0x11D0,0x95,0x8A,0x00,0x60,0x97,0xC9,0xA0,0x90)
DEFINE_GUID(IID_ITaskbarList3,0xEA1AFB91,0x9E28,0x4B86,0x90,0xE9,0x9E,0x9F,0x8A,0x5E,0xEF,0xAF)

def pTaskBar as ITaskbarList3

uint WM_TASKBARBUTTONCREATED = RegisterWindowMessage("TaskbarButtonCreated")


HICON myicon = LOADIMAGE(GETSTARTPATH + "\heart.ico", @IMGICON)

DEF w as window
OPENWINDOW w,0,0,320,120,@MINBOX,NULL,"Simple Window",&whandler
centerwindow w
seticon w, myicon
move w, 10, 10: PRINT w,"Demonstration on how to create overlay icon"
move w, 10, 40: PRINT w,"programmatically..."
starttimer w, 1000, 1
WAITUNTIL w = 0
END


SUB whandler(),INT
static BOOL TaskBarButtonCreated = FALSE
static uint64 pos = 0uq
static uint64 max = 100uq

select @MESSAGE
case WM_TASKBARBUTTONCREATED
TaskBarButtonCreated = TRUE
CoInitialize(NULL)
HRESULT result = CoCreateInstance(CLSID_TaskbarList,0, 1, IID_ITaskbarList3, &pTaskBar)
if result = S_OK
pTaskBar->HrInit()
else
MessageBox(w,"Could not init TaskBarList!","Demo Application")
deleteimage myicon, @IMGICON
pTaskBar->Release()
CoUninitialize()
CLOSEWINDOW w
endif
case @IDTIMER
if TaskBarButtonCreated
if pos <= max
pTaskBar->SetProgressValue(w.hwnd, pos, max)
pTaskBar->SetProgressState(w.hwnd,TBPF_NORMAL)
if pos < max
HICON hIcon = CreateProgressOverlayIcon(w.hwnd, str$(pos))
pTaskBar->SetOverlayIcon(w.hwnd, hIcon, str$(pos))
DeleteObject(hIcon)
pos += 1
else
stoptimer w, 1
pTaskBar->SetOverlayIcon(w.hwnd, 0, NULL)
endif
endif
endif
case @IDCLOSEWINDOW
deleteimage myicon, @IMGICON
CLOSEWINDOW w
endselect
RETURN 0
ENDSUB


sub CreateProgressOverlayIcon(HWND hWnd, string szText),HICON
HDC hdc, hdcMem
HBITMAP hBitmap = NULL
HBITMAP hOldBitMap = NULL
HBITMAP hBitmapMask = NULL
ICONINFO iconInfo
HFONT hFont
HICON hIcon

int rcIcon[4]
        rcIcon =  0,0,16,16

hdc = GetDC(hWnd)
hdcMem = CreateCompatibleDC(hdc)
hBitmap = CreateCompatibleBitmap(hdc, 16, 16)
hBitmapMask = CreateCompatibleBitmap(hdc, 16, 16)
ReleaseDC(hWnd, hdc)
hOldBitMap = SelectObject(hdcMem, hBitmap)
PatBlt(hdcMem, 0, 0, 16, 16, PATCOPY)

hFont = CreateFont(12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Verdana")
hFont = SelectObject ( hdcMem, hFont )
DrawText(hdcMem, szText, -1, rcIcon, DT_CENTER | DT_VCENTER | DT_SINGLELINE)

SelectObject (hdc, hOldBitMap)
hOldBitMap = NULL

iconInfo.fIcon = TRUE
iconInfo.xHotspot = 0
iconInfo.yHotspot = 0
iconInfo.hbmMask = hBitmapMask
iconInfo.hbmColor = hBitmap

hIcon = CreateIconIndirect(iconInfo)

DeleteObject (SelectObject(hdcMem, hFont))
DeleteDC(hdcMem)
DeleteDC(hdc)
DeleteObject(hBitmap)
DeleteObject(hBitmapMask)

return hIcon
endsub

Brian

Jalih,

Both excellent examples. I haven't looked closely at the code yet, but I suppose you can dispense with the popup information window?

I was rather fooled by the progress bar example. I thought it was actually going to show a progress bar on the taskbar! Always wondered how that was done

Thank you,

brian

Egil

jalih,

Two excellent examples!
Thanks for sharing.


Egil
Support Amateur Radio  -  Have a ham  for dinner!