Jump to content

How to change window title color ?


Andk
 Share

Recommended Posts

Try this.

#include <WinAPI.au3>
; http://www.autoitscript.com/forum/index.php?showtopic=62641&view=findpost&p=469512

Global Const $COLOR_ACTIVECAPTION = 2
Global Const $COLOR_GRADIENTACTIVECAPTION = 27
Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]
; Red and Yellow
Local $aColors[2] = [255, 65535], $aSaveColors[2]

$hGui = GUICreate("My GUI", 300, 200)
$aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)
$aSaveColors[1] = _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)

_WinAPI_SetSysColors($aElements, $aColors)

GUISetState()

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

_WinAPI_SetSysColors($aElements, $aSaveColors)

As most things have already been mentioned on these forums in the past, try searching on +titlebar + color using the forum search input box.

Link to comment
Share on other sites

#Include <Constants.au3>
#Include <FontConstants.au3>
#Include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

$hFont = _WinAPI_CreateFont(16, 0, 0, 0, $FW_BOLD, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_PITCH, $ANTIALIASED_QUALITY, 'Arial')

$hForm = GUICreate('', 400, 400)
$hHook = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;long;ptr')
$pHook = DllCallbackGetPtr($hHook)
$hProc = _WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $pHook)
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $hProc)
DllCallBackFree($hProc)

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)

    Local $Res = _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
    Local $hDC, $hSv

    Switch $iMsg
        Case $WM_NCACTIVATE, $WM_NCPAINT
            Switch $iMsg
                Case $WM_NCACTIVATE
                    $hDC = _WinAPI_GetWindowDC($hWnd)
                Case $WM_NCPAINT
                    $hDC = _WinAPI_GetDCEx($hWnd, $wParam, BitOR($DCX_WINDOW, $DCX_INTERSECTRGN))
            EndSwitch
            $hSv = _WinAPI_SelectObject($hDC, $hFont)
            _WinAPI_SetTextColor($hDC, 0x00FFFF)
            _WinAPI_SetBkMode($hDC, $TRANSPARENT)
            _WinAPI_TextOut($hDC, 25, 8, 'MyGUI')
            _WinAPI_SelectObject($hDC, $hSv)
            _WinAPI_ReleaseDC($hWnd, $hDC)
    EndSwitch
    Return $Res
EndFunc   ;==>_WinProc

WinAPIEx.au3

Edited by Yashied
Link to comment
Share on other sites

  • 2 years later...

Hi,

I have try both example but not work ( maybe need a code update, 2010 --> 2013 )

So if was possible to change the TITLEBAR color in the 2010 i think is possible also now lol

Yashied, is possible to update the code? Thanks

And also to the TITLEBAR color, is possible to change the FONT color or/and the type?

Link to comment
Share on other sites

MyEarth,

Despite the code being posted 28 months ago Malkey's code works perfectly and

Yashied's code works with the addition of one include file.

How are you testing this and what error are you receiving?

And, more importantly, did you try to do any debugging?

kylomas

edit: additional info - There is also a similar example in the help file. To quote Malkey

As most things have already been mentioned on these forums in the past, try searching on +titlebar + color using the forum search input box.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

I have modified the system theme,

maybe that is the cause there is no change in the color of title bar i guess :huh:

Edit : I added error check and I receive error code = 1(ERROR_INVALID_FUNCTION) with _Winapi_GetDCEx

#include <Constants.au3>
#include <APIConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>

$hFont = _WinAPI_CreateFont(16, 0, 0, 0, $FW_BOLD, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_PITCH, $ANTIALIASED_QUALITY, 'Arial')

$hForm = GUICreate('Hello', 400, 400)
$hHook = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;long;ptr')
$pHook = DllCallbackGetPtr($hHook)
$hProc = _WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $pHook)
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $hProc)
DllCallbackFree($hProc)

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)

Local $Res = _WinAPI_CallWindowProcW($hProc, $hWnd, $iMsg, $wParam, $lParam)
Local $hDC, $hSv

Switch $iMsg
Case $WM_NCACTIVATE
$hDC = _WinAPI_GetWindowDC($hWnd)
Case $WM_NCPAINT
$hDC = _WinAPI_GetDCEx($hWnd, $wParam, BitOR($DCX_WINDOW, $DCX_INTERSECTRGN))
If @error Then ConsoleWrite(@error) ;This give me error code 1 = ERROR_INVALID_FUNCTION
EndSwitch

$hSv = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_SetTextColor($hDC, 0x00FFFF)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_TextOut($hDC, 25, 8, 'MyGUI')
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_ReleaseDC($hWnd, $hDC)

Return $Res
EndFunc ;==>_WinProc

Environment(Language:0409 Keyboard:00000409 OS:WIN_7/ CPU:X64 OS:X86)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

After running the following code I received the following ConsoleOutput

After changing the theme back to Aero also, i received the error

#include <Constants.au3>
#include <APIConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>

$hFont = _WinAPI_CreateFont(16, 0, 0, 0, $FW_BOLD, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_PITCH, $ANTIALIASED_QUALITY, 'Arial')
If @error Then Exit -1
$hForm = GUICreate('Hello', 400, 400)
$hHook = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;long;ptr')
$pHook = DllCallbackGetPtr($hHook)
$hProc = _WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $pHook)
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_SetWindowLongEx($hForm, $GWL_WNDPROC, $hProc)
DllCallbackFree($hProc)

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)

Local $Res = _WinAPI_CallWindowProcW($hProc, $hWnd, $iMsg, $wParam, $lParam)
Local $hDC, $hSv


Switch $iMsg
Case $WM_NCACTIVATE, $WM_NCPAINT
Switch $iMsg

Case $WM_NCACTIVATE
$hDC = _WinAPI_GetWindowDC($hWnd)
If @error Then ConsoleWrite("GetWindowDC:" & _WinAPI_GetLastErrorMessage()) ;This give me error code 1 = The Parameter is Incorrect
Case $WM_NCPAINT
$hDC = _WinAPI_GetDCEx($hWnd, $wParam, BitOR($DCX_WINDOW, $DCX_INTERSECTRGN))
If @error Then ConsoleWrite("GetDCEx:" & _WinAPI_GetLastErrorMessage()) ;This give me error code 1 = The Parameter is Incorrect
EndSwitch

$hSv = _WinAPI_SelectObject($hDC, $hFont)
If $hSv <= 0 Then ConsoleWrite("SelectObject1: <= 0; Message:" & _WinAPI_GetLastErrorMessage())
If _WinAPI_SetTextColor($hDC, 0x00FFFF) = -1 Then ConsoleWrite("SetTextColor: -1; Message:" & _WinAPI_GetLastErrorMessage())

If _WinAPI_SetBkMode($hDC, $TRANSPARENT) = 0 Then ConsoleWrite("SetBkMode: 0; Message:" & _WinAPI_GetLastErrorMessage())

_WinAPI_TextOut($hDC, 25, 8, 'MyGUI')

If @error Then ConsoleWrite("TextOut:" & _WinAPI_GetLastErrorMessage()) ;This give me error code 1 = The Parameter is Incorrect
If _WinAPI_SelectObject($hDC, $hSv) <= 0 Then ConsoleWrite("SelectObject2: <= 0; Message:" & _WinAPI_GetLastErrorMessage())

If _WinAPI_ReleaseDC($hWnd, $hDC) = False Then ConsoleWrite("ReleaseDC: False; Message" & _WinAPI_GetLastErrorMessage())

EndSwitch

Return $Res
EndFunc ;==>_WinProc

Console

GetDCEx:The parameter is incorrect.
SelectObject1: <= 0; Message:The handle is invalid.
SetTextColor: -1; Message:The handle is invalid.
SetBkMode: 0; Message:The handle is invalid.
TextOut:The handle is invalid.
SelectObject2: <= 0; Message:The handle is invalid.
ReleaseDC: False; MessageThe handle is invalid.

The handle receiving from the DC fails and all the subsequent functions hence fail

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

PhoenixXL,

The code that you posted does not run on my system either. The code that I was referring to was that posted by Malkey and Yashied.

Both these examples work perfectly on my system (Win7 64bit).

I should have been more explicit.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

If you check the code i posted its the same as yashied's code, if have only added the debugging part

I got the problem, the theme was overiding the colors

Change to a contrast theme rather than aero like classic window theme to get the changes i'll post back the results soon

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

This should finally solve the problem - the theme was overriding the colors

#include <WinAPI.au3>
; http://www.autoitscript.com/forum/index.php?showtopic=62641&view=findpost&p=469512


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

Local $aElements[3] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]
; Red and Yellow
Local $aColors[3] = [255, 65535], $aSaveColors[2]

$hGui = GUICreate("My GUI", 300, 200)

DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hGui, "wstr", 0, "wstr", 0)

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

_WinAPI_SetSysColors($aElements, $aColors)

GUISetState()

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

_WinAPI_SetSysColors($aElements, $aSaveColors)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

It should only affect the window that you create with the script using the DLLCall function.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hi have a couple last question, sorry for this late answer:

1) How to change the font color ( and maybe type ) of the TitleBar? If i make the titlebar black and the font is black i don't see nothing

2) How to center the title bar text, now is everything on the left. ( EDIT :Solved adding space char, maybe there is another way but i think is good )

3) How to remove that border like Windows 98 around the window?

Thanks everyone

Edited by MyEarth
Link to comment
Share on other sites

There is a problem with this line:

DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", WinGetHandle($GUI), "wstr", 0, "wstr", 0)

or

DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $GUI, "wstr", 0, "wstr", 0)

Not apply only the the main GUI, but also to every window ( on XP )

If i double click on a title bar of a folder, or i minimize a folder i see the color of my titlebar GUI, also if i have close it. I need to reboot to remove it.

How to disable the effect when the autoit GUI is closed?

EDIT: Tested also on Windows 7, same problem...

Edited by johnmcloud
Link to comment
Share on other sites

It's not supposed to do it to every window, just the one that the handle applies to. I've used this line dozens of times and it's never applied its effects to anything other than the window or control I referenced it to.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hi BrewManNH,

Do you think i see strange color without no reason? Lol, check it out:

The code ( is the same of Phoneix, just change to $COLOR_WINDOW for see the effect, but is the same with $COLOR_GRADIENTACTIVECAPTION) :

#include <WinAPI.au3>
#include <WindowsConstants.au3>
Local $aElements[3] = [$COLOR_ACTIVECAPTION, $COLOR_WINDOW]
; Red and Yellow
Local $aColors[3] = [255, 65535], $aSaveColors[2]
$hGui = GUICreate("My GUI", 300, 200)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hGui, "wstr", 0, "wstr", 0)
$aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)
$aSaveColors[1] = _WinAPI_GetSysColor($COLOR_WINDOW)
_WinAPI_SetSysColors($aElements, $aColors)
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3 ; $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_WinAPI_SetSysColors($aElements, $aSaveColors)

Image proof:

Posted Image

Posted Image

My life in yellow ahah. if I wanted to do it I would not be able, it's like a real time theme :D

I have the same problem on 7, if close the gui nothing change, i need to reboot or disconnect

Edited by johnmcloud
Link to comment
Share on other sites

It's not caused by the line you mentioned, it's caused by this line

_WinAPI_SetSysColors($aElements, $aColors)

If you comment out that line, then you don't get recolored window elements in every window. So, as I said, it has nothing to do with the dllcall statement.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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