Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WIN32 Console application colour ? Pin
James Laing26-Aug-06 12:35
James Laing26-Aug-06 12:35 
GeneralRe: WIN32 Console application colour ? Pin
James Brown27-Aug-06 4:26
James Brown27-Aug-06 4:26 
GeneralRe: WIN32 Console application colour ? Pin
James Laing28-Aug-06 1:44
James Laing28-Aug-06 1:44 
GeneralRe: WIN32 Console application colour ? Pin
James Brown28-Aug-06 2:35
James Brown28-Aug-06 2:35 
GeneralRe: WIN32 Console application colour ? Pin
James Laing28-Aug-06 3:54
James Laing28-Aug-06 3:54 
GeneralRe: WIN32 Console application colour ? Pin
James Brown28-Aug-06 4:13
James Brown28-Aug-06 4:13 
GeneralRe: WIN32 Console application colour ? Pin
James Laing28-Aug-06 9:50
James Laing28-Aug-06 9:50 
GeneralRe: WIN32 Console application colour ? Pin
James Brown28-Aug-06 10:39
James Brown28-Aug-06 10:39 
James,
I really do believe the FillConsoleOutputAttribute will solve your problem - and do shouldn't need to know how many characters/bytes have been written. I had assumed you just wanted to fill the entire console buffer with the same colour? You can use FillConsoleOutputAttribute to colour all cell-positions within the console, not just those characters already written (think about how the 'CLS' command might work). So the number of characters to fill = width_of_console * height_of_console. Filling the entire console does not alter the 'cursor position' it just sets the cell-colours.

GetConsoleScreenBufferInfo API will return you information regarding the size of the output-window (in the CONSOLE_SCREEN_BUFFER_INFO::dwSize field). So your number of characters. This is untested code:

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;

GetConsoleScreenBufferInfo(hConsole, &csbi);

COORD top = { 0, 0 };
DWORD written;
WORD attr = << colour value here >>
FillConsoleOutputAttribute(hConsole, attr, csbi.dwSize.x * csbi.dwSize.y, top,
&written);

Documentation for FillConsoleOutputAttribute states: "If the number of character cells whose attributes are to be set extends beyond the end of the specified row in the screen buffer, the cells are written up to the end of the screen buffer". So you could in fact omit the GetConsoleScreenBufferInfo and just specify a "big" number for the number-of-characters. (i.e. 2^31).

Hope this was of some help, and sorry that we got off on the wrong foot.

regards,
James



GeneralRe: WIN32 Console application colour ? Pin
James Laing28-Aug-06 11:41
James Laing28-Aug-06 11:41 
GeneralRe: WIN32 Console application colour ? Pin
Laing,James28-Aug-06 11:59
Laing,James28-Aug-06 11:59 
QuestionI hate Unicode!! Pin
Waldermort26-Aug-06 10:24
Waldermort26-Aug-06 10:24 
AnswerRe: I hate Unicode!! Pin
Michael Dunn26-Aug-06 21:27
sitebuilderMichael Dunn26-Aug-06 21:27 
GeneralRe: I hate Unicode!! [modified] Pin
Waldermort26-Aug-06 22:08
Waldermort26-Aug-06 22:08 
GeneralRe: I hate Unicode!! [modified] Pin
fefe.wyx26-Aug-06 22:24
fefe.wyx26-Aug-06 22:24 
GeneralRe: I hate Unicode!! Pin
Waldermort26-Aug-06 22:48
Waldermort26-Aug-06 22:48 
GeneralRe: I hate Unicode!! Pin
fefe.wyx26-Aug-06 23:33
fefe.wyx26-Aug-06 23:33 
GeneralRe: I hate Unicode!! Pin
Waldermort27-Aug-06 0:27
Waldermort27-Aug-06 0:27 
QuestionRegistry Unicode Problem Pin
lucki_luke26-Aug-06 9:55
lucki_luke26-Aug-06 9:55 
AnswerRe: Registry Unicode Problem Pin
Mike Dimmick26-Aug-06 11:09
Mike Dimmick26-Aug-06 11:09 
Questionreading values within std::list types Pin
jon-8026-Aug-06 8:34
professionaljon-8026-Aug-06 8:34 
AnswerRe: reading values within std::list types Pin
Waldermort26-Aug-06 9:23
Waldermort26-Aug-06 9:23 
GeneralRe: reading values within std::list types Pin
jon-8026-Aug-06 10:40
professionaljon-8026-Aug-06 10:40 
GeneralRe: reading values within std::list types Pin
Waldermort26-Aug-06 10:53
Waldermort26-Aug-06 10:53 
AnswerRe: reading values within std::list types [modified] Pin
Mike Danberg27-Aug-06 17:53
Mike Danberg27-Aug-06 17:53 
QuestionOperating system info Pin
Kiran Pinjala26-Aug-06 8:29
Kiran Pinjala26-Aug-06 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.