Jump to content

Change title bar Color [XP]


Recommended Posts

Hi,

I've gotta prob.. i'll create a window with the default XP titlebar. But not in this blue. e.g. if there is an error happened, then the title bar should be colored red.

I don't want use XSkin or smth like this, because the program have to be little as possible.. I tough the best way is with the WinAPI or GDI+ but i dont know how.

It would be great AMAZING, if someone can help me :D

MFG / BEst Regards your Spider

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

 

Link to comment
Share on other sites

Moin Spider,

the colors of the Window frames are defiened as Bitmaps in the Theme-DLLs, so I don't know if it is possible to change/paint over the frame colors easily.

But it sounds interesting and it would make me delighted too if there is a way to do so ... :P

Has the window a fixed size ?

Then maybe create your own frame and set the window style to popup ...

Yeah, ok, it's abad idea, but ... :D

Gretz

Greenhorn

Link to comment
Share on other sites

"Moin" Greenhorn :P

Yes, i though too, about a popupwindow with 50% transparent on e.g RED and then i put it over the titlebar. But the window hasn't got a fixed pos/size.

I have an second question^^: How can i colorize menus? I dont mean smth like this. I mean the main Menu (GuiCtrlCreateMenu("File")). Is this possible to colorize? I have a black GUI and it looks bad if the Menu aren't black (the default gray suxt^^)

Thank you for comment, Greenhorn :D

MFG / BEst Regardz Spider

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

 

Link to comment
Share on other sites

Example from GUICtrlGetHandle

#include <GUIConstants.au3>

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


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

SetMenuColor($FileMenu, 0xEEBB99)   ; BGR color value
SetMenuColor($OptionsMenu, 0x66BB99); BGR color value
SetMenuColor($HelpMenu, 0x99BBEE)   ; BGR color value

GUISetState()

While 1
    $Msg = GUIGetMsg()
    
    Switch $Msg
        Case $EndBtn, $GUI_EVENT_CLOSE
            ExitLoop
        
        Case $AboutItem
            Msgbox(64, "About...", "Colored 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  = GUICtrlGetHandle($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))
    
    ; release Struct not really needed as it is a local 
    $stMenuInfo = 0
EndFunc
Link to comment
Share on other sites

Thanx Saunders,

it looks great !!! I think GtaSpider will be very delighted about this solution ! (me naturally too :P )

The last days he hadn't much luck with his requests, so I think he's gone offline now and sit in his Flat, drinking a lot of alcohol ...

(No, I'm just a joking :D;) )

Greetz

Greenhorn

Edited by Greenhorn
Link to comment
Share on other sites

Example from GUICtrlGetHandle

#include <GUIConstants.au3>

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


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

SetMenuColor($FileMenu, 0xEEBB99)   ; BGR color value
SetMenuColor($OptionsMenu, 0x66BB99); BGR color value
SetMenuColor($HelpMenu, 0x99BBEE)   ; BGR color value

GUISetState()

While 1
    $Msg = GUIGetMsg()
    
    Switch $Msg
        Case $EndBtn, $GUI_EVENT_CLOSE
            ExitLoop
        
        Case $AboutItem
            Msgbox(64, "About...", "Colored 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  = GUICtrlGetHandle($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))
    
    ; release Struct not really needed as it is a local 
    $stMenuInfo = 0
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

Far as I can tell you can set the System Active Title Bar color, not just a the Active Window at least not with-out painting and callback procedure.

This will set the System Active Title Bar color.

Note: It sets it back to the original color upon exit.

#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))
    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
Edited by GaryFrost

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 Gray,

I am getting errors on both your examples, can you take a look at them?

Missing some WinAPI functions there Gar... I don't have them. Do you?? :P Are they in the beta?

Answered my own question... ;) Run it with beta... :D

Edited by Bert
Link to comment
Share on other sites

Hello

Yeah, AMAZING. Thats very nice! Respect to booth of you! :D

But the Menubar isnt colored by me ;)

Posted Image

On WindowBlinds nothing Works (On the Default XP Theme, the Color in then Menu works), but this is not sooo important..

Posted Image

Thank you for your Replies :P

Mfg / Best Regardz Spider

Edited by GtaSpider

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

 

Link to comment
Share on other sites

hi Gray,

I am getting errors on both your examples, can you take a look at them?

Who the hell is Gray?

Nothing wrong with the examples, look at the beta.

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

Yeah, AMAZING. Thats very nice! Respect to booth of you! :D

But the Menubar isnt colored by me ;)

Posted Image

On WindowBlinds nothing Works (On the Default XP Theme, the Color in then Menu works), but this is not sooo important..

Posted Image

Thank you for your Replies :P

Mfg / Best Regardz Spider

You didn't say anything about coloring the menu bar itself.

Global Const $COLOR_MENU = 4
Global Const $COLOR_MENUHILIGHT = 29
Global Const $COLOR_MENUBAR = 30
Global Const $COLOR_MENUTEXT = 7
Edited by GaryFrost
added vars

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

Moin Gary,

it's a cool thing that you figured out.

My question is: Is this only available with the beta of AutoIt or also with the stable version ???

Greetz

Greenhorn

p.s.: I put an advert in the newspaper to search for 'Gray' ! :D

I'll let you know if it succeeds, but maybe we'll find an Alien ...

Link to comment
Share on other sites

Moin Gary,

it's a cool thing that you figured out.

My question is: Is this only available with the beta of AutoIt or also with the stable version ???

Greetz

Greenhorn

p.s.: I put an advert in the newspaper to search for 'Gray' ! :D

I'll let you know if it succeeds, but maybe we'll find an Alien ...

Well if it don't run in stable then I would say only in beta ATM.

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

how can I use this with tray menus?

-----------

Edit : sorry never mind found it in the help file !!

Edited by star2

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Link to comment
Share on other sites

...if there is an error happened, then the title bar should be colored red.

If you want something that looks and behaves like a title bar that can change colors, you could create your GUI with only the $WS_POPUP style or something, so that it has no title bar, and create it so that it can't be re-sized. Then you create an image file that looks like a title bar and put it at the top of your GUI and disable the pic control with GuiCtrlSetState. Then replace the image when needed, with another title-bar looking image, but of a different color, using GuiCtrlSetImage or by destroying the original pic control and replacing it, using the new colored image. You could even replicate the Windows system controls that minimize/restore, and close the GUI.

Das Häschen benutzt Radar

Link to comment
Share on other sites

If you want something that looks and behaves like a title bar that can change colors, you could create your GUI with only the $WS_POPUP style or something, so that it has no title bar, and create it so that it can't be re-sized. Then you create an image file that looks like a title bar and put it at the top of your GUI and disable the pic control with GuiCtrlSetState. Then replace the image when needed, with another title-bar looking image, but of a different color, using GuiCtrlSetImage or by destroying the original pic control and replacing it, using the new colored image. You could even replicate the Windows system controls that minimize/restore, and close the GUI.

Moin Squirrely1,

GtaSpider told me that it is not for a self created GUI ! He want to use it for windows from any Application, if I understood him right.

Greetz

Link to comment
Share on other sites

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

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

 

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