Jump to content

How to change window title color ?


Andk
 Share

Recommended Posts

No clue what that line is supposed to be doing, but whatever it is, isn't working as expected. I was just commenting on your assertion that the dllcall was causing the problem.

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

I think was DLLCall because i see the _WinAPI_SetSysColors in the autoit example. So, if it is in the autoit example must be working, and the only change to that code is the DLLCall

The _WinAPI_SetSysColors without the DllCall("UxTheme.dll" etc. not work on both sistem i have tested, if i add it work but but have that strange behavior

Myabe i'm wrong, i don't know, anyway don't work as expected

Edited by johnmcloud
Link to comment
Share on other sites

Wait, i have found the error. The original post by GaryFrost have this WinAPI_SetSysColors:

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

This is the _WinAPI_SetSysColor in autoit:

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("dword NewColor[" & $iElementNum & "]")

 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 $aResult = DllCall("user32.dll", "bool", "SetSysColors", "int", $iElementNum, "struct*", $tElements, "struct*", $tColors)
 If @error Then Return SetError(@error, @extended, False)
 Return $aResult[0]
EndFunc   ;==>_WinAPI_SetSysColors

If i use the GaryFrost _GetSysColor i have the yellow notepad, but if i close the GUI everything goes to normal. It's possible to edit the GaryFrost _GetSysColor for work only on my gui instead of everyone?

Anyway it's a good start at least, close the GUI remove the problem

Edited by johnmcloud
Link to comment
Share on other sites

I only wanted to point out that you were wrong when you said the DllCall was causing the issue, when it's clear that it's not because it's been used by a lot of people before without any problem. Here's a quote from the MSDN site in regards to SetSysColor

Remarks

The SetSysColors function sends a WM_SYSCOLORCHANGE message to all windows to inform them of the change in color. It also directs the system to repaint the affected portions of all currently visible windows.

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

Just for conclude this, the SetSysColors function sends a WM_SYSCOLORCHANGE message to all windows, right? But there isn't a way to prevent this? Maybe:

1) Usign a dummy

or

2) We can't send directly the WM_SYSCOLORCHANGE to our GUI insted to use SetSysColors? So we can avoid the message to all window

Do you guy think is possible or I'm delirious for the late hours?

Link to comment
Share on other sites

I believe its a Bug that the colors arent changing back

I did some debugging

and guess what the debugging made the bug vanish (or maybe i forgot what i did :P)

Here is the code

#include <WinAPI.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_WINDOW]
; 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_WINDOW)

_ArrayDisplay($aSaveColors)

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

GUISetState()

Local $iTemp[2] = [_WinAPI_GetSysColor($COLOR_ACTIVECAPTION), _WinAPI_GetSysColor($COLOR_WINDOW)]
_ArrayDisplay($iTemp)

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

If _WinAPI_SetSysColors($aElements, $aSaveColors) Then MsgBox(0, 0, True)
Local $iTemp[2] = [_WinAPI_GetSysColor($COLOR_ACTIVECAPTION), _WinAPI_GetSysColor($COLOR_WINDOW)]
_ArrayDisplay($iTemp)

This reverts the color back to normal :)

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

Perhaps I missed it, but why would you need to change the titlebar colour?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 4 years later...

Been a few years since this post was touched. Any chance the full code is still around. I got it to change the color of my GUI as the code above works. I just can't get the sample working where he ( @johnmcloud ) was able to change notepad's color yellow.  

Update: Arghhh I looked at it a bit more and realized it's changing the whole windows theme color for every cooperating windows program. I tested i by running the code above and opened notepad as the color theme was changed and noticed notepad text area was yellow.  This isn't going to help me. I wanted to change an individual windows titlebar color as an alert so I tried the following:

;From: https://www.autoitscript.com/forum/topic/120421-how-to-change-window-title-color/

#include <WinAPI.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]

Local $aColors[2] = [DEC("FF"),DEC("FFFF")] ; Red and Yellow
Local $aSaveColors[2]

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Run(@WindowsDir & "\Notepad.exe")
Global $hGUI = WinWait("Notepad")
;$hGui = GUICreate("My GUI", 300, 200)
$aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)
$aSaveColors[1] = _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)

_ArrayDisplay($aSaveColors)

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

GUISetState()

Local $iTemp[2] = [_WinAPI_GetSysColor($COLOR_ACTIVECAPTION), _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)]
_ArrayDisplay($iTemp)

While 1
   $Msg = GUIGetMsg()
   If NOT (WinExists($s_remoteMainTitle)) Then
      ;MsgBox(0,"Notice","Shutting down QbooksButtons, No remoteTitle found")
      ExitLoop
   EndIf
;~    Switch $Msg
;~    Case -3 ; $GUI_EVENT_CLOSE
;~       ExitLoop
;~    EndSwitch
WEnd

If _WinAPI_SetSysColors($aElements, $aSaveColors) Then MsgBox(0, 0, True)
Local $iTemp[2] = [_WinAPI_GetSysColor($COLOR_ACTIVECAPTION), _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)]
_ArrayDisplay($iTemp)

but that didn't change notepads titlebar color. I'm still missing something so that I can just change one remote windows titlebar color.

Edited by nassausky
Update on research.
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...