Jump to content

How can I create a Ribbon Menu


Tiger
 Share

Recommended Posts

I would like to create a menu in the round button. I have a example in the attachment

The Code

Opt("GUIOnEventMode", 1)
#include <GUIConstants.au3>
GUICreate("", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$icon = GUICtrlCreateIcon("restart.ico", -1, 0, 0, 32, 32)
GUICtrlCreateMenuItem("Icon", $icon)
GUISetState(@SW_SHOW)
Func _close()
    Exit
EndFunc   ;==>_close
While 1 
    Sleep(250)
WEnd

post-21671-1218464065_thumb.jpg

My UDFs:- _RegEnumKey
Link to comment
Share on other sites

Hey Tiger.

Maybe what you want is a context menu for the control ...

GUICtrlCreateContextMenu ( [controlID] )

As far as I know, this is the only type of menu you can make for the little green button.

Edit 1: Correction - it wouldn't be simple, but you could make another window you built to appear when the mouse is hovering over the little green thing, and that window could be without a title bar and contain have only clickable label controls.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Thanks but there is still no menuitem under the green icon

Opt("GUIOnEventMode", 1)
#include <GUIConstants.au3>
$gui = GUICreate("", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$ribbon = GUICtrlCreateIcon("restart.ico", -1, 0, 0, 32, 32, $BS_FLAT)
GUICtrlSetOnEvent(-1, "_ribbon")
$ribbondummy = GUICtrlCreateDummy()
$ribboncontext = GUICtrlCreateContextMenu($ribbondummy)
$ribbonexit = GUICtrlCreateMenuItem("Exit", $ribboncontext)

GUISetState(@SW_SHOW)

Func _ribbon()
    
    ShowMenu($gui, $ribbon, $ribboncontext)
    
EndFunc   ;==>_ribbon

Func _close()
    Exit
EndFunc   ;==>_close

; 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

While 1 
    Sleep(250)
WEnd
My UDFs:- _RegEnumKey
Link to comment
Share on other sites

  • Developers

You need to tell the GUI to fire a message for a ICO control:

$ribbon = GUICtrlCreateIcon("restart.ico", -1, 0, 0, 32, 32, BitOR($BS_FLAT,$SS_NOTIFY))

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...