Popular Post LarsJ Posted October 4, 2013 Popular Post Share Posted October 4, 2013 (edited) Hot-tracking in a menu bar means that the (drop down) menu items are shown automatically, when the mouse cursor hovers over the top menu item, without the need to click it. This is the case for an ordinary menu, but not for a toolbar menu. To implement that functionality for a toolbar menu, you have to code it yourself. These examples implements that functionality. The toolbar menu can be custom drawn, to look like an ordinary menu. You have to click a top menu item once, to open the first drop down menu. The toolbar can contain other controls in addition to the menu. And it can be used in a rebar. When the window is resized, the arrows and menu are aligned to the left border. The search box and icon are aligned to the right border. This means, that it's the gap between the two parts of the rebar, that is resized. The first version of the examples was created autumn 2013 with AutoIt 3.3.8. These examples are not running under 3.3.10. This is an update for 3.3.10. Update 2014-05-04: AutoIt 3.3.10 All the examples in this update are based on a rebar. The code is optimized, and there are several bug fixes. This is a list of the examples: ToolbarReBar1.au3 - just a toolbar menu and a search box ToolbarReBar2.au3 - the example in the picture ToolbarReBar3.au3 - the right arrow is moved to the right side of the menu ToolbarReBar4.au3 - the top menu items (not custom drawn) are provided with an icon ToolbarReBar5.au3 - same as 4 but the top menu items are custom drawn ToolbarReBar6.au3 - the top menu buttons are split buttons ToolbarReBar7.au3 - added 4 buttons on the right side of the menu ToolbarReBar8.au3 - same as 7 but the 4 buttons can be replaced dynamically ToolbarReBar9.au3 - the drop down menus are replaced with custom controls The buttons in a toolbar are often used to open a drop down menu. Example 9 shows how the buttons can be used to open various controls. The buttons are still hot-track enabled. This is a picture of example 9: HotToolbar3.3.10.7z Testet on XP 32 bit and Win 7 32/64 bit. First version october 2013: AutoIt 3.3.8 Spoiler There are five examples in the zip below. The first example is a standard toolbar menu without hot-tracking and without custom drawing. In the second example hot-tracking is added. Custom drawing is added in the third example. The arrow keys can be used in these three examples. In the third example the mouse cursor should not be positioned on the toolbar, when the arrow keys are used. The last two examples are rebars with a toolbar menu band and a search band. The picture shows the fifth example. For about two weeks ago there was a question about this topic in one of the support forums. There was a picture that looked like this picture. I've tried to look for the case, but I have not found it. Nor have I spent much time looking. Minor update 2013-10-06 Added $WS_CLIPCHILDREN style to all GUIs. The GUIs looks much better while resizing. Added an empty band between the toolbar band and the search band in the two rebar examples. This creates a separator after the last toolbar button and ensures that the search band is right aligned. Hot-tracking _GUICtrlMenu_TrackPopupMenu is used to show the menu items when a toolbar button is clicked. Because this is a modal (blocking) function it's necessary to use a message hook to receive menu messages which are used to implement hot-tracking: $hMenuMsgFilter = DllCallbackRegister( "MenuMsgFilter", "long", "int;wparam;lparam" ) $hHook = _WinAPI_SetWindowsHookEx( $WH_MSGFILTER, DllCallbackGetPtr( $hMenuMsgFilter ), 0, _WinAPI_GetCurrentThreadId() ) When the drop down menu disappears the message hook is deleted. MenuMsgFilter function: Func MenuMsgFilter( $nCode, $wParam, $lParam ) If $nCode = $MSGF_MENU Then $tMSG = DllStructCreate( $tagMSG, $lParam ) If MenuMsg() Then Return True ; If the message is handled by MenuMsg() then return True Else ; In all other cases send the message to the next hook Return _WinAPI_CallNextHookEx( 0, $nCode, $wParam, $lParam ) EndIf Else Return _WinAPI_CallNextHookEx( 0, $nCode, $wParam, $lParam ) EndIf EndFunc MenuMsg function: expandcollapse popupFunc MenuMsg() Local $iMsg, $vKey, $tPoint, $iButton $iMsg = DllStructGetData( $tMSG, "message" ) Switch $iMsg ; --- Arrow keys --- Case $WM_KEYDOWN $vKey = DllStructGetData( $tMSG, "wParam" ) Switch $vKey Case $VK_LEFT _WinAPI_PostMessage( $hToolbar, $WM_CANCELMODE, 0, 0 ) ; Don't send this message to the Toolbar _WinAPI_PostMessage( $hToolbar, $WM_KEYDOWN, $VK_LEFT, 1 ) ; Send the following messages to the Toolbar _WinAPI_PostMessage( $hToolbar, $WM_KEYUP, $VK_LEFT, 1 ) _WinAPI_PostMessage( $hToolbar, $WM_KEYDOWN, $VK_DOWN, 1 ) _WinAPI_PostMessage( $hToolbar, $WM_KEYUP, $VK_DOWN, 1 ) Return True Case $VK_RIGHT _WinAPI_PostMessage( $hToolbar, $WM_CANCELMODE, 0, 0 ) ; Don't send this message to the Toolbar _WinAPI_PostMessage( $hToolbar, $WM_KEYDOWN, $VK_RIGHT, 1 ) ; Send the following messages to the Toolbar _WinAPI_PostMessage( $hToolbar, $WM_KEYUP, $VK_RIGHT, 1 ) _WinAPI_PostMessage( $hToolbar, $WM_KEYDOWN, $VK_DOWN, 1 ) _WinAPI_PostMessage( $hToolbar, $WM_KEYUP, $VK_DOWN, 1 ) Return True EndSwitch ; --- Mouse --- Case $WM_MOUSEMOVE, $WM_LBUTTONDOWN ; Mouse screen coordinates $tPoint = DllStructCreate("int X;int Y") DllStructSetData( $tPoint, "X", DllStructGetData( $tMSG, "X" ) ) DllStructSetData( $tPoint, "Y", DllStructGetData( $tMSG, "Y" ) ) ; Convert to client coordinates _WinAPI_ScreenToClient( $hGui, $tPoint ) ; Get toolbar button index ; $iButton < 0 if not mouse cursor is over a toolbar button $iButton = _GUICtrlToolbar_HitTest( $hToolbar, DllStructGetData( $tPoint, "X" ), DllStructGetData( $tPoint, "Y" ) ) If $iMsg = $WM_MOUSEMOVE Then If $iButton >= 0 And $iButton <> $iToolbarButtonLast Then _WinAPI_PostMessage( $hToolbar, $WM_CANCELMODE, 0, 0 ) ; Don't send this message to the Toolbar _GUICtrlToolbar_ClickIndex( $hToolbar, $iButton, "left", False, 2 ) Return True EndIf ElseIf $iMsg = $WM_LBUTTONDOWN Then If $iButton >= 0 And $iButton = $iToolbarButtonLast Then _WinAPI_PostMessage( $hToolbar, $WM_CANCELMODE, 0, 0 ) ; Don't send this message to the Toolbar Return True EndIf EndIf ; --- Custom draw --- Case Else If $bDropDownMenuNew Then ; Set the Hot-Track state of the Toolbar button ; Necessary to use custom drawing (If $uItemState = $CDIS_HOT Then) ; Mouse screen coordinates $tPoint = DllStructCreate("int X;int Y") DllStructSetData( $tPoint, "X", DllStructGetData( $tMSG, "X" ) ) DllStructSetData( $tPoint, "Y", DllStructGetData( $tMSG, "Y" ) ) ; Convert to client coordinates _WinAPI_ScreenToClient( $hGui, $tPoint ) ; Get toolbar button index ; $iButton < 0 if not mouse cursor is over a toolbar button $iButton = _GUICtrlToolbar_HitTest( $hToolbar, DllStructGetData( $tPoint, "X" ), DllStructGetData( $tPoint, "Y" ) ) If $iButton >= 0 Then _GUICtrlToolbar_SetHotItem( $hToolbar, $iButton ) $bDropDownMenuNew = False Return True EndIf Else Return False EndIf EndSwitch Return False EndFunc The last part of the function is only used to handle custom draw. In examples without custom draw this part of the function is deleted. Custom draw NM_CUSTOMDRAW notifications are contained in WM_NOTIFY messages. This is the code to implement custom draw (copied from the fifth example): Case $NM_CUSTOMDRAW Local $tNMTBCUSTOMDRAW = DllStructCreate( $tagNMTBCUSTOMDRAW, $ilParam ) Local $dwDrawStage = DllStructGetData( $tNMTBCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the Toolbar paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting a Toolbar menu item Local $dwItemSpec = DllStructGetData( $tNMTBCUSTOMDRAW, "dwItemSpec" ) ; Command identifier If $dwItemSpec < $idMenu1 Then Return $CDRF_DODEFAULT ; Menu items only Local $uItemState = DllStructGetData( $tNMTBCUSTOMDRAW, "uItemState" ) ; Item state If $uItemState = $CDIS_HOT Then ; Hot-Item DllStructSetData( $tNMTBCUSTOMDRAW, "clrHighlightHotTrack", 0xCC6600 ) ; Hot-Track color, BGR DllStructSetData( $tNMTBCUSTOMDRAW, "clrText", 0xFFFFFF ) ; Forecolor, white Return BitOR( $TBCDRF_HILITEHOTTRACK, $TBCDRF_USECDCOLORS ) ; $TBCDRF_HILITEHOTTRACK must be returned to set Hot-Track color EndIf ; $TBCDRF_USECDCOLORS necessary for Vista and higher Return $CDRF_DODEFAULT ; Default colors for other menu items Case Else Return $CDRF_DODEFAULT ; Always return a value to the parent window EndSwitch Information and documentation How to Create an Internet Explorer-Style Menu Bar Changing fonts and colors Custom Draw Toolbar UDFs APIConstants.au3 and WinAPIEx.au3 by Yashied. The UDFs are included in the zip (cause of size). Zipfile The zip contains a few files and folders: Toolbar.au3 - standard toolbar menu ToolbarHot.au3 - with hot-tracking ToolbarHotDrawn.au3 - with custom draw ToolbarReBar1.au3 - first rebar example ToolbarReBar2.au3 - second rebar example (picture) icons - icons for ToolbarReBar2.au3 include - include files HotToolbar.7z Minor update 2013-10-06: HotToolbar2.7z Testet on XP 32 bit and Win 7 32/64 bit. If you are on XP and have issues with the ReBar examples take a look at post #4 below. Edited December 8, 2019 by LarsJ New image links mLipok, JohnOne, KaFu and 3 others 6 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
ldub Posted October 4, 2013 Share Posted October 4, 2013 Doesn't work for me (Win XP SP3), nothing happens ! Link to comment Share on other sites More sharing options...
wakillon Posted October 4, 2013 Share Posted October 4, 2013 Works well for me, on win7 x64 AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
LarsJ Posted October 4, 2013 Author Share Posted October 4, 2013 (edited) ldub, What do you mean by nothing happens? Do you see a window? Do you get any errors? Does nothing happen in any of the examples? There are five examples. It works for me on XP SP3 and with AutoIt 3.3.8.1. Have you extracted everything from the zip to the same folder? And of course you have to click a toolbar button once to expand the first dropdown menu like an ordinary menu.ldub, Now I remember and understand. Take a look at this thread. I have added post #6 myself. The issue in this thread only regards ReBar controls. If the examples without ReBars (ToolbarHot.au3 and ToolbarHotDrawn.au3) works but the two ReBar examples doesn't work you probably need a new version of StructureConstants.au3.Rename the existing StructureConstants.au3 in the Include folder of your AutoIt installation to StructureConstants-a.au3 and then install the new version in this zip:StructureConstants.7zldub, Thank you for pointing this out.I have made a test with the wrong version of StructureConstants.au3. The second reband with the searchbox is completely missing.Good to see wakillon. Thank you. Edited October 5, 2013 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
JohnOne Posted October 4, 2013 Share Posted October 4, 2013 Nice! Works great, win 7 32 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
LarsJ Posted October 5, 2013 Author Share Posted October 5, 2013 If you are on XP and have issues with the ReBar examples take a look at post #4 above.Thank you JohnOne. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
ldub Posted October 5, 2013 Share Posted October 5, 2013 I have replaced my StructureConstants.au3 with the new one in post #4. Works fine now. Thank's LarsJ Link to comment Share on other sites More sharing options...
LarsJ Posted October 5, 2013 Author Share Posted October 5, 2013 (edited) Excellent ldub. And thank you. I would never have thought about this issue with $tagREBARBANDINFO in StructureConstants.au3 without your comment. On my XP I fixed the problem january 2012. And forgot all about it. That's why I didn't notice the problem on my own PC. Edited October 5, 2013 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted October 6, 2013 Author Share Posted October 6, 2013 Minor update. See first post. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted May 4, 2014 Author Share Posted May 4, 2014 3.3.10 update. New examples. Optimized code. Several bug fixes. See first post. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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