I have an application which draws to the console window in text mode
using the following two functions:
* WriteConsoleOutputCharacter
* WriteConsoleOutputAttribute
Is it possible to modify the palette used for text in console mode?
I.E., can I modfy the appearance of color 2 (normally green) to use a
specific set of RGB values?
Also, can I modify the appearance of the text characters?
Thank you.
Well, if your application needs the colour changes to effects the
currently active console window, you can use the following API to
set the current foreGround and backGround colours:
SetConsoleTextAttribute()
However, I've tried the following API's to modify the console's
palette dynamically during the console's run session, and even
though all the calls have succeeded withOut any error code, the
results was not the desired effects on the colour palette.
SetConsoleTitle()
FindWindowEx()
GetDC()
GetDeviceCaps() using RASTERCAPS
CreatePalette()
SelectPalette()
RealizePalette()
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsoletitle.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_4esj.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_88s3.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/colors_4x5x.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/colors_4u79.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/colors_9kv9.asp
Hope these information helps,
Kellie.
The standard API palette routines do not (as you have found) work
on console windows. However...
it is possible to modify a console window's palette at runtime
using an undocumented method. It uses the same "interface" to control
the console window at runtime that is used by the console's Properties
window
www.catch22.net/source/files/setconsoleinfo.c
VOID WINAPI SetConsolePalette(COLORREF crPalette[16]);
e.g.
COLORREF DefaultColors[16] =
{
0x00000000, 0x00800000, 0x00008000, 0x00808000,
0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0,
0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00,
0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
};
SetConsolePalette(DefaultColors);
James
--
www.catch22.net
Free win32 software, sourcecode and tutorials
"Kellie Fitton" <KELLIE...@YAHOO.COM> wrote in message
news:1127710554....@g14g2000cwa.googlegroups.com...
What about modifying the colour table in the registry? for example:
HKEY_CURRENT_USER/Console/{programName}/ColorTable00
if I use the API's RegOpenKey() and RegSetValueEx() to change the
colour table {00} to red colour(000000ff), is there a way to make
these changes affects the active console window and set the console
palette to any specific RGB values?
Kellie.
The only "runtime" programmatic method is to use the undocumented
console message (WM_USER+201) and pass a handle-to-section which
contains the CONSOLE_INFO structure.
James
--
www.catch22.net
Free win32 software, sourcecode and tutorials
"Kellie Fitton" <KELLIE...@YAHOO.COM> wrote in message
news:1127745526....@g44g2000cwa.googlegroups.com...
Awesome, thank you James. I will try this later today.
Kellie. :--)
>Hi,
>
>The standard API palette routines do not (as you have found) work
>on console windows. However...
>
>it is possible to modify a console window's palette at runtime
>using an undocumented method. It uses the same "interface" to control
>the console window at runtime that is used by the console's Properties
>window
>
>www.catch22.net/source/files/setconsoleinfo.c
>
>VOID WINAPI SetConsolePalette(COLORREF crPalette[16]);
>
>e.g.
>
>COLORREF DefaultColors[16] =
>{
> 0x00000000, 0x00800000, 0x00008000, 0x00808000,
> 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0,
> 0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00,
> 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
>};
>
>SetConsolePalette(DefaultColors);
>
>
>James
Hi James,
I tried with the code you linked to, but for some reason I am not
seeing any palette change (I modified the array so the colors are no
longer the default ones). I also tried changing a few of the other
fields like window width/height, just to see if anything was
happening, but the console window is not changing at all. Your
routines are getting executed with no problems (no exceptions or
anything), but I am just not seeing any results on the screen.
Unfortunately I am quite unfamiliar with Windows programming. I
cannot easily follow your code because of this, and I am having a
difficult time debugging this. I know it's a vague and general
question, but would you happen to have any ideas on what the problem
could be? I would very much like to be able to change the console's
palette, and it would be perfect if I could get your solution to work.
If I can't get it to work, then I will try to do the registry thing
that Kellie suggested (thanks Kellie!), but ideally I would like to be
able to change the palette multiple times for the same console window.
Thanks.
But interestingly it appears to be not working on my XP SP2..
I've just dug around and the undoc message (0x4c9) is no longer being
sent...
this is something that has presumably changed since the related security
advisory+patch.
So things are slightly different on Windows with security update KB890859
applied
I'll see if I can find what new method is being used now and post an update.
James
www.catch22.net
Free win32 software, sourcecode and tutorials
"Squeamizh" <blhbalh@.balh> wrote in message
news:ekoij11jrhttht47u...@4ax.com...
The difference is that the CONSOLE_INFO structure (as I call it)
has changed size slightly. Put the following at the end of the struct.
BYTE Padding[0x20];
I'll update the source on my site later on.
James
--
www.catch22.net
Free win32 software, sourcecode and tutorials
"James Brown" <remove_james_dot_brown7_at_virgin_dot_net> wrote in message
news:43396fec$0$22983$cc9e...@news.dial.pipex.com...
www.catch22.net/source/files/setconsoleinfo.c
James
--
www.catch22.net
Free win32 software, sourcecode and tutorials
"James Brown" <remove_james_dot_brown7_at_virgin_dot_net> wrote in message
news:43396fec$0$22983$cc9e...@news.dial.pipex.com...
HKEY_CURRENT_USER\Console\C:_UI.EXE\ColorTable00 set to a value of
0x00bababa
It then launches C:\UI.EXE so the registry entries are there before the
program starts.
However, UI doesn't appear to see the ColorTable00 setting in the
registry. It still uses the ColorTable00 value from
HKEY_CURRENT_USER\Console.
If I go to UI Properities and manually change the value for
ColorTable00 and save, it updates the registry and overwrites WININIT's
entry so I assume it must be writing to the correct registry key.
I am using Windows XP SP1 and Visual Studio .NET C++
Any ideas why this wouldn't be working?
Rich
> BYTE Padding[0x20];
It works beautifully! Thank you so much--this is a huge help.
The registry settings for a console are based upon the console-window title.
So unless you start the console-program with the same title that appears
in the registry, it will not pick up the correct settings.
This is how the "Apply to current window only" and "Save properties for
future windows with same title"
thing works when you change the console properties using the regular
Properties dialog.
i.e. when a console is created, it checks it's title, and then tries to
match this title
to one stored in the registry under the HKCU\Console tree.
>ok just confirmed with SoftIce that the message is still being sent.
>
>The difference is that the CONSOLE_INFO structure (as I call it)
>has changed size slightly. Put the following at the end of the struct.
>
> BYTE Padding[0x20];
>
>I'll update the source on my site later on.
>
>James
Hi James,
I have another very similar question. The code that you provided
works perfectly for consoles that are not in full-screen mode.
However, I epxerience problems when trying to change the palette of a
full-screen console. If I specify FullScreen = TRUE in the
ConsoleInfo struct, calling the SetConsoleColor function results in
the screen flickering for a moment (as if the console switched to
windowed mode and then instantly back to full-screen mode again), and
the palette remains unchanged. After this, I have to manually
ALT+ENTER to see the change in palette (switching back to full-screen
mode once again after doing this resulst in a full-screen console with
the correctly modified palette).
What I would like now is to be able to instantly change the palette of
a full-screen console. I have the sinking suspicion that this is not
possible, but I thought I would ask in case you or anyone else happens
to know of a solution. If not then I can definitely make do with what
you've given me.
Thanks again for your help so far,
Chris
>Hi James,
>
>I have another very similar question. The code that you provided
>works perfectly for consoles that are not in full-screen mode.
>However...
Actually, my mistake. I won't be needing to do this afterall.
that's good because I'm not sure how to set the console when it's in
full-screen mode. Windows puts it in some kind of video emulation mode and
the palette-change occurs (I believe) through an LPC call (i.e. a
CSRSS message, not a Windows message).