Jump to content

Thumbnail Toolbar Example


Beege
 Share

Recommended Posts

Updated 3-3-2010: UDF Finished. See here.

Updated 3-1-2010:

Learned how to create array of thumbutton structures correctly(Thanks Wraithdu). Now there's no problem adding extra buttons. But note that the MSDN says the most you can add is 7. I will soon finish a UDF for making this very easy to do. :mellow:

Heres small example that demonstrates another Windows 7 feature, Thumbnail toolbars. While the example works, I'm pretty sure I'm doing something wrong because I can't get it work with more than 2 buttons so PLEASE let me know if the example works for you. I think problem is coming from the ThumbBarAddButtons Method. The MSDN states that it needs a "pointer to an array of THUMBBUTTON structures". If anybody know how I would correctly create this array in AutoIT, please comment. I also want to give thanks to the autoitobject team and to wraithdu for his recent example. Without it I would never have been able to figure out my very small, but fatal mistake in implementing ITaskBarList.

#include <AutoItObject.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
OnAutoItExitRegister('_Exit')

#region Constants
;THUMBBUTTONMASK
Global Const $THB_BITMAP = 0x00000001
Global Const $THB_ICON = 0x00000002
Global Const $THB_TOOLTIP = 0x00000004
Global Const $THB_FLAGS = 0x00000008

;ThumbEvent
Global Const $THBN_CLICKED = 0x1800

;THUMBBUTTONFLAGS
Global Const $THBF_ENABLED = 0x00000000
Global Const $THBF_DISABLED = 0x00000001
Global Const $THBF_DISMISSonclick = 0x00000002
Global Const $THBF_NOBACKGROUND = 0x00000004
Global Const $THBF_HIDDEN = 0x00000008
Global Const $THBF_NONINTERACTIVE = 0x00000010
#endregion

Global $hGui = GUICreate("Thumbnail Buttons", 250, 10)
Global $o_hGui = Number($hGui)
GUIRegisterMsg($WM_COMMAND, 'WM_Command')
GUISetState()

_AutoItObject_StartUp()
Global $pTask
Global $oTaskBar = _GetTaskBarObj($pTask)
$oTaskBar.HrInit()

Global $aButtons
_Create_THUMBBUTTON_Structures($aButtons)
$oTaskBar.ThumbBarAddButtons($o_hGui, 3, Number(DllStructGetPtr($aButtons)))


Do
Until GUIGetMsg() = -3


Func _Create_THUMBBUTTON_Structures(ByRef $Struct)

    $sIcondown = _WinAPI_LoadImage(0, @ScriptDir & '\Down.ico', $IMAGE_ICON, 16, 16, $LR_LOADFROMFILE)
    $sIconleft = _WinAPI_LoadImage(0, @ScriptDir & '\Left.ico', $IMAGE_ICON, 16, 16, $LR_LOADFROMFILE)
    $sIconright = _WinAPI_LoadImage(0, @ScriptDir & '\Right.ico', $IMAGE_ICON, 16, 16, $LR_LOADFROMFILE)

    Local $tagTHUMBBUTTON = "dword;UINT;UINT;handle;WCHAR[260];dword"
    $Struct = DllStructCreate($tagTHUMBBUTTON & ';' & $tagTHUMBBUTTON & ';' & $tagTHUMBBUTTON)

    ;Down Button
    DllStructSetData($Struct, 1, BitOR($THB_ICON, $THB_TOOLTIP, $THB_FLAGS));'dwMask'
    DllStructSetData($Struct, 2, 10);'iId'
    DllStructSetData($Struct, 3, 0);'iBitmap'
    DllStructSetData($Struct, 4, $sIcondown);'hIcon'
    DllStructSetData($Struct, 5, 'Down Button');'szTip'
    DllStructSetData($Struct, 6, $THBF_ENABLED);'dwFlags'

    ;Left Button
    DllStructSetData($Struct, 7, BitOR($THB_ICON, $THB_TOOLTIP, $THB_FLAGS));'dwMask'
    DllStructSetData($Struct, 8, 11);'iId'
    DllStructSetData($Struct, 9, 0);'iBitmap'
    DllStructSetData($Struct, 10, $sIconleft);'hIcon'
    DllStructSetData($Struct, 11, 'Left Button');'szTip'
    DllStructSetData($Struct, 12, $THBF_ENABLED);'dwFlags'

    ;Right Button
    DllStructSetData($Struct, 13, BitOR($THB_ICON, $THB_TOOLTIP, $THB_FLAGS));'dwMask'
    DllStructSetData($Struct, 14, 12);'iId'
    DllStructSetData($Struct, 15, 0);'iBitmap'
    DllStructSetData($Struct, 16, $sIconright);'hIcon'
    DllStructSetData($Struct, 17, 'Right Button');'szTip'
    DllStructSetData($Struct, 18, $THBF_ENABLED);'dwFlags'

EndFunc

; ===================================================================
; _GetTaskBarObj(ByRef $pInstance)
;
; Description. Creates and Returns ITaskbar Interface Object. (Or is this a Dispatch Object?)
; Parameters:
;   $pInstance - IN/OUT - Pointer to var to put CoCreateInstance.
; Returns: ITaskbar Object
;   None.
; ===================================================================
Func _GetTaskBarObj(ByRef $pInstance)

    Local $CLSID_TaskBarlist = _AutoItObject_CLSIDFromString("{56FDF344-FD6D-11D0-958A-006097C9A090}")
    Local $IID_ITaskbarList3 = _AutoItObject_CLSIDFromString("{ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf}")

    Local $tagInterface = "QueryInterface long(ptr;ptr;ptr);" & _
            "AddRef ulong();" & _
            "Release ulong();" & _
            "HrInit long();" & _
            "AddTab long(hwnd);" & _
            "DeleteTab long(hwnd);" & _
            "ActivateTab long(hwnd);" & _
            "SetActiveAlt long(hwnd);" & _
            "MarkFullscreenWindow long(hwnd;int);" & _
            "SetProgressValue long(hwnd;uint64;uint64);" & _
            "SetProgressState long(hwnd;int);" & _
            "RegisterTab long(hwnd;hwnd);" & _
            "UnregisterTab long(hwnd);" & _
            "SetTabOrder long(hwnd;hwnd);" & _
            "SetTabActive long(hwnd;hwnd;dword);" & _
            "ThumbBarAddButtons long(hwnd;uint;ptr);" & _
            "ThumbBarUpdateButtons long(hwnd;uint;ptr);" & _
            "ThumbBarSetImageList long(hwnd;ptr);" & _
            "SetOverlayIcon long(hwnd;ptr;wstr);" & _
            "SetThumbnailTooltip long(hwnd;wstr);" & _
            "SetThumbnailClip long(hwnd;ptr);"

;~  Local $pInstance
    _AutoItObject_CoCreateInstance(DllStructGetPtr($CLSID_TaskBarlist), 0, 1, DllStructGetPtr($IID_ITaskbarList3), $pInstance)

    Return _AutoItObject_WrapperCreate($pInstance, $tagInterface)

EndFunc   ;==>_GetTaskBarObj

Func WM_Command($hWnd, $msg, $wParam, $lParam)

    Local $iMsg = _WinAPI_HiWord($wParam)

    If $iMsg = $THBN_CLICKED Then
        Local $iID = _WinAPI_LoWord($wParam)
        Switch $iID
            Case 11
                MsgBox(0, 'Button Pressed', 'Left Button ID = ' & $iID)
            Case 12
                MsgBox(0, 'Button Pressed', 'Right Button ID = ' & $iID)
            Case 10
                MsgBox(0, 'Button Pressed', 'Down Button ID = ' & $iID)
        EndSwitch
    EndIf

EndFunc   ;==>WM_Command

Func _Exit()
    $oTaskBar = 0
    _AutoItObject_Shutdown()
EndFunc   ;==>_Exit

Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
    Return
EndFunc   ;==>_ErrFunc

Thumbnail Buttons Example.zip

PD = 34

Obviously, you need Windows 7 and AutoitObject for this example to work.

Edited by Beege
Link to comment
Share on other sites

Nice idea and screenshot :(

So now the AutoItObject.au3 is supose to be a native AutoIt's include file? :mellow:

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Thanks. By native you mean in the main autoit include folder? If so then no. Some time back they changed it so that autoit will check the script folder if the include is not found in main include folder.

So... #include "AutoItObject.au3" is no longer needed.

Link to comment
Share on other sites

You are creating an array of pointers to structures. To create an array of structures, you need to create the whole structure a number of times equal to the size of the array you need. In pseudo code:

$tag = "int;int" ; you can't name the elements here since you will be duplicating this tag
$array = $tag & $tag & $tag ; array of 3 tag structures
Link to comment
Share on other sites

You are creating an array of pointers to structures. To create an array of structures, you need to create the whole structure a number of times equal to the size of the array you need. In pseudo code:

$tag = "int;int" ; you can't name the elements here since you will be duplicating this tag
$array = $tag & $tag & $tag ; array of 3 tag structures

That worked like a charm wraithdu! Thankyou very much. I can now finish the UDF for it. :mellow:
Link to comment
Share on other sites

wonderful,waiting for your udf

Thanks. Should have it ready tomorrow. :mellow:
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...