WIN32 Console application colour ?
-
just run your console app, right click the title bar to open the proerties dialog and set it from there. Remember to click yes when it prompts you to save for all future windows.
Sorry, I was not clear, I meant programmatically, at the console initialisation stage. James.
-
Sorry, I was not clear, I meant programmatically, at the console initialisation stage. James.
FillConsoleOutputAttribute
-
FillConsoleOutputAttribute
Thank you very much for the response. The function is indeed useful, however, I would like to know if there is a way to define the console output attributes at creation time, as my application writes an indeterminate number of lines to its output console. I would like to avoid the overhead of having to determine if the next write will be ‘outside’ the currently defined range of cells covered by the last call to function. Is there a way to specify at console initialisation, for example, the background colour of all console line output ? James.
-
Thank you very much for the response. The function is indeed useful, however, I would like to know if there is a way to define the console output attributes at creation time, as my application writes an indeterminate number of lines to its output console. I would like to avoid the overhead of having to determine if the next write will be ‘outside’ the currently defined range of cells covered by the last call to function. Is there a way to specify at console initialisation, for example, the background colour of all console line output ? James.
Use FillConsoleOutputAttribute when your program starts to fill the entire console with one colour. Use SetConsoleTextAttribute to set the current colour used for text-output these are fully documented in MSDN, I really don't know why people don't read the documentation before asking questions - it would save you a lot of time.
-
Use FillConsoleOutputAttribute when your program starts to fill the entire console with one colour. Use SetConsoleTextAttribute to set the current colour used for text-output these are fully documented in MSDN, I really don't know why people don't read the documentation before asking questions - it would save you a lot of time.
Thanks again for the response. I really do not understand your need to be critical of my question whilst at the same time attempting to answer it. Why did you bother if the question is so trivial?. Your answer is not even directed at me, it is a cheap arogant point scroring excercise and very childish. There are people of differing levels of experience and competence that post questions on this forum and it is people like you that most of us in the industry despise. Please feel free to ignore any further questions that I might post, I would rather not have your help. And, your response does not answer my question - try re-reading it. James.
-
Thanks again for the response. I really do not understand your need to be critical of my question whilst at the same time attempting to answer it. Why did you bother if the question is so trivial?. Your answer is not even directed at me, it is a cheap arogant point scroring excercise and very childish. There are people of differing levels of experience and competence that post questions on this forum and it is people like you that most of us in the industry despise. Please feel free to ignore any further questions that I might post, I would rather not have your help. And, your response does not answer my question - try re-reading it. James.
Excuse me, but being overly sensitive and calling people arrogant and childish is what the 'industry' despise. I am suggesting you read the documentation as this is surely the starting point of any programming question. Going by the limited description of your problem I provided an accurate solution which you would also be advised to investigate by reading the relevant MSDN pages. If you still insist that this is 'wrong' then try articulting your question a little more clearly.
-
Excuse me, but being overly sensitive and calling people arrogant and childish is what the 'industry' despise. I am suggesting you read the documentation as this is surely the starting point of any programming question. Going by the limited description of your problem I provided an accurate solution which you would also be advised to investigate by reading the relevant MSDN pages. If you still insist that this is 'wrong' then try articulting your question a little more clearly.
Prior to posting my original question, I had read all the MSDN documentation regarding console functionality. I could not find what I wanted, so I posted the question. If there is anyone that knows if there is a way to set console output to display in a particular colour without having to specify the number of output bytes, ie) to be able to avoid the overhead of having to keep track of the number of bytes written so far? If there is not, then so be it, but if there is, then I would very much like some pointers. James.
-
Prior to posting my original question, I had read all the MSDN documentation regarding console functionality. I could not find what I wanted, so I posted the question. If there is anyone that knows if there is a way to set console output to display in a particular colour without having to specify the number of output bytes, ie) to be able to avoid the overhead of having to keep track of the number of bytes written so far? If there is not, then so be it, but if there is, then I would very much like some pointers. James.
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
-
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
James Thank you for the reply. I do not want an argument and I do appreciate the response, dealing with WIN32 is a nightmare and I really do value your help. I do applogise for calling you arrogant and childish, I just sometimes find it frustrating on this web-site because there are so many people that post questions that are clearly homework and I can understand experienced members like yourself that get tired of the endless ill thought through quick fix demands from those that do want to exhaust other channels before posting a help me help question. I will look into what you have advised and I appreciate the help. Best regards. James. As a point of interest, I cannot believe that you cannot create a console with a default foreground/background output attribute.
-
James Thank you for the reply. I do not want an argument and I do appreciate the response, dealing with WIN32 is a nightmare and I really do value your help. I do applogise for calling you arrogant and childish, I just sometimes find it frustrating on this web-site because there are so many people that post questions that are clearly homework and I can understand experienced members like yourself that get tired of the endless ill thought through quick fix demands from those that do want to exhaust other channels before posting a help me help question. I will look into what you have advised and I appreciate the help. Best regards. James. As a point of interest, I cannot believe that you cannot create a console with a default foreground/background output attribute.
Sorry..that should have been "...from those that do NOT want to exhaust..." Bit of a typo problem there!