AndyS01 Posted September 15, 2011 Share Posted September 15, 2011 I have a button that has a context menu attached to it using GUICtrlCreateContextMenu() but I cannot figure out how to add a little black triangle to the right of the text to indicate that clicking on the button will bring up a menu. Here is my sample code:expandcollapse popup#include <GUIConstants.au3> Opt("GUIOnEventMode", 1) GUICreate("", 200, 200, 200, 200) $button = GUICtrlCreateButton('context', 1, 1, 50, 25) GUICtrlSetOnEvent(-1, 'handle_context_btn') $context = GUICtrlCreateContextMenu($button) GUICtrlCreateMenuItem('Sub Menu 1', $context) GUICtrlSetOnEvent(-1, "handle_SubMenu1_click") GUICtrlCreateMenuItem('Exit', $context) GUICtrlSetOnEvent(-1, "handle_Exit_click") GUICtrlCreateButton('close', 1, 30, 50, 25) GUICtrlSetOnEvent(-1, 'handle_close_btn') GUISetState() While 1 Sleep(10) WEnd Func handle_close_btn() Exit EndFunc Func handle_Exit_click() Exit EndFunc Func handle_context_btn() MouseClick('right') EndFunc Func handle_SubMenu1_click() ConsoleWrite("+++: SubMenu1 pressed" & @CRLF) EndFunc Func handle_SubMenu2_click() ConsoleWrite("+++: SubMenu2 pressed" & @CRLF) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 16, 2011 Moderators Share Posted September 16, 2011 AndyS01, You need the $BS_SPLITBUTTON style to get the "menu" arrow on the button - I think it is Vista+ only. All is explained in this thread. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AndyS01 Posted September 17, 2011 Author Share Posted September 17, 2011 Thank you for the link. I added this to my test code and got the display I wanted. However, I have a problem with the notification. If I left click on the left half of the button, I get the notification and in the handler, I simulate a right mouse button click and the drop down menu is displayed. If I left click on the right side (the black triangle), I don't get any notification. Is there a way to register a handler for the right side of the button? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 17, 2011 Moderators Share Posted September 17, 2011 AndyS01,I do not understand your problem - why are you simulating right clicks in the handler? Here is the simplest script I can produce for you to test a split button. Left clicking on the button should give you "Button Pressed" in the SciTE console - left clicking on the arrow should bring up the menu and selecting the one available item should give you "Split Menu" instead. No need for any right click simulation and the menu only appears when you left click the arrow: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> Opt("MustDeclareVars", 1) Global $btn, $iMemo, $btn2 _Main() Func _Main() GUICreate("Buttons", 400, 400) $btn = GUICtrlCreateButton("Split Button", 10, 10, 120, 30, $BS_SPLITBUTTON) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn ConsoleWrite("Button Pressed" & @CRLF) EndSwitch WEnd EndFunc ;==>_Main Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam) Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code") Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom") Switch $nNotifyCode Case $BCN_DROPDOWN _Popup_Menu($hCtrl) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _Popup_Menu($hCtrl) Local $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Split Menu", 1000) Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2) Case 1000 ConsoleWrite("Split Menu" & @CRLF) EndSwitch _GUICtrlMenu_DestroyMenu($hMenu) EndFunc ;==>_Popup_MenuDo you get the same result? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AndyS01 Posted September 17, 2011 Author Share Posted September 17, 2011 That worked great! Thank you. Link to comment Share on other sites More sharing options...
AndyS01 Posted September 26, 2011 Author Share Posted September 26, 2011 Oh-Oh, it doesn't work on XP systems. I wrote conditional code, so the buttons are normal on the XP machine and are split buttons on Windows 7 and Vista. So I still need to do something on the XP machine to indicate that the buttons have a drop down menu. I'm sure this must have been done by someone. If ($flags <> -1) And (BitAND($flags, $BS_SPLITBUTTON)) Then If (StringInStr(@OSVersion, "XP")) Then $flags = BitAND($flags, BitNOT($BS_SPLITBUTTON)) EndIf EndIf Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 26, 2011 Moderators Share Posted September 26, 2011 AndyS01,I did mention I thought it was Vista+. What about this as an alternative for XP: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIMenu.au3> Global Enum $idOpen = 1000, $idSave, $idInfo $hGUI = GUICreate("Test", 500, 500) $hButton = GUICtrlCreateButton("XP Split", 10, 10, 60, 30) $hSplit = GUICtrlCreateButton("6", 69, 10, 20, 30) GUICtrlSetFont(-1, 10, 400, 0, "Webdings") $hContextMenu = GUICtrlCreateContextMenu($hSplit) $hContextHandle = GUICtrlGetHandle($hContextMenu) GUICtrlCreateMenuItem("Open", $hContextMenu) GUICtrlCreateMenuItem("Save", $hContextMenu) GUICtrlCreateMenuItem("", $hContextMenu) ; separator GUICtrlCreateMenuItem("Info", $hContextMenu) GUISetState() GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton ConsoleWrite("Button Pressed" & @CRLF) Case $hSplit ; Show the menu for a left click on the button _Menu() EndSwitch WEnd Func _Menu() $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $idInfo) _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) _GUICtrlMenu_DestroyMenu($hMenu) EndFunc Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ; If the context menu was fired by a right click on the Split button then do nothing If $wParam = GUICtrlGetHandle($hSplit) Then Return True EndIf EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch $wParam Case $idOpen ConsoleWrite("Open" & @CRLF) Case $idSave ConsoleWrite("Save" & @CRLF) Case $idInfo ConsoleWrite("Info" & @CRLF) EndSwitch EndFunc ;==>WM_COMMANDThis way you get the context menu appearing only for a left click on the "split" button - right clicking does not fire it. Not as sexy as the full $BS_SPLITBUTTON version, but XP users will not feel too deprived! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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