Sardith Posted January 26, 2007 Share Posted January 26, 2007 expandcollapse popup#include <GUIConstants.au3> $hGui = GUICreate("My GUI", 170, 40) $OptionsBtn = GUICtrlCreateButton("&Options", 10, 10, 70, 20, $BS_FLAT) ; At first create a dummy control for the options and a contextmenu for it $OptionsDummy = GUICtrlCreateDummy() $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy) $OptionsCommon = GUICtrlCreateMenuItem("Common", $OptionsContext) $OptionsFile = GUICtrlCreateMenuItem("File", $OptionsContext) GUICtrlCreateMenuItem("", $OptionsContext) $OptionsExit = GUICtrlCreateMenuItem("Exit", $OptionsContext) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $OptionsExit, $GUI_EVENT_CLOSE ExitLoop Case $OptionsBtn ShowMenu($hGui, $Msg, $OptionsContext) EndSwitch WEnd Exit ; Show a menu in a given GUI window which belongs to a given GUI ctrl Func ShowMenu($hWnd, $CtrlID, $nContextID) Local $hMenu = GUICtrlGetHandle($nContextID) $arPos = ControlGetPos($hWnd, "", $CtrlID) Local $x = $arPos[0] Local $y = $arPos[1] + $arPos[3] ClientToScreen($hWnd, $x, $y) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc ; Convert the client (GUI) coordinates to screen (desktop) coordinates Func ClientToScreen($hWnd, ByRef $x, ByRef $y) Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) ; release Struct not really needed as it is a local $stPoint = 0 EndFunc ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd) Func TrackPopupMenu($hWnd, $hMenu, $x, $y) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc Not much Experiance with Gui's, a simple drop down menu like when you go file. Is there a way to make a button transparent/flat like that? Or do I need to use a label, and if so how would I go about something like that. Also, a side question. Is there a way, that if you click on the drop down menu, like file and go new, that it puts a check next to it? To mark as something in use. Jeff [font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font] Link to comment Share on other sites More sharing options...
Sardith Posted January 26, 2007 Author Share Posted January 26, 2007 Labels work, but the second question. Is there anyway to put a check next to a option in the drop menu, after you've clicked it? [font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font] Link to comment Share on other sites More sharing options...
Zedna Posted January 26, 2007 Share Posted January 26, 2007 GUICtrlSetState($OptionsFile ,$GUI_CHECKED) I'm curious. Although HelpFile sais: GUICtrlSetState State of a "contextmenu" control cannot be changed.Above example works fine. Resources UDF ResourcesEx UDF AutoIt Forum Search 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