Menü überall platzieren

  • Hallo!

    Hab in der Hilfe eine Funktion gefunden, mittels derer man ein (Kontext-)Menü an beliebiger Stelle aufrufen kann. Hab das ganze gleich mal zweckentfremdet ;)

    Spoiler anzeigen
    [autoit]

    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGui = GUICreate("Mein eigenes Menü", 270, 140, -1, -1);, 0x80000000)
    GUISetOnEvent(-3, '_Exit')

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('Das Menü befindet sich unterhalb ;)', 50, 15)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('', 0, 48, 270, 2, 0x1000)

    [/autoit] [autoit][/autoit] [autoit]

    $MenueDatei = GUICtrlCreateLabel('&Datei', 95, 50, 40, 19, 0x201)
    GUICtrlSetOnEvent(-1, '_MenuPressed')

    [/autoit] [autoit][/autoit] [autoit]

    $DateiContext = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
    $OptionsOpen = GUICtrlCreateMenuItem("Ö&ffnen", $DateiContext)
    $OptionsClose = GUICtrlCreateMenuItem("S&chließen", $DateiContext)
    GUICtrlCreateMenuItem("", $DateiContext)
    $OptionsExit = GUICtrlCreateMenuItem("B&eenden", $DateiContext)
    GUICtrlSetOnEvent(-1, '_Exit')

    [/autoit] [autoit][/autoit] [autoit]

    $MenueHelp = GUICtrlCreateLabel("&Hilfe", 135, 50, 30, 19, 0x201)
    GUICtrlSetOnEvent(-1, '_MenuPressed')

    [/autoit] [autoit][/autoit] [autoit]

    $HelpContext = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
    $HelpWWW = GUICtrlCreateMenuItem("&Website", $HelpContext)
    GUICtrlSetOnEvent(-1, '_Website')
    GUICtrlCreateMenuItem("", $HelpContext)
    $HelpAbout = GUICtrlCreateMenuItem("Ü&ber...", $HelpContext)
    GUICtrlSetOnEvent(-1, '_About')

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('', 0, 70, 270, 2, 0x1000)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Global $AccelKeys[2][2]=[["!d", $MenueDatei], ["!h", $MenueHelp]]
    GUISetAccelerators($AccelKeys)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _MenuPressed()
    Switch @GUI_CtrlId
    Case $MenueDatei
    ShowMenu($hGui, $MenueDatei, $DateiContext)
    Case $MenueHelp
    ShowMenu($hGui, $MenueHelp, $HelpContext)
    EndSwitch
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _About()
    MsgBox(64, "About...", "Beispiel für ein eigenes Menü")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Website()
    MsgBox(64, "Website...", "www.autoit.de")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; Show a menu in a given GUI window which belongs to a given GUI ctrl
    Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)

    $arPos = ControlGetPos($hWnd, "", $CtrlID)

    $x = $arPos[0]
    $y = $arPos[1] + $arPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
    EndFunc ;==>ShowMenu

    [/autoit] [autoit][/autoit] [autoit]

    ; 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)

    [/autoit] [autoit][/autoit] [autoit]

    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 ;==>ClientToScreen

    [/autoit] [autoit][/autoit] [autoit]

    ; 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 ;==>TrackPopupMenu

    [/autoit]
    • Offizieller Beitrag

    Find ich Super das Script. :thumbup: Werde ich mal archivieren. ;)

  • Wenn man die Position ändern kann, kann man da auch dem menu eine Farbe zu teilen?
    also meine jetzt nich die menü unterpunkte

  • [autoit]

    Func SetMenuColor($nMenuID, $nColor)
    Local $hMenu, $hBrush, $stMenuInfo
    Local Const $MIM_APPLYTOSUBMENUS = 0x80000000
    Local Const $MIM_BACKGROUND = 0x00000002

    $hMenu = GUICtrlGetHandle($nMenuID)

    $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
    $hBrush = $hBrush[0]

    $stMenuInfo = DllStructCreate("dword;dword;dword;uint;dword;dword;ptr")
    DllStructSetData($stMenuInfo, 1, DllStructGetSize($stMenuInfo))
    DllStructSetData($stMenuInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND))
    DllStructSetData($stMenuInfo, 5, $hBrush)

    DllCall("user32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "ptr", DllStructGetPtr($stMenuInfo))

    ; release Struct not really needed as it is a local
    $stMenuInfo = 0
    EndFunc ;==>SetMenuColor

    [/autoit]
  • Sry, dass ich den Thread auswühl, wollt aber keinen neuen machen. Also, ich hab mein Skript für meinen MusikPlayer und das Menü soll angezeigt werden, wenn man auf ein Label klickt. Wie oben also. Wenn ich das ganze aber in mein Skript einbaue passiert einfach nix, ich hoff ihr könnt mir helfen ;D Skript is in der Rar, geht leider nur so, das ihr die Bilder braucht, damits geht.
    Download: Klick mich!