Jump to content

Change Backgroundcolor of an Menu


Recommended Posts

Hi,

how do i change the background color of a Menu and the menuitems?

Regards Daniel W.

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

This may also help you get an idea.

[code

$Title = GuiCreate("Good Night Everyone", 700, 440,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

WinSetTrans($Title, "", 250)

GUISetBkColor(0x0080FF)

just use GUICrlSetBkColor or GUICtrlSetColor on the specify item.

The doc was not updated on the subject until .125. It was working since .72 ... :)

Link to comment
Share on other sites

just use GUICrlSetBkColor or GUICtrlSetColor on the specify item.

The doc was not updated on the subject until .125. It was working since .72 ... :)

Just wondering... I believe it's mentioned in the example for GUICtrlGetHandle,

which do some menu-coloring, that's coloring of menus and items doesn't work

on Windows 98 (and another OS; NT4 ?).

Do you know if that's also the case when using SetColor and SetBkColor ?

Edited by Helge
Link to comment
Share on other sites

Just wondering... I believe it's mentioned in the example for GUICtrlGetHandle,

which do some menu-coloring, that's coloring of menus and items doesn't work

on Windows 98 (and another OS; NT4 ?).

Do you know if that's also the case when using SetColor and SetBkColor ?

No Idea

Just PM to Holger to see what he say :)

Link to comment
Share on other sites

For coloring menus in Win95/NT you have to use ownerdrawn menus - see my signature.

For coloring a listbox here a small sample (beta-version needed)...

#include <GUIConstants.au3>

Global Const $WM_CTLCOLORLISTBOX    = 0x0134 

Dim $nTextClr1  = 0x00FF80  ; BGR-value
Dim $nBkClr1    = 0xDD5566  ; BGR-value
Dim $hBrush1    = 0

Dim $nTextClr2  = 0x8844FF  ; BGR-value
Dim $nBkClr2    = 0xC0F0F0  ; BGR-value
Dim $hBrush2    = 0

Dim $hGUI       = GUICreate("Test")

GUISetState()
GUIRegisterMsg($WM_CTLCOLORLISTBOX, "WM_CTLCOLORLISTBOX")

$nList1 = GUICtrlCreateList("", 10, 10, 185, 200)
GUICtrlSetData(-1, "Item1|Item2|Item3")

$nList2 = GUICtrlCreateList("", 205, 10, 185, 200)
GUICtrlSetData(-1, "Item1|Item2|Item3")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

DeleteObject($hBrush1)
DeleteObject($hBrush2)

Exit


Func WM_CTLCOLORLISTBOX($hWnd, $Msg, $wParam, $lParam)
    If $lParam = GUICtrlGetHandle($nList1) Then
        Return SetListBoxColor($wParam, $nTextClr1, $nBkClr1, $hBrush1)
    ElseIf $lParam = GUICtrlGetHandle($nList2) Then
        Return SetListBoxColor($wParam, $nTextClr2, $nBkClr2, $hBrush2)
    EndIf
EndFunc


Func SetListBoxColor($hDC, $nTextClr, $nBkColor, ByRef $hBrush)
    SetTextColor($hDC, $nTextClr)
    SetBkColor($hDC, $nBkColor)
    
    If $hBrush = 0 Then $hBrush = CreateSolidBrush($nBkColor)
    Return $hBrush
EndFunc


Func SetTextColor($hDC, $nColor)
    Local $nLastColor = DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", $nColor)
    Return $nLastColor[0]
EndFunc


Func SetBkColor($hDC, $nColor)
    Local $nLastColor = DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", $nColor)
    Return $nLastColor[0]
EndFunc


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


Func DeleteObject($hObj)
    DllCall("gdi32.dll", "int", "DeleteObject", "hwnd", $hObj)
EndFunc

So long...so less time...

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...