C++ Windows Console Color Palette - c++

I am making a console application similar to a rudimentary AAlib for a class. I am working with the win32 console. I wish to have more colors to work with. In the properties menu for the console there is a palette, giving 24 bit colors to foreground and background. Is there any way to access this palette in code?
The only thing I can think of is redefining the color palette[n] in HKEY_CURRENT_USER\Console for each call to color a character.
Alternatively if anyone knows a method for printing to window class like a terminal(where each character could have background color, not a fill) that could also work.

Related

How to change button color?

I am developing a GUI application using Embarcadero VCL c++ IDE for windows OS. As part of this project, I have to change color of button with respect to an external state.
I understood that windows32 API will not allow to change the color of button.
Could you please suggest me, how to change button color?
Do you wish to change the background-colour of the button, or the text-colour of it?
Since windows has used visual themes for some time now, if you have commctrl loaded and include a manifest file, the button will be drawn using the default (current) theme.
Options I can see include (a) custom-drawing the background (b) changing the text-colour in the normal draw process (c) drawing the button without a theme (i.e drawing a 'flat' button).
You could simply draw a bitmap-button, changing the bitmap depending on the state of the button. You could also use a single bitmap, tinting it using the HSL or HSV colour-space, depending on the state.
As for the flat type of button, I think you can probably change it's background-colour in much the same way as you can change the colour of the text - by intervening during the standard draw process and changing the colour from 3D_FACE (or whatever it is, I forget) to whatever you'd like.
If you look at the calculator included with windows XP, you can see an example of changing the text colour.
CodeProject.com likely has a stack of articles that would help in this endeavour. :)

Color Picker / Choser for an OpenGL Application

I am building an OpenGL application. I read through the GLUI tutorial on Code Project to create windows form controls on an OpenGL Application. But my requirement is to develop a color choser/picker, like an RGB chart or RGB cube to select a color. The tutorial on Code project shows the list of colors as a drop down box. However that wont really help me, as I require it to be present as a windows color picker. I know that color picker as a dialog box is a part of the windows application. Can anyone suggest me a way to use it with my OpenGL Application?
You can try fox-toolkit. It is a C++ based Toolkit for developing Graphical User Interfaces. It provides Color Picker and OpenGL widgets for 3D graphical manipulations.
On windows, you can call directly ChooseColor() from the windows API. It will open the native color color chooser.If you need a cross-platform solution, tiny file dialogs on sourceforge also has a color picker and no main loop.
You could render a Quad/Triangle/Cirle with different color on each vertex and activate smooth shading for interpolation between these points. Then just read back the color value from OpenGL at the mouse position.
edit: or like that where you calculate the color on the mouse position by yourself (reading values slows down OpenGL a lot!): http://sharathpatali.wordpress.com/2009/07/07/a-color-picker-for-pymt/
I did this with simple gradient image which i kept in memory. Then i just tracked my mouse position on the image, and simply read the data from the image (that was kept in RAM) and get the 32bit RGBA color value for it. This is easier than reading the pixels from screen (also faster and more reliable).
This also allows a lot more flexible way of presenting the palette, only your imagination is the limit on the looks of your palette. Note: you must use 32bit colors on the image, because if you want smooth edges, you simply just fade the alpha but keep the colors the same, so the colors wont get distorted at edges. Don't forget to enable blending when rendering the image.

win32 c++ owner draw button with transparent image

i've implemented a owner draw button into my win32 app (no MFC). The button is a normal 20x20 bitmap (round icon with transparency). The problem is that the button is positioned on a solid background and i can see the buttons gray background (since the bitmap is round). I've tried responding to WM_CTLCOLORBTN with NULL_BRUSH but no luck.. I've tried displaying the button using a bitmap and a ico file but wont budge.. Does anyone know how to solve this problem?
This is my problem, the settings icon should be transparent at the edges (not white/gray)
It sounds like you're trying to make a non-rectangular control.
You could call SetWindowRgn to tell Windows that your control is non-rectangular.
In addition to what #joel's answer, if you want to make some area transperant put a unique color in the area where you want to have transperancy using some image editors (RGB(0xFF,0x00,0xFF)) is mostly used Then use TransperantBlt
You say it's a solid background but your image shows some kind of orange-yellow gradient as a background. If it really was a standard windows button solid color you can load the bitmap with LoadImage using the LR_LOADMAP3DCOLORS or LR_LOADTRANSPARENT. Since you have a gradient you'll have to use a more complicated technique to mask out the bitmap.
http://www.winprog.org/tutorial/transparency.html

Win32: How can i set the color of windows Title, Scrollbar etc.?

I am updating a GUI of a Win32 Application in white text on black background. Thats simple for my content. But how can i change also the color of my child windows (Titlebar, Scrollbar etc.). i Know there is WM_CTLCOLORDLG to set the color of Dialogs. I also know there is WM_NCPAINT, but that would leave all painting (i.e of Scrollbars) to me. All i want, is to set colors of my choice.
You can use SetSysColors() to change the colour for window captions, borders, etc. (see http://msdn.microsoft.com/en-us/library/ms724940(VS.85).aspx). However this will change the colour for all windows, not just yours, so it is at the least an unfriendly thing to do.
One option is to use SetSysColors() to change the active window caption colour when your application has focus and to reset it to the defaults when it loses focus. But I'd say that's klunky and not really in keeping with good practice (suppose your application crashes? and there might be some flickering).
WM_NCPAINT is there so that you can do things like this. It is a bit of a pain, but maybe that's to discourage you from creating non-standard windows... ;-)
Hook GetSysColor() (Using something like Microsoft Detours)

How to draw Windows 7 taskbar like Shaded Buttons

Windows 7 taskbar buttons are drawn on a shaded background. The color shade somehow reacts on where the mouse is over the button.
I'd like to use such buttons in my application. How can i do that ?
Perhaps try
DrawThemeBackground
http://msdn.microsoft.com/en-us/library/bb773289(VS.85).aspx
Give it the BS_PUSHBUTTON constant. I've used this in Windows XP to draw the plush blue XP themed controls, but not in Aero, but it's worth a try.
The effect is called "Color Hot-track". It does not seem that there is a dedicated API for that. There are some notes in a developer blog about it:
I found some source code from Rudi Grobler though doing a similar thing:
Make your WPF buttons color hot-track!
I believe they're implemented as shader programs on the GPU. Just a simple program which takes the cursor position, and computes a brightness for each pixel based on the distance from that position.
It uses the new animation api (Some of it exists in Vista, extended in 7) There is no magic style to set, you still need to do the drawing on your own