rasim Posted December 11, 2007 Share Posted December 11, 2007 How can i set tips for toolbar buttons? I know difficult variant with GuiRegisterMsg() from help-file, but can exist easy way for this task?expandcollapse popup#include <GuiConstants.au3> #include <GuiToolbar.au3> #include <GuiImageList.au3> #include <GuiToolTip.au3> Dim Enum $id1 = 1000, $id2 $hGUI = GUICreate("Toolbar", 400, 300) $hToolbar = _GUICtrlToolbar_Create($hGUI, $BTNS_BUTTON+$BTNS_SHOWTEXT+$TBSTYLE_LIST+$TBN_GETINFOTIP+$TBSTYLE_WRAPABLE, $TBSTYLE_EX_DRAWDDARROWS) $hImage = _GUIImageList_Create(16, 16, 5, 3) $hToolTip = _GUIToolTip_Create($hToolbar, $TTS_ALWAYSTIP) _GUICtrlToolbar_SetToolTips($hToolbar, $hToolTip) _GUIImageList_AddIcon($hImage, @AutoItExe, 0) _GUIImageList_AddIcon($hImage, @AutoItExe, 1) _GUICtrlToolbar_SetImageList($hToolbar, $hImage) $String1 = _GUICtrlToolbar_AddString($hToolbar, "Autoit") $String2 = _GUICtrlToolbar_AddString($hToolbar, "Close") _GUICtrlToolbar_AddButton($hToolBar, $id1, 0, $String1) _GUICtrlToolbar_AddButtonSep($hToolBar, 6) _GUICtrlToolbar_AddButton($hToolBar, $id2, 1, $String2) _GUICtrlToolbar_SetStyleFlat($hToolBar, True) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Link to comment Share on other sites More sharing options...
GaryFrost Posted December 11, 2007 Share Posted December 11, 2007 Don't think you'll get around the GUIRegisterMsg expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiToolbar.au3> #include <GuiImageList.au3> #include <GuiToolTip.au3> #include <WindowsConstants.au3> Dim Enum $id1 = 1000, $id2 $hGUI = GUICreate("Toolbar", 400, 300) $hToolbar = _GUICtrlToolbar_Create($hGUI, BitOR($BTNS_BUTTON,$BTNS_SHOWTEXT),$TBSTYLE_EX_DRAWDDARROWS) $hImage = _GUIImageList_Create(16, 16, 5, 3) $hToolTip = _GUIToolTip_Create($hToolbar, $TTS_ALWAYSTIP) _GUICtrlToolbar_SetToolTips($hToolbar, $hToolTip) _GUIImageList_AddIcon($hImage, @AutoItExe, 0) _GUIImageList_AddIcon($hImage, @AutoItExe, 1) _GUICtrlToolbar_SetImageList($hToolbar, $hImage) $String1 = _GUICtrlToolbar_AddString($hToolbar, "AutoIt") $String2 = _GUICtrlToolbar_AddString($hToolbar, "Close") _GUICtrlToolbar_AddButton($hToolbar, $id1, 0, $String1) _GUICtrlToolbar_AddButtonSep($hToolbar, 6) _GUICtrlToolbar_AddButton($hToolbar, $id2, 1, $String2) _GUICtrlToolbar_SetStyleFlat($hToolBar, True) ;Register WM_NOTIFY events GUIRegisterMsg($WM_NOTIFY, "WM_Notify") GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; WM_NOTIFY event handler Func WM_Notify($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $code, $tInfo $tInfo = DllStructCreate($tagNMTTDISPINFO, $lParam) $code = DllStructGetData($tInfo, "Code") Switch $code Case $TTN_GETDISPINFO Local $iID = DllStructGetData($tInfo, "IDFrom") Switch $iID Case $id1 DllStructSetData($tInfo, "aText", "Run AutoIt") Case $id2 DllStructSetData($tInfo, "aText", "Close AutoIt") EndSwitch EndSwitch ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>WM_Notify SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
rasim Posted December 11, 2007 Author Share Posted December 11, 2007 GaryFrostThank you! Link to comment Share on other sites More sharing options...
GaryFrost Posted December 11, 2007 Share Posted December 11, 2007 GaryFrostThank you!yw, you might want to put a switch/select in there for the tooltip handle, so it only checks when the tooltip handle matches the handle from lParam. SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
rover Posted December 11, 2007 Share Posted December 11, 2007 (edited) heres a toolbar example based on helpfile scripts with tooltip and toolbar event handling and a button state check.* * you may need to disable certain buttons on the toolbar when your script is running certain functions, just as menu items are 'greyed out' when those functions are not available has handle check for both toolbar and tooltips and example of enable / disable button state expandcollapse popup;AutoIt3 v3.2.10.0 or higher #include <GuiConstantsEx.au3> #include <GuiToolbar.au3> #include <GuiToolTip.au3> #Include <GuiRebar.au3> #Include <GuiImageList.au3> Opt('MustDeclareVars', 1) Global $iItem ; Command identifier of the button associated with the notification. Global $hGUI, $hToolbar, $hToolTip, $hReBar, $iMemo, $aStrings[5], $i = 0 Global Enum $id1 = 1000, $id2, $id3, $id4, $id5 ; ID's for each ToolBar button _Main() Func _Main() Local $hToolBarImageListNorm, $hToolBarImageListDisabled, $hToolBarImageListHot, $aSize $hGUI = GUICreate("Toolbar", 400, 300) $hReBar = _GUICtrlReBar_Create($hGUI, BitOR($RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) $hToolbar = _GUICtrlToolbar_Create($hGUI, BitOR($BTNS_AUTOSIZE, $BTNS_BUTTON, $BTNS_SHOWTEXT)) $aSize = _GUICtrlToolbar_GetMaxSize($hToolbar) ; Create ToolTip $hToolTip = _GUIToolTip_Create($hToolbar, $TTS_ALWAYSTIP) _GUICtrlToolbar_SetToolTips($hToolbar, $hToolTip) ; Add Icons from system DLL shell32.dll to ImageList $hToolBarImageListNorm = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 110) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 131) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 165) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 168) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 137) _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 146) ; add AutoIt icon from exe internal resources or icon added at compile time by compiler directives _GUIImageList_AddIcon($hToolBarImageListNorm, @AutoItExe, 0) ; AutoIt icon if run in Scite or compiled _GUICtrlToolbar_SetImageList($hToolbar, $hToolBarImageListNorm) ; Add strings $aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "&Open") $aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "E&xit") $aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "&Gear") $aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "&Tunes") $aStrings[4] = _GUICtrlToolbar_AddString($hToolbar, "&AutoIt") ; Add buttons _GUICtrlToolbar_AddButton($hToolbar, $id1, 0, $aStrings[0]) ; Index 0 _GUICtrlToolbar_AddButton($hToolbar, $id2, 1, $aStrings[1]) ; Index 1 _GUICtrlToolbar_AddButton($hToolbar, $id3, 2, $aStrings[2]) ; Index 2 _GUICtrlToolbar_AddButtonSep($hToolbar) ; Index 3 - separators have index values _GUICtrlToolbar_AddButton($hToolbar, $id4, 3, $aStrings[3]) ; Index 4 _GUICtrlToolbar_AddButtonSep($hToolbar) ; Index 5 - separators have index values _GUICtrlToolbar_AddButton($hToolbar, $id5, 6, $aStrings[4]) ; Index 6 _GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0) ; Remove $iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; /Remove ; Loop until user exits Do Sleep(10) Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Remove ; Write message to memo Func MemoWrite($sMessage = "") $i += 1 If $i = 16 Then GUICtrlSetData($iMemo, $sMessage & @CRLF) $i = 0 Else GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndIf EndFunc ;==>MemoWrite ; /Remove ; WM_NOTIFY event handler for Toolbar button press events and tooltips Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $hwndFrom, $code, $index Local $tNMTOOLBAR, $tInfo, $iID $tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam) $tInfo = DllStructCreate($tagNMTTDISPINFO, $lParam) $hwndFrom = DllStructGetData($tNMTOOLBAR, "hWndFrom") $code = DllStructGetData($tNMTOOLBAR, "Code") $iItem = DllStructGetData($tNMTOOLBAR, "iItem") Switch $hwndFrom Case $hToolbar Switch $code Case $TBN_BEGINDRAG $index = _GUICtrlToolbar_CommandToIndex($hToolbar, $iItem) ; Remove ;------------------------------------------------------------------ MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & $index) ;------------------------------------------------------------------ ; /Remove Switch _GUICtrlToolbar_IsButtonEnabled($hToolbar, $iItem) Case True Switch $index Case 0 Beep(1000, 5) Case 1 Beep(1500, 5) Exit Case 2 Beep(2000, 5) ; Disable / Enable Button 4 - Button 3 Is Checked when button 4 is disabled If _GUICtrlToolbar_IsButtonEnabled($hToolbar, $id4) Then _GUICtrlToolbar_EnableButton($hToolbar, $id4, False) _GUICtrlToolbar_CheckButton($hToolbar, $id3, True) Else _GUICtrlToolbar_EnableButton($hToolbar, $id4, True) _GUICtrlToolbar_CheckButton($hToolbar, $id3, False) EndIf Case 4 Beep(2500, 5) Case 6 Beep(3000, 5) SoundPlay(@WindowsDir & "\media\tada.wav", 0) EndSwitch EndSwitch EndSwitch Case $hToolTip Switch $code ; Toolbar Button Tooltips Case $TTN_GETDISPINFO $iID = DllStructGetData($tInfo, "IDFrom") Switch $iID Case $id1 DllStructSetData($tInfo, "aText", "Open") Case $id2 DllStructSetData($tInfo, "aText", "Exit") Case $id3 DllStructSetData($tInfo, "aText", "Options") Case $id4 DllStructSetData($tInfo, "aText", "Tunes") Case $id5 DllStructSetData($tInfo, "aText", "AutoIt") EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Edited December 11, 2007 by rover I see fascists... Link to comment Share on other sites More sharing options...
rasim Posted December 12, 2007 Author Share Posted December 12, 2007 roverYour example is very nice! This that me was it is necessary! Thank you guys! Link to comment Share on other sites More sharing options...
Madza91 Posted September 14, 2008 Share Posted September 14, 2008 (edited) Rover, great example, but is possible to call funcion when push up mouse button (like on default button) ?! Edited September 14, 2008 by n3nE [quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :) Link to comment Share on other sites More sharing options...
rover Posted September 14, 2008 Share Posted September 14, 2008 Rover, great example, but is possible to call funcion when push up mouse button (like on default button) ?!good timing n3nEwas just checking new poststo answer your question,you can use $TBN_ENDDRAG to indicate a mouse button up release.I'll take this opportunity to explain my using $TBN_BEGINDRAG instead of $NM_LDOWNin my above example.the button press messages for the toolbar you can use are$TBN_BEGINDRAG - left mouse down$TBN_ENDDRAG - left mouse up$NM_LDOWN - left mouse downI chose $TBN_BEGINDRAG because of its fast response time.$NM_LDOWN is much slower.its an incorrect usage, but if you don't use moveabletoolbar buttons then you can use that message.the downside is that the right click also works without depressing the button,so I use a check with _IsPressed("01") (Left Mouse Button) to prevent right mouse clicks.say for example a soundboard with preset sounds on a toolbar.using $TBN_BEGINDRAG the response is much faster without the lag of $NM_LDOWNthat's the reason why I used short beeps sounds, for button clicks, they demonstrate quite nicely the difference.Case $TBN_BEGINDRAG ; Take your pick: $TBN_BEGINDRAG or $NM_LDOWN ; $TBN_BEGINDRAG - both right and left click work, but faster response.* ; $NM_LDOWN - slower responsiveness, not suitable for functions requiring fast repeat (eg. sound effects) ; clicks missed if interval between clicks is too short ; * could use _IsPressed("01") (Left Mouse Button) with If or Switch statement combined with $TBN_BEGINDRAG I see fascists... Link to comment Share on other sites More sharing options...
ProgAndy Posted September 14, 2008 Share Posted September 14, 2008 (edited) Don't forget $NM_CLICK, if you want to use Mouse UP Func _TB_WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) Local $NMMOUSE = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;ulong_ptr dwItemSpec;ulong_ptr dwItemData;int pt[2]; ulong_ptr dwHitInfo;", $lParam) ;~ ConsoleWrite(DllStructGetData($NMMOUSE,1) & @CRLF) If DllStructGetData($NMMOUSE, 1) = $hToolbar Then If DllStructGetData($NMMOUSE, 3) = $NM_CLICK Then ; Here you can add the commands :) I made an extra Func, which is called with a Dummy -> This Func doens't wait;) Local $ClickedButtonID = DllStructGetData($NMMOUSE, "dwItemSpec") GUICtrlSendToDummy($ToolbarBUTTONDummy, $ClickedButtonID) EndIf EndIf Return 'GUI_RUNDEFMSG' EndFunc ;==>_TB_WM_NOTIFY Edited September 14, 2008 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Madza91 Posted September 14, 2008 Share Posted September 14, 2008 Oh Rover, thank you very much for this detailed explains!!! [quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :) Link to comment Share on other sites More sharing options...
ProgAndy Posted September 14, 2008 Share Posted September 14, 2008 But he forgot the easiest way, $NM_CLICK *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
rover Posted September 14, 2008 Share Posted September 14, 2008 Don't forget $NM_CLICK, if you want to use Mouse UP Func _TB_WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) Local $NMMOUSE = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;ulong_ptr dwItemSpec;ulong_ptr dwItemData;int pt[2]; ulong_ptr dwHitInfo;", $lParam) ;~ ConsoleWrite(DllStructGetData($NMMOUSE,1) & @CRLF) If DllStructGetData($NMMOUSE, 1) = $hToolbar Then If DllStructGetData($NMMOUSE, 3) = $NM_CLICK Then ; Here you can add the commands :) I made an extra Func, which is called with a Dummy -> This Func doens't wait;) Local $ClickedButtonID = DllStructGetData($NMMOUSE, "dwItemSpec") GUICtrlSendToDummy($ToolbarBUTTONDummy, $ClickedButtonID) EndIf EndIf Return 'GUI_RUNDEFMSG' EndFunc;==>_TB_WM_NOTIFY $NM_CLICK thanks for pointing that out ProgAndy I didn't review all the toolbar messages I have been using the dummy control however because of the necessity of returning quickly from the message handler and not having blocking functions in there. I see fascists... Link to comment Share on other sites More sharing options...
Madza91 Posted September 14, 2008 Share Posted September 14, 2008 (edited) Btw, one more thing... how to add separator between 2 buttons but no empty space? I use _GUICtrlToolbar_AddButtonSep but its only added empty space between 2 buttons... Edited September 14, 2008 by n3nE [quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :) Link to comment Share on other sites More sharing options...
rover Posted September 14, 2008 Share Posted September 14, 2008 Btw, one more thing... how to add separator between 2 buttons but no empty space? I use _GUICtrlToolbar_AddButtonSep but its only added empty space between 2 buttons...you can set the width of the separator, the default is 6 pixels_GUICtrlToolbar_AddButtonSep($hToolbar, 1) is that what you mean? I see fascists... Link to comment Share on other sites More sharing options...
Madza91 Posted September 14, 2008 Share Posted September 14, 2008 I mean on line between buttons like this: [quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :) Link to comment Share on other sites More sharing options...
rover Posted September 14, 2008 Share Posted September 14, 2008 Ok, I think I know what you mean you want something else in between 2 toolbar buttons? you will probably have to use rebars for that with two separate toolbars I see fascists... Link to comment Share on other sites More sharing options...
Madza91 Posted September 14, 2008 Share Posted September 14, 2008 In example script is added separator and it's not empty space - it is that line what i want, but never mind, i can add Graphic ;D#include <GuiToolbar.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> Opt('MustDeclareVars', 1) $Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work _Main() Func _Main() Local $hGUI, $hToolbar Local Enum $idNew = 1000, $idOpen, $idSave, $idHelp ; Create GUI $hGUI = GUICreate("Toolbar", 400, 300) $hToolbar = _GUICtrlToolbar_Create ($hGUI) GUISetState() ; Add standard system bitmaps _GUICtrlToolbar_AddBitmap ($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR) ; Add buttons _GUICtrlToolbar_AddButton ($hToolbar, $idNew, $STD_FILENEW) _GUICtrlToolbar_AddButton ($hToolbar, $idOpen, $STD_FILEOPEN) _GUICtrlToolbar_AddButton ($hToolbar, $idSave, $STD_FILESAVE) _GUICtrlToolbar_AddButtonSep ($hToolbar) _GUICtrlToolbar_AddButton ($hToolbar, $idHelp, $STD_HELP) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_MainHehe, i have one more question Is possible to made button with menu like this on screenshot: [quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :) Link to comment Share on other sites More sharing options...
rover Posted September 14, 2008 Share Posted September 14, 2008 (edited) perhaps with setmetrics looks like some of this depends on the visual style in use ok late on the post, I see your second image, that's a dropdown button Edited September 14, 2008 by rover I see fascists... Link to comment Share on other sites More sharing options...
Madza91 Posted September 14, 2008 Share Posted September 14, 2008 Thank you for answers ;D [quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :) Link to comment Share on other sites More sharing options...
rover Posted September 14, 2008 Share Posted September 14, 2008 Thank you for answers ;D if you want an example of using dropdown menu buttons look at this post. I know I updated the _GetToolbarButtonScreenPos function but that was a while back and I don't remember what i changed in it, I'll review the code and post here if its relevant. Toolbar example, How To? I see fascists... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now