Jump to content

how I can colorize this item plz


Recommended Posts

There is a great example in the help file under TrayItemGetHandle(). It reads:

#include <Constants.au3>

Opt("TrayMenuMode", 1); Don't show the default tray context menu

Global Const $MIM_APPLYTOSUBMENUS   = 0x80000000
Global Const $MIM_BACKGROUND        = 0x00000002

TraySetIcon("shell32.dll", 21)
TraySetToolTip("This is just a small example to show that colored tray menus" & @LF & "are easy possible under Windows 2000 and higher.")

$OptionsMenu    = TrayCreateMenu("Options")
$OnTopItem    = TrayCreateItem("Always On Top", $OptionsMenu)
TrayItemSetState(-1, $TRAY_CHECKED)
$RepeatItem  = TrayCreateItem("Repeat Always", $OptionsMenu)
TrayCreateItem("")
$AboutItem    = TrayCreateItem("About")
TrayCreateItem("")
$ExitItem      = TrayCreateItem("Exit Sample")

SetMenuColor(0, 0xEEBB99)  ; BGR color value, '0' means the tray context menu handle itself
SetMenuColor($OptionsMenu, 0x66BB99); BGR color value

While 1
    $Msg = TrayGetMsg()

    Switch $Msg
        Case $ExitItem
            ExitLoop
        
        Case $AboutItem
            Msgbox(64, "About...", "Colored tray menu sample")
    EndSwitch   
WEnd

Exit


; Apply the color to the menu
Func SetMenuColor($nMenuID, $nColor)
   ; Minimum OS are Windows98 and 2000 
    If @OSVersion = "WIN_95" Or @OSVersion = "WIN_NT4" Then Return
    
    $hMenu  = TrayItemGetHandle($nMenuID); Get the internal menu handle
    
    $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
    $hBrush = $hBrush[0]
        
    Local $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))
EndFunc
Link to comment
Share on other sites

thank you but not work when I put in a gui Exemple:

#include <GUIConstants.au3>

Opt("TrayMenuMode", 1)

$Tray = TrayCreateItem("Tray")

$Show = TrayCreateItem("Show")

$ExitItem = TrayCreateItem("Exit")

$lol = GUICreate("test item", 399, 338, 193, 125,$WS_POPUP)

GUISetState(@SW_SHOW)

While 1

$Msg = GUIGetMsg()

Switch $Msg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

Edited by NewForAutoit
Link to comment
Share on other sites

Give this a shot. It doesn't look pretty, and most of it is straight from the help file, but it works:

#include <GUIConstants.au3>

Opt("TrayMenuMode", 1)
$Tray = TrayCreateItem("Tray")
$Show = TrayCreateItem("Show")
$ExitItem = TrayCreateItem("Exit")

Global Const $MIM_APPLYTOSUBMENUS   = 0x80000000
Global Const $MIM_BACKGROUND        = 0x00000002

SetMenuColor(0, 0x00FF00); <- Set your color here

While 1
    $Msg = TrayGetMsg()
    Switch $Msg
        Case $ExitItem
            Exit
    EndSwitch
WEnd

Func SetMenuColor($nMenuID, $nColor)
    If @OSVersion = "WIN_95" Or @OSVersion = "WIN_NT4" Then Return
    
    $hMenu  = TrayItemGetHandle($nMenuID)
    
    $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
    $hBrush = $hBrush[0]
        
    Local $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))
EndFunc
Edited by Vakari
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...