Sign in to follow this  
Followers 0
nend

Colourtray back to normal

3 posts in this topic

I found this in the help file (to set colour to the traymenu).

It works perfect but I want it on the fly (without shutting down te programm) to set it back to normal.

Is there a way to do that?

#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)
    $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

Share this post


Link to post
Share on other sites



nend,

Just reset the colours to the original, which you can find using _WinAPI_GetSysColor:

#include <Constants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.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("")
$ResetItem      = TrayCreateItem("Reset")
TrayCreateItem("")
$ExitItem       = TrayCreateItem("Exit Sample")

$iOrg_MenuColour = _WinAPI_GetSysColor($COLOR_MENU)

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

        Case $ResetItem
            SetMenuColor(0, $iOrg_MenuColour)
            SetMenuColor($OptionsMenu, $iOrg_MenuColour)

    EndSwitch
WEnd

Exit

; Apply the color to the menu
Func SetMenuColor($nMenuID, $nColor)
    $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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Yep!! that's wat I'm looking for, Thanks for the help.

nend,

Just reset the colours to the original, which you can find using _WinAPI_GetSysColor:

#include <Constants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.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("")
$ResetItem      = TrayCreateItem("Reset")
TrayCreateItem("")
$ExitItem       = TrayCreateItem("Exit Sample")

$iOrg_MenuColour = _WinAPI_GetSysColor($COLOR_MENU)

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

        Case $ResetItem
            SetMenuColor(0, $iOrg_MenuColour)
            SetMenuColor($OptionsMenu, $iOrg_MenuColour)

    EndSwitch
WEnd

Exit

; Apply the color to the menu
Func SetMenuColor($nMenuID, $nColor)
    $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

M23

Share this post


Link to post
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
Sign in to follow this  
Followers 0