Jump to content

Change title bar Color [XP]


Recommended Posts

Hi

Yeah, Greenhorn you're rigth..

@Gary: (Sorry, i now, you are not a color^^)

Yes, the inMenu is colored, like this: http://www.autoitscript.com/forum/index.ph...;hl=color++menu

But the Gray (not you^^) Top Menu isnt colored :P I have already installed the Beta. (3.2.11.0)

Thank you for Replies :D

Mfg / BEst regards sPider

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiMenu.au3>

Global Const $COLOR_ACTIVECAPTION = 2
Global Const $COLOR_GRADIENTACTIVECAPTION = 27

_Main()

Func _Main()
    Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]
    ; Red and Yellow
    Local $aColors[2] = [255, 65535], $aSaveColors[2]
   
    $hGui = GUICreate("My GUI", 300, 200)

    $FileMenu = GUICtrlCreateMenu("&File")
    $OpenItem = GUICtrlCreateMenuItem("&Open", $FileMenu)
    $SaveItem = GUICtrlCreateMenuItem("&Save", $FileMenu)
    GUICtrlCreateMenuItem("", $FileMenu)

    $OptionsMenu = GUICtrlCreateMenu("O&ptions", $FileMenu)
    $ViewItem = GUICtrlCreateMenuItem("View", $OptionsMenu)
    GUICtrlCreateMenuItem("", $OptionsMenu)
    $ToolsItem = GUICtrlCreateMenuItem("Tools", $OptionsMenu)

    GUICtrlCreateMenuItem("", $FileMenu)
    $ExitItem = GUICtrlCreateMenuItem("&Exit", $FileMenu)

    $HelpMenu = GUICtrlCreateMenu("&?")
    $AboutItem = GUICtrlCreateMenuItem("&About", $HelpMenu)

    $EndBtn = GUICtrlCreateButton("End", 110, 140, 70, 20)

    ; Minimum OS are Windows98 and 2000
    If @OSVersion <> "WIN_95" And @OSVersion <> "WIN_NT4" Then
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($FileMenu), _WinAPI_CreateSolidBrush(0xEEBB99))
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($OptionsMenu), _WinAPI_CreateSolidBrush(0x66BB99))
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($HelpMenu), _WinAPI_CreateSolidBrush(0x99BBEE))
          $hmenu = _GUICtrlMenu_GetMenu($hGui)
        _GUICtrlMenu_SetMenuBackground($hmenu, _WinAPI_CreateSolidBrush(65280))
    EndIf

    $aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)
    $aSaveColors[1] = _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)

    _WinAPI_SetSysColors($aElements, $aColors)

    GUISetState()

    While 1
        $Msg = GUIGetMsg()

        Switch $Msg
            Case $EndBtn, $GUI_EVENT_CLOSE
                ExitLoop

            Case $AboutItem
                MsgBox(64, "About...", "Colored menu sample")
        EndSwitch
    WEnd

    GUIDelete()
   
    _WinAPI_SetSysColors($aElements, $aSaveColors)

    Exit

EndFunc   ;==>_Main

Func _WinAPI_SetSysColors($vElements, $vColors)
    Local $isEArray = IsArray($vElements), $isCArray = IsArray($vColors)
    Local $iElementNum
   
    If Not $isCArray And Not $isEArray Then
        $iElementNum = 1
    ElseIf $isCArray Or $isEArray Then
        If Not $isCArray Or Not $isEArray Then Return SetError(-1, -1, False)
        If UBound($vElements) <> UBound($vColors) Then Return SetError(-1, -1, False)
        $iElementNum = UBound($vElements)
    EndIf
   
    Local $tElements = DllStructCreate("int Element[" & $iElementNum & "]")
    Local $tColors = DllStructCreate("int NewColor[" & $iElementNum & "]")
    Local $pElements = DllStructGetPtr($tElements)
    Local $pColors = DllStructGetPtr($tColors)


    If Not $isEArray Then
        DllStructSetData($tElements, "Element", $vElements, 1)
    Else
        For $x = 0 To $iElementNum - 1
            DllStructSetData($tElements, "Element", $vElements[$x], $x + 1)
        Next
    EndIf

    If Not $isCArray Then
        DllStructSetData($tColors, "NewColor", $vColors, 1)
    Else
        For $x = 0 To $iElementNum - 1
            DllStructSetData($tColors, "NewColor", $vColors[$x], $x + 1)
        Next
    EndIf
    Local $iResults = DllCall("user32.dll", "int", "SetSysColors", "int", $iElementNum, "ptr", $pElements, "ptr", $pColors)
    If @error Then Return SetError(-1, -1, False)
    Return $iResults[0] <> 0
EndFunc   ;==>_WinAPI_SetSysColors

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hi

Gary, you are my GOD!! Thank you very much, you are amazing!

But now i've an other Problem.. I'll change the Position and width of the Menu. No Problem, with $WS_POPUP and RegisterMsg $WM_MOVE.

But if I move the MainGUI, the ChildGUI will be disabled, and the Menu grayout :D

Here is the Example code:

#include <WindowsConstants.au3>
#include <misc.au3>
#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>

;Main GUI wird erstellt
$hGui = GUICreate("My GUI", 300, 200)

;Menü färben button
$MenuColBtn = GUICtrlCreateButton("Menü Färben", 110, 140, 70, 20)
GUISetState()

$aWgp = WinGetPos($hGUI)



$hChildGUI = GUICreate("",200,25,$aWgp[0]+40,$aWgp[1]+40,$WS_POPUP,$WS_EX_TOOLWINDOW,$hGui)
;Menüs werden erstellt
$FileMenu = GUICtrlCreateMenu("&Datei")
$OpenItem = GUICtrlCreateMenuItem("&Öffnen", $FileMenu)
$SaveItem = GUICtrlCreateMenuItem("&Speichern", $FileMenu)
GUICtrlCreateMenuItem("", $FileMenu)

$OptionsMenu = GUICtrlCreateMenu("O&ptionen", $FileMenu)
$ViewItem = GUICtrlCreateMenuItem("Aussehen", $OptionsMenu)
GUICtrlCreateMenuItem("", $OptionsMenu)
$ToolsItem = GUICtrlCreateMenuItem("Tools", $OptionsMenu)

GUICtrlCreateMenuItem("", $FileMenu)
$ExitItem = GUICtrlCreateMenuItem("&Exit", $FileMenu)

$HelpMenu = GUICtrlCreateMenu("&?")
$AboutItem = GUICtrlCreateMenuItem("&About", $HelpMenu)

;GUI wird gezeigt
_SetColorOfMenu(0xbbbb)
GUISetState()

GUIRegisterMsg($WM_MOVE, "WM_MOVE")

While 1
    Switch GUIGetMsg()
        Case - 3
            ExitLoop
        Case $MenuColBtn
            $clr = _ChooseColor()
            If @error Then ContinueLoop
            _SetColorOfMenu($clr)
        Case $AboutItem
            MsgBox(64, "About...", "")
    EndSwitch
WEnd

Func _SetColorOfMenu($hColor)
    If @OSVersion <> "WIN_95"  And @OSVersion <> "WIN_NT4"  Then
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($FileMenu), _WinAPI_CreateSolidBrush($hColor))
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($OptionsMenu), _WinAPI_CreateSolidBrush($hColor - 0x002200))
        _GUICtrlMenu_SetMenuBackground(GUICtrlGetHandle($HelpMenu), _WinAPI_CreateSolidBrush($hColor))
        $hmenu = _GUICtrlMenu_GetMenu($hChildGUI)
        _GUICtrlMenu_SetMenuBackground($hmenu, _WinAPI_CreateSolidBrush($hColor))
        GUISwitch($hChildGUI)
        GUISetState(@SW_HIDE)
        GUISetState()
        Return 1
    EndIf
    Return 0
EndFunc   ;==>_SetColorOfMenu

Func WM_MOVE($hWndGUI)
    If $hWndGUI <> $hGUI Then Return $GUI_RUNDEFMSG
    Local $aWgp = WinGetPos($hWndGUI)
    WinMove($hChildGUI, "", $aWgp[0]+40, $aWgp[1]+40)
EndFunc

I hope someone can help me (Sorry for my exotic questions^^)

Mfg / Best Regards Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

No one an idea? Im also lucky about other Resulotions.

I want only change the menu width and the menu pos..

Mfg / Best Regarz Spider

Func WM_MOVE($hWndGUI)
    If $hWndGUI <> $hGUI Then Return $GUI_RUNDEFMSG
    Local $aWgp = WinGetPos($hWndGUI)
    WinMove($hChildGUI, "", $aWgp[0]+40, $aWgp[1]+40)
    WinActivate($hChildGUI)
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hello

thank you for posting, but it doesnt work..

Main problem is, that the GUI Lagging extremely..

Second problem is, that the MainGUI isnt active..

I'll that both guis are Enabled :P

Or have you an other solution to change the Width and the position of the Menu?

Thank you for your comments :D

Mfg / Best Regadz Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Hello

thank you for posting, but it doesnt work..

Main problem is, that the GUI Lagging extremely..

Second problem is, that the MainGUI isnt active..

I'll that both guis are Enabled :P

Or have you an other solution to change the Width and the position of the Menu?

Thank you for your comments :D

Mfg / Best Regadz Spider

The reason it grays out is because you can only have 1 window/gui active at a time, the grayed menu is because that gui isn't the active gui/window.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I found several examples where the titlebar is customized (color, bitmap, gradient etc):

codeguru

Custom title bars

Win32 tips and tricks

The way they go is to intercept WM_NCPAINT and draw on the title bar area.

case WM_NCPAINT:
{
    HDC hdc;
    hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
    // Paint into this DC
    ReleaseDC(hwnd, hdc);
}

for painting:

void PaintRect(HDC hdc, RECT *rect, COLORREF colour)
{
    COLORREF oldcr = SetBkColor(hdc, colour);
    ExtTextOut(hdc, 0, 0, ETO_OPAQUE, rect, "", 0, 0);
    SetBkColor(hdc, oldcr);
}

Perhaps the experts can translate this to AutoIt code.

There are many examples floating around in other programming languages, look for WM_NCPAINT and 'title bar'.

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