You are here:

C++/change win color


I would like to know, how to change the background-color of a window (known by a HWND) of another win23-application!?
(the window belongs to an other app, not my app!)

Example for changing of the text of a window:
::SetWindowText(hwnd, "text");

SetClassLong(hwnd, GCL_HBRBACKGROUND, hbrush);
doesn't work because of 'access denied' GetLastError().

OS: win-xp
compiler: visual studio

I've never had to do this but I think the problem is the hbrush is allocated in one process and SetClassLong applies it to a window in another process.  This is a pretty obscure requirement and request - I don't know anyone who would have done this kind of task.  I might suggest you look into one of the MicroSoft support lists and see if anyone there knows if this is possible, and if it is, how.

Sorry to not be much help on this one.



All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2016 All rights reserved.