Jump to content

_GUICtrlMenu highlight color


KaFu
 Share

Recommended Posts

Link to comment
Share on other sites

You can do it by set general system settings:

#Include <WinAPI.au3>
#include <WindowsConstants.au3>
; $COLOR_HIGHLIGHT - Item(s) selected in a control.
; $COLOR_HIGHLIGHTTEXT - Text of item(s) selected in a control.

Local $aElements[2] = [$COLOR_HIGHLIGHT,$COLOR_HIGHLIGHTTEXT]
Local $aOldColor[2] = [_WinAPI_GetSysColor($COLOR_HIGHLIGHT),_WinAPI_GetSysColor($COLOR_HIGHLIGHTTEXT)]
Local $aNewColor[2] = [0x008000,0x00D7FF]

_WinAPI_SetSysColors($aElements, $aNewColor)

GUICreate('test', 130, 100)
GUICtrlCreateLabel('HighLight color changed.', 5, 40)
GUISetState()
Do
Until GUIGetMsg() = -3
_WinAPI_SetSysColors($aElements, $aOldColor)

Best Regards BugFix  

Link to comment
Share on other sites

Thanks for the feedback! In general this is exactly what I was looking for. For menus the highlight color is $COLOR_MENUHILIGHT. Sadly this setting is system-wide. Is there a possibility to restrict this behaviour to my own GUI only?

#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

; $COLOR_HIGHLIGHT - Item(s) selected in a control.
; $COLOR_HIGHLIGHTTEXT - Text of item(s) selected in a control.
Local $aElements[2] = [$COLOR_HIGHLIGHTTEXT,$COLOR_MENUHILIGHT]
Local $aOldColor[2] = [_WinAPI_GetSysColor($COLOR_HIGHLIGHTTEXT),_WinAPI_GetSysColor($COLOR_MENUHILIGHT)]
Local $aNewColor[2] = [0x0000FF, 0xC2EEFF]

_WinAPI_SetSysColors($aElements, $aNewColor)

Opt('MustDeclareVars', 1)

Global $iMemo
Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout

_Main()

_WinAPI_SetSysColors($aElements, $aOldColor)


Func _Main()
    Local $hGUI, $hFile, $hEdit, $hHelp, $hMain

    ; Create GUI
    $hGUI = GUICreate("Menu", 400, 300)

    ; Create File menu
    $hFile = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hFile, 0, "&New", $idNew)
    _GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave)
    _GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit)

    ; Create Edit menu
    $hEdit = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste)

    ; Create Help menu
    $hHelp = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hHelp, 0, "&About", $idAbout)

    ; Create Main menu
    $hMain = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile)
    _GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit)
    _GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp)

    ; Set window menu
    _GUICtrlMenu_SetMenu ($hGUI, $hMain)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Loop until user exits
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

; Handle menu commands
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch _WinAPI_LoWord ($iwParam)
        Case $idNew
            MemoWrite("New")
        Case $idOpen
            MemoWrite("Open")
        Case $idSave
            MemoWrite("Save")
        Case $idExit
            Exit
        Case $idCut
            MemoWrite("Cut")
        Case $idCopy
            MemoWrite("Copy")
        Case $idPaste
            MemoWrite("Paste")
        Case $idAbout
            MemoWrite("About")
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

; Write message to memo
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite
Edited by KaFu
Link to comment
Share on other sites

A workaround may be, to toggle this settings by check which window is active: yours or another one.

Thought about this one too, until I saw the language selector in my taskbar changing colors >_<... would prefer a 'permanent' solution. Already searched msdn in vain, maybe I'll do some more googling this evening :(, thanks for your feedback!
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...