Jump to content

Recommended Posts

Posted (edited)

I'm aware of ModernMenu. I only want to change the color.

#include <GuiMenu.au3>
Local $iMenuItem[1]
Local $tPoint, $aPos, $a_iniList, $ContMenu

$hGui = GUICreate('My Program', 250, 260)
$iCombo = GUICtrlCreateButton('v', 220, 10, 22, 22)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $iCombo
                $ContMenu = GUICtrlCreateContextMenu($iCombo)
                SetMenuColor(-1, 0xAAFFFF)
                $a_iniList = StringSplit('item1|item2|item3|item4', '|')
                ReDim $iMenuItem[$a_iniList[0] + 1]
                $iMenuItem[0] = $a_iniList[0]
                For $i = 1 To $a_iniList[0]
                    $iMenuItem[$i] = GUICtrlCreateMenuItem($a_iniList[$i], $ContMenu)
                Next
                $aPos = ControlGetPos($hGui, "", $iCombo)
                $tPoint = DllStructCreate("int X;int Y")
                DllStructSetData($tPoint, "X", $aPos[0] + $aPos[2])
                DllStructSetData($tPoint, "Y", $aPos[1] + $aPos[3])
                _WinAPI_ClientToScreen($hGui, $tPoint)
                _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($ContMenu), $hGui, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), 2)
                $tPoint = 0
                GUICtrlDelete($ContMenu)
        Case -3
            Exit
    EndSwitch
WEnd

Func SetMenuColor($nMenuID, $nColor)
    Local $tInfo
    $tInfo = DllStructCreate($tagMENUINFO)
    DllStructSetData($tInfo, 1, DllStructGetSize($tInfo))
    DllStructSetData($tInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND))
    DllStructSetData($tInfo, 5, _WinAPI_CreateSolidBrush($nColor))
    _GUICtrlMenu_SetMenuInfo(GUICtrlGetHandle($nMenuID), $tInfo)
EndFunc   ;==>SetMenuColor
Edited by AZJIO
Posted

Look at SetMenuColor()

Opt('GUIOnEventMode', 1)

Global $hGui = GUICreate("Mein eigenes Menü", 270, 140, -1, -1);, 0x80000000)
GUISetOnEvent(-3, '_Exit')
GUISetBkColor(0x00ffff)
GUICtrlCreateLabel('Das Menü befindet sich unterhalb ;)', 50, 15)

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

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

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

$MenueHelp = GUICtrlCreateLabel("&Hilfe", 135, 50, 30, 19, 0x201)
GUICtrlSetOnEvent(-1, '_MenuPressed')
$HelpContext = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
SetMenuColor(-1, 0xffff00)
$HelpWWW = GUICtrlCreateMenuItem("&Website", $HelpContext)
GUICtrlSetOnEvent(-1, '_Website')
GUICtrlCreateMenuItem("", $HelpContext)
$HelpAbout = GUICtrlCreateMenuItem("Ü&ber...", $HelpContext)
GUICtrlSetOnEvent(-1, '_About')

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

GUISetState()

;~ ToolTip($DateiContext & @CR & $HelpContext)

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

While 1
    Sleep(10000)
WEnd

Func _Exit()
    Exit
EndFunc

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

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

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

; 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

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

; 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

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

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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
×
×
  • Create New...