Set background color of entire window in PDCurses - c++

wattron and a color pair only sets the background color of text when it is printed inside a window. What is the best way to set the background color of the entire window without filling it with spaces (i.e. a title or status bar)?

A call to wbkgd with a pointer to a WINDOW object and a color pair sets the background color of the window.

Related

Different colors of COLOR_WINDOW in Windows 10 and Windows XP

In Windows 10 color of window equal of background colors of GUI elements. However, in Windows XP color of window is white, that is not equal of background colors of elements.
WNDCLASSEX configuration:
WNDCLASSEX wincl;
//...
wincl.hbrBackground = (HBRUSH)COLOR_WINDOW; // Set background color
//...
if (!RegisterClassEx (&wincl))
return 1;
What is color I should use as window background in Windows XP?
COLOR_3DFACE/COLOR_BTNFACE is the color constant you are looking for. COLOR_WINDOW is the color inside a text box.
GetSysColor function
Value
Meaning
COLOR_3DFACE15
Face color for three-dimensional display elements and for dialog box backgrounds.
COLOR_BTNFACE15
Face color for three-dimensional display elements and for dialog box backgrounds. The associated foreground color is COLOR_BTNTEXT.
You must add +1 to the system color constant when using it as a class brush:
WNDCLASSEXA structure
WNDCLASSEXW structure
hbrBackground
Type: HBRUSH
A handle to the class background brush. This member can be a handle to the brush to be used for painting the background, or it can be a color value. A color value must be one of the following standard system colors (the value 1 must be added to the chosen color). If a color value is given, you must convert it to one of the following HBRUSH types:
Why do I have to add one when setting a class background brush to a system color?
To make sure that the result is not zero.
The COLOR_SCROLL­BAR system color is index zero. If we didn’t add one to the system color indices, then an attempt to set the background color to the scroll bar color would end up with (HBRUSH)0, which is a null pointer. When the system saw that you set hbrBackground to a null pointer, it wouldn’t know whether you meant the window to have no background color (null pointer), or whether you wanted it to have the system scroll bar color (COLOR_SCROLL­BAR).

How to change the background color of the whole console without affecting the text color in c++ on windows OS

I am trying to make a function having a text color and a background color attribute. The text color attribute just sets the color of the text to follow while the background color has to change the background color of whole console window.
The problem is that the SetConsoleTextAttribute() function only changes the background color of a block of text but not of the whole console window. While the problem with system("Color code") is that it changes the color of any pre-written text also.
what I want to do is this:
int main()
{
setColor("Red","Blue");
//custom function setColor() to set text color Red and Console's color Blue.
cout << "This is Red text on a Blue console window" << endl;
setColor("Yellow","Black"); /*now the whole console's color should turn Black, the color
of pre-written text above remains Red and the color of text
to follow should be Yellow.*/
cout << "This is Yellow text on a Black console window, The previous text is still Red";
return 0;
}
I have tried mixing both system() and setConsoleTextAttribute functions to achieve this but I failed to preserve the color of pre-written text while changing color of the text to follow.
So, is there a way of making a function which does the same thing as the setColor() function did in this example?
You will need to implement this yourself. The Windows Console API can help, all the functions are documented here.
You can read the colors of the currently displayed characters with ReadConsoleOutputAttributes. You can change them to the new background color with WriteConsoleOutputAttributes.

How to set the background color of a OpenGL enhanced QGraphicsView?

I have a custom QGraphicsView class where I try to set the background color in its constructor.
These work in non-OpenGL mode:
QColor backgroundColor(50,50,50,255);
setBackGroundBrush(backgroundColor)
and
QPalette myPal = this->palette();
myPal.setColor(this->backgroundRole(), backgroundColor);
this->setPalette(myPal);
However in OpenGL mode the first produces a white screen clearing, while the second clears the widget with the given color. I can also see for a few milliseconds the actual item ought to be drawn in between repaints.
If I don't set the background color at all a white background is set, and everything functions just fine.

c++ DrawText() font color and background color

How do I change the text color and font background color that is displayed when I use the DrawText() function?
Whenever I use the DrawText() function, I always output a present font as well as a "white" background color. I understand to change the font I must create the HFONT and use SelectObject to set the font, however... I did not find any color options in the CreateFont parameters (searched in msdn):
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499(v=vs.85).aspx
Now, on msdn page for the DrawText() function (http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx) I found the following comment:
"The DrawText function uses the device context's selected font, text color, and background color to draw the text. "
And that is all I could find relative to text color and background color. From that sentence, I am unsure if I should be using some other GDI functions to select other objects that specify text color or background color (if those objects exist), nor am I sure if I missed something in the parameters for CreatFont().
QUESTION:
How do I change the text color and font background color that is displayed when I use the DrawText() function?

hbrBackground in c++

I have created the above simple GUI in c++. I would like the static text control background to be same as the main window (which is white) or how can i make the main window background (hbrBackground) to be the same color as the background in the static text control?
Many thanks!
You can set the background of the static control by responding to WM_CTLCOLORSTATIC.
You can change the background color of your window by responding to WM_ERASEBKGND and calling (for one possibility) FillRect.