PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Thumbnail with tool bar buttons from Task-bar  (Read 560 times)

Pierre Bellisle

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 57
Thumbnail with tool bar buttons from Task-bar
« on: December 19, 2016, 03:18:50 PM »

Hey,

This is some 32/64 bit code that will show a thumbnail with a three buttons tool-bar
when one hover the application button in the task-bar.

Info: TaskbarItemInfo.ThumbButtonInfos Property

Info: Raymond Chen - The Old New Thing - Display a custom thumbnail for your application.



Have fun,
Pierre

Main .bas file
Code: [Select]

#Print Add a hover taskbar"s thumbnail with toolbar to your application - Windows 32/64
#Print Coded written under FreeBASIC 1.05.0
#Ifdef __FB_64BIT__
  #Print 64bit compiler used
#Else
  #Print 32bit compiler used
#EndIf
#lang "fb"

#Define unicode

#Include Once "windows.bi"
#Include Once "win\commctrl.bi"
#Include Once "win\shellapi.bi"
#Include Once "win\combaseapi.bi"
#Include Once "win\objbase.bi"
#Include Once "win\winnt.bi"
#Include Once "win\shobjidl.bi" 'For Windows taskbar thumbnail toolbar

Declare Function RtlGetVersion Lib "NtDll.dll" Alias "RtlGetVersion"(OsVersionInformation As RTL_OSVERSIONINFOW) As Long 'RtlGetVersion returns 0-STATUS_SUCCESS.

#Define AppName                     "Thumbnail"
#Define CrLf                        Chr(13, 10)
#Define ButtonDecrement             101
#Define ButtonIncrement             102
#Define ButtonExit                  103
#Define ButtonThumbnailBarDecrement 111
#Define ButtonThumbnailBarIncrement 112
#Define ButtonThumbnailBarExit      113
#Define StaticInfo                  201
#Define StaticNum                   202

#Define MakeDword(HighWord, LowWord)(HighWord Shl 16 Or LowWord)

Dim Shared As HINSTANCE hInstance : hInstance = GetModuleHandle(NULL)

Function WinVerRtl() As Single
 Dim OsVerInfo As RTL_OSVERSIONINFOW

 'Report true version even without manifest for Windows 8.1+
 OsVerInfo.dwOSVersionInfoSize = SizeOf(OsVerInfo)
 RtlGetVersion(OsVerInfo)
 Function = Val(OsVerInfo.dwMajorVersion & "." & OsVerInfo.dwMinorVersion)
 
 'MessageBox(HWND_DESKTOP, _
 '"dwMajorVersion   " & OsVerInfo.dwMajorVersion  & CRLF & _
 '"dwMinorVersion   " & OsVerInfo.dwMinorVersion  & CRLF & _
 '"dwBuildNumber    " & OsVerInfo.dwBuildNumber   & CRLF & _
 '"dwPlatformId     " & OsVerInfo.dwPlatformId    & CRLF & _
 '"szCSDVersion     " & "[" & OsVerInfoEx.szCSDVersion & "]", _
 '"Thumbnail - RtlGetVersion", MB_OK OR MB_TOPMOST)

End Function

Function EnumCharSet(elf As ENUMLOGFONT, ntm As NEWTEXTMETRIC, _
                     ByVal FontType As Long, CharSet As Long) As BOOLEAN
 'Get type of character set - ansi, symbol, a must for some fonts.
 CharSet  = elf.elfLogFont.lfCharSet
 Function = TRUE
End Function

Function MakeFontEx(ByVal hDC As HDC, ByVal pwsFontName As WString Pointer, ByVal PointSize As Long, _
                    ByVal Angle As Long, ByVal fBold As Long, ByVal fItalic As DWORD, _
                    ByVal fUnderline As DWORD, ByVal StrikeThru As DWORD) As HFONT 'Thank to Börje Hagsten
 
 'Create a font and return its handle.
 Dim CharSet  As LParam
 Dim CyPixels As Long
 
 If hDC = 0 Then
   hDC      = GetDC(HWND_DESKTOP)
   CyPixels = GetDeviceCaps(hDC, LOGPIXELSY) 
   EnumFontFamilies(hDC, pwsFontName, Cast(FONTENUMPROCW, ProcPtr(EnumCharSet)), CharSet)
   ReleaseDC(HWND_DESKTOP, hDC)
 Else
   CyPixels = GetDeviceCaps(hDC, LOGPIXELSY)
   EnumFontFamilies(hDC, pwsFontName, Cast(FONTENUMPROCW, ProcPtr(EnumCharSet)), CharSet)
 End If

 PointSize = 0 - (PointSize * CyPixels) \ 72

 Function = CreateFont(PointSize, 0, _                         'Height, Width (default=0),
                       Angle, Angle, _                         'Escapement(angle), Orientation,
                       fBold, _                                'Weight (%FW_DONTCARE = 0, %FW_NORMAL = 400, %FW_BOLD = 700),
                       fItalic, fUnderline, StrikeThru, _      'Italic, Underline, Strike thru,
                       CharSet, OUT_TT_PRECIS, _               'Char set, Output precision,
                       CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, _ 'ClipPrecision, Quality,
                       FF_DONTCARE,  pwsFontName)              'Pitch and family, Typeface

End Function

Sub CreateThumbnailToolbar(hWnd As HWND)
 Dim ThumbnailButtonArray(0 To 2) As THUMBBUTTON
 Dim pITaskBarList3  As ITaskBarList3 Pointer 
 Dim uzDesc          As WString * 36
 Dim icoDecrement    As HICON
 Dim icoExit         As HICON
 Dim icoIncrement    As HICON
 Dim IcoOverlay      As HICON
 Dim iconIndexOffset As Long
 Dim HR              As HRESULT
 
 CoInitialize(NULL)
 
 HR = CoCreateInstance(@CLSID_TaskBarList, NULL, CLSCTX_INPROC_SERVER, _
                       @IID_ITaskBarList3, @pITaskBarList3)
 If (SUCCEEDED(HR)) Then
   
   pITaskBarList3->lpVtbl->HrInit(pITaskBarList3) 'Initialize

   'Choose images for thumbnail buttons
   If WinVerRtl < 10 Then iconIndexOffset = 15 'Win10 have a different index for those icons
   icoDecrement = ExtractIcon(hInstance, "wmploc.DLL", 184 + iconIndexOffset) 'Left arrow
   icoExit      = ExtractIcon(hInstance, "wmploc.DLL", 182 + iconIndexOffset) 'Red x
   icoIncrement = ExtractIcon(hInstance, "wmploc.DLL", 183 + iconIndexOffset) 'Right arrow

   'Create the toolbar via an array of buttons
   ThumbnailButtonArray(0).dwMask  = THB_ICON Or THB_FLAGS Or THB_TOOLTIP
   ThumbnailButtonArray(0).iId     = ButtonThumbnailBarDecrement
   ThumbnailButtonArray(0).iBitmap = 0 'With THB_BITMAP flag. Image list index of ITaskbarList3::ThumbBarSetImageList
   ThumbnailButtonArray(0).hIcon   = icoDecrement
   ThumbnailButtonArray(0).szTip   = "Decrement" 'Tooltip
   ThumbnailButtonArray(0).dwFlags = THBF_ENABLED

   ThumbnailButtonArray(1).dwMask  = THB_ICON Or THB_FLAGS Or THB_TOOLTIP
   ThumbnailButtonArray(1).iId     = ButtonThumbnailBarExit
   ThumbnailButtonArray(1).iBitmap = 0 'With THB_BITMAP flag. Image list index of ITaskbarList3::ThumbBarSetImageList
   ThumbnailButtonArray(1).hIcon   = icoExit
   ThumbnailButtonArray(1).szTip   = "Exit program" 'Tooltip
   ThumbnailButtonArray(1).dwFlags = THBF_ENABLED

   ThumbnailButtonArray(2).dwMask  = THB_ICON Or THB_FLAGS Or THB_TOOLTIP
   ThumbnailButtonArray(2).iId     = ButtonThumbnailBarIncrement
   ThumbnailButtonArray(2).iBitmap = 0 'With THB_BITMAP flag. Image list index of ITaskbarList3::ThumbBarSetImageList
   ThumbnailButtonArray(2).hIcon   = icoIncrement
   ThumbnailButtonArray(2).szTip   = "Increment" 'Tooltip
   ThumbnailButtonArray(2).dwFlags = THBF_ENABLED
   
   'Add thumbnail toolbar buttons made of 3 buttons 
   pITaskBarList3->lpVtbl->ThumbBarAddButtons(pITaskBarList3, hWnd, ByVal 3, @ThumbnailButtonArray(0))

   'Taskbar overlay icon, shown over the taskbar icon if "Use small icon" Start button option is unchecked
   'To set: Start button right click/Properties/Taskbar/Uncheck "Use small icon"
   'hIcon is 16x16, pass a NULL to remove it.
   uzDesc     = "Description if icon can't be shown"
   IcoOverlay = ExtractIcon(hInstance, "Shell32.dll", 176)
   pITaskBarList3->lpVtbl->SetOverlayIcon(pITaskBarList3, hWnd, IcoOverlay, @uzDesc)
   
   'Clean up
   pITaskBarList3->lpVtbl->Release(pITaskBarList3)
   
   'The thumbnail made his own copy, so those handles can be destroyed
   DestroyIcon(icoDecrement)
   DestroyIcon(icoExit)
   DestroyIcon(icoIncrement)
   DestroyIcon(IcoOverlay)
   
 Else
   MessageBox(HWND_DESKTOP, "CoCreateInstance error", "Thumbnail", MB_OK Or MB_TOPMOST)
 End If
 
 CoUninitialize()

End Sub
Function WndProc(ByVal hWnd As HWND, ByVal uMsg As UINT, ByVal wParam As WPARAM, ByVal lParam As LPARAM) As Integer
 Dim    hButtonDecrement As HWND
 Dim    hButtonIncrement As HWND
 Dim    hButtonExit      As HWND
 Dim    hStaticInfo      As HWND
 Static hStaticNum       As HWND
 Static WM_TaskBarId     As UINT
 Static hFont            As HFONT
 Dim    zBuff            As WString * 64
 Static Value            As LONG32 => 5
 
 Function = 0
   
 Select Case (uMsg)
 
   Case WM_CREATE
     hFont = GetStockObject(DEFAULT_GUI_FONT)     
     
     'A message will be received at WM_TaskBarId after registration and
     'after the creation of the taskbar button
     WM_TaskBarId = RegisterWindowMessage("TaskbarButtonCreated")

     hButtonDecrement = CreateWindowEx(0, "Button", "&Decrement", _ 'ExStyle, ClassName, WindowName,
                                       WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or WS_GROUP Or _
                                       BS_CENTER Or BS_VCENTER, _ 'Style,
                                       10, 10, 80, 30, _ 'PosX, PosY, Width, Height,
                                       hWnd, Cast(HMENU, ButtonDecrement), _ 'hParent, id/hMenu,
                                       hInstance, NULL) 'hInstance, lpParam
     SendMessage(hButtonDecrement, WM_SETFONT, Cast(UInteger, hFont), TRUE)
     
     hButtonIncrement = CreateWindowEx(0, "Button", "&Increment", _ 'ExStyle, ClassName, WindowName,
                                       WS_CHILD Or WS_VISIBLE Or BS_CENTER Or WS_TABSTOP Or _
                                       BS_NOTIFY Or BS_TEXT Or BS_VCENTER, _ 'Style,
                                       10, 50, 80, 30, _ 'PosX, PosY, Width, Height,
                                       hWnd, Cast(HMENU, ButtonIncrement), _ 'hParent, id/hMenu,
                                       hInstance, NULL) 'hInstance, lpParam
     SendMessage(hButtonIncrement, WM_SETFONT, Cast(UInteger, hFont), TRUE)
     
     hButtonExit      = CreateWindowEx(0, "Button", "E&xit", _ 'ExStyle, ClassName, WindowName,
                                       WS_CHILD Or WS_VISIBLE Or BS_CENTER Or WS_TABSTOP Or _
                                       BS_NOTIFY Or BS_TEXT Or BS_VCENTER, _ 'Style,
                                       10, 90, 80, 30, _ 'PosX, PosY, Width, Height,
                                       hWnd, Cast(HMENU, ButtonExit), _ 'hParent, id/hMenu,
                                       hInstance, NULL) 'hInstance, lpParam
    SendMessage(hButtonExit, WM_SETFONT, Cast(WPARAM, hFont), TRUE)
     
    hStaticInfo       = CreateWindowEx(0, "Static", "Hover taskbar's button to " & CRLF & "see thumbnail & toolbar", _
                                       WS_CHILD Or WS_VISIBLE Or SS_CENTER Or _
                                       SS_NOPREFIX Or SS_NOTIFY Or SS_SUNKEN, _ 'Style,
                                       10, 125, 200, 30, _ 'PosX, PosY, Width, Height,
                                       hWnd, Cast(HMENU, StaticInfo), _ 'hParent, id/hMenu,
                                       hInstance, NULL) 'hInstance, lpParam
    SendMessage(hStaticInfo, WM_SETFONT, Cast(UInteger, hFont), TRUE)   
   
    hStaticNum        = CreateWindowEx(0, "Static", "", _'ExStyle, ClassName, WindowName, 
                                       WS_CHILD Or WS_VISIBLE Or SS_CENTER Or SS_CENTERIMAGE Or _
                                       SS_NOPREFIX Or SS_NOTIFY Or SS_SUNKEN, _ 'Style,
                                       100, 10, 110, 110, _ 'PosX, PosY, Width, Height,
                                       hWnd, Cast(HMENU, StaticNum), _ 'hParent, id/hMenu, 
                                       hInstance, NULL) 'hInstance, lpParam
    hFont = MakeFontEx(0, "Arial", 48, 0000, FW_BOLD, 0, 0, 0) 'Create a big font
    SendMessage(hStaticNum, WM_SETFONT, Cast(UInteger, hFont), TRUE) 'Set hStaticNum font
    zBuff = Str(Value) 'Convert value to text
    SendMessage(hStaticNum, WM_SETTEXT, 0, Cast(UInteger, @zBuff)) 'Set hStaticNum text
     
    Case WM_TaskBarId
     CreateThumbnailToolbar(hWnd) 'Now is the time to create the toolbar
       
    Case WM_COMMAND
     Select Case LoWord(wParam)

        Case ButtonDecrement
         If HiWord(wParam) = BN_CLICKED Then
           Value -= 1 : If Value < 0 Then Value = 9
           zBuff = Str(Value)
           SendMessage(hStaticNum, WM_SETTEXT, 0, Cast(UInteger, @zBuff))           
         EndIf

        Case ButtonIncrement
          If HiWord(wParam) = BN_CLICKED Then
            Value += 1 : If Value > 9 Then Value = 0
            zBuff = Str(Value)
            SendMessage(hStaticNum, WM_SETTEXT, 0, Cast(UInteger, @zBuff))           
          EndIf

        Case ButtonExit
          If HiWord(wParam) = BN_CLICKED Then
            PostMessage(hWnd, WM_CLOSE, 0, 0)
            Exit Function
          EndIf

        Case ButtonThumbnailBarDecrement 'This come from a thumbnail button
          PostMessage(hWnd, WM_COMMAND, MakeDword(BN_CLICKED, ButtonDecrement), 0)

        Case ButtonThumbnailBarExit 'This come from a thumbnail button
          PostMessage(hWnd, WM_CLOSE, 0, 0)

        Case ButtonThumbnailBarIncrement 'This come from a thumbnail button
          PostMessage(hWnd, WM_COMMAND, MakeDword(BN_CLICKED, ButtonIncrement), 0)

     End Select     
 
   Case WM_DESTROY
     DeleteObject(hFont) 'Clean up "Arial", 48
     PostQuitMessage(0)
     Exit Function
   
 End Select
   
 Function = DefWindowProc(hWnd, uMsg, wParam, lParam)
       
End Function

Function WinMain(ByVal hInstance As HINSTANCE, ByVal hPrevInst As HINSTANCE, _
                 ByVal CmdLine As WString Ptr, ByVal CmdShow As Integer) As UINT
 Dim WinClass   As WNDCLASS     
 Dim wMsg       As MSG
 Dim hWnd       As HWND 
 Dim hIco       As HICON 
 Dim WindowSize As SIZEL
 Dim wsAppName  As WString * 128
 
 CoInitialize(NULL) 'Initialize COM library
 
 wsAppName              = AppName & " - " & SizeOf(UInteger) * 8 
 WindowSize.cx          = 230
 WindowSize.cy          = 190
 hIco                   = ExtractIcon(hInstance, "Shell32.dll", 27)
 WinClass.style         = CS_HREDRAW Or CS_VREDRAW
 WinClass.lpfnWndProc   = ProcPtr(WndProc)
 WinClass.cbClsExtra    = 0
 WinClass.cbWndExtra    = 0
 WinClass.hInstance     = hInstance
 WinClass.hIcon         = hIco
 WinClass.hCursor       = LoadCursor(NULL, IDC_ARROW)
 WinClass.hbrBackground = Cast(HGDIOBJ, COLOR_BTNFACE + 1)   
 WinClass.lpszMenuName  = NULL
 WinClass.lpszClassName = VarPtr(wsAppName) 
   
 If (RegisterClass(@WinClass)) Then
   hWnd = CreateWindowEx(WS_EX_WINDOWEDGE, _ 'ExStyle
                         wsAppName, wsAppName, _ 'ClassName, WindowName
                         WS_CLIPCHILDREN Or WS_DLGFRAME Or WS_BORDER Or WS_VISIBLE Or WS_CAPTION Or _
                         WS_MAXIMIZEBOX Or WS_MINIMIZEBOX Or WS_SYSMENU , _ 'Style
                         (GetSystemMetrics(SM_CXSCREEN) - WindowSize.cx) / 2, _ 'PosX
                         (GetSystemMetrics(SM_CYSCREEN) - WindowSize.cy) / 2, _ 'PosY
                         WindowSize.cx, WindowSize.cy, _ 'Width, height                   
                         NULL, NULL, hInstance, NULL) 'hWndParent, hMenu, hInstance, lpParam

   While GetMessage(@wMsg, ByVal NULL, 0, 0) > 0 'Message loop
     If IsDialogMessage(hWnd, @wMsg) = 0 Then
       TranslateMessage(@wMsg)
       DispatchMessage(@wMsg)
     End If
   Wend   
   
  End If
  DestroyIcon(hIco)
  CoUninitialize
  Function = wMsg.message
 
  Dim As HDC hDc = GetDC(hWnd)
   
End Function

End WinMain(hInstance, NULL, Command(), SW_NORMAL) 'Call main() and return a code to the OS

Resource .rc file
Code: [Select]
#define MANIFEST 24
#define IDR_VERSION1 1
#define IDR_MANIFEST1 1

IDR_VERSION1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x00000004
FILETYPE 0x00000001
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904B0"
    BEGIN
      VALUE "FileVersion", "1.0.0.0\0"
      VALUE "ProductVersion", "1.0.0.0\0"
    END
  END
  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x0409, 0x04B0
  END
END

IDR_MANIFEST1 MANIFEST "manifest.xml"

Manifest file: manifest.xml
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
   version="1.0.0.0"
   processorArchitecture="*"
   name="Company.Product.Name"
   type="win32"
/>
<description></description>

       <!-- Theme section -->
       <dependency>
         <dependentAssembly>
           <assemblyIdentity
             type="win32"
             name="Microsoft.Windows.Common-Controls"
             version="6.0.0.0"
             processorArchitecture="*"
             publicKeyToken="6595b64144ccf1df"
             language="*"
           />
         </dependentAssembly>
       </dependency>

       <!-- Trustinfo section -->
        <asmv3:trustInfo xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
         <asmv3:security>
           <asmv3:requestedPrivileges>
             <!-- level="asInvoker" level="highestAvailable" level="requireAdministrator" -->
             <asmv3:requestedExecutionLevel
               level="asInvoker"
               uiAccess="false" />
           </asmv3:requestedPrivileges>
         </asmv3:security>
       </asmv3:trustInfo>

       <!-- Compatibility section for Program Compatibility Assistant (PCA) -->
       <compatibility xmlns='urn:schemas-microsoft-com:compatibility.v1'>
         <application>
           // Windows XP and Windows Vista ignore this manifest section
           <!-- Windows Vista -->
           <supportedOS Id='{e2011457-1546-43c5-a5fe-008deee3d3f0}'/>
           <!-- Windows 7 -->
           <supportedOS Id='{35138b9a-5d96-4fbd-8e2d-a2440225f93a}'/>
           <!-- Windows 8 -->
           <supportedOS Id='{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}'/>
           <!-- Windows 8.1 Needed to report GetVersionEx 6.3 instead of 8.2-->
           <supportedOS Id='{1f676c76-80e1-4239-95bb-83d0f6d0da78}'/>
           <!-- Windows 10.0 Needed to report GetVersionEx 10.0 instead of 6.2-->
           <supportedOS Id='{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}'/>
         </application>
       </compatibility>

       //DpiAware section
       <asmv3:application xmlns:asmv3='urn:schemas-microsoft-com:asm.v3'>
         <asmv3:windowsSettings xmlns='http:\x2F\x2Fschemas.microsoft.com/SMI/2005/WindowsSettings'> // \x2F = 47 = "/"
           <dpiAware>false</dpiAware>
           // <dpiAware>true</dpiAware>
         </asmv3:windowsSettings>
       </asmv3:application>

</assembly>
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: Thumbnail with tool bar buttons from Task-bar
« Reply #1 on: December 19, 2016, 05:56:48 PM »

Hey that's pretty cool!
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Pierre Bellisle

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 57
Re: Thumbnail with tool bar buttons from Task-bar
« Reply #2 on: December 19, 2016, 07:09:13 PM »

:-) Yes, I like it too. When you got a multitude of open windows,
it is quite usefull to get acces to the fundamentals
of a program without disturbing the desktop order.
I was jealous of "Windows Media Player" and wondered
what trick the old Bill was using to do that...
Logged