Advertisement

Color is reverting back on its own?

Started by July 09, 2002 07:02 PM
8 comments, last by KTurner 22 years, 2 months ago
Hey, I''ve got a problem here I just can''t seem to get to the bottom of. I''m using Dev C++. I''m using the following to change the text color... HANDLE OutputH; OutputH = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(OutputH, 2); The program is a dos console program I am developing. I have various other calls to SetConsoleTextAttribute with other colors when neccesary as well. Everything appears to work fine except that during one specific routine the text color starts changing to the default color (7) I think on its own! It even will start changing halfway into a word. Then it will eventually revert back to the color I set again. This is really weird. Even if I put a call to SetConsoleTextAttribute DIRECTLY before the cout call, It still will return the default color. Any ideas? My only thought is some kind of memory issue or something? Thanks for any help you can give me... Keith
quote: Original post by KTurner
Everything appears to work fine except that during one specific routine...


if it only happens in that specific routine. the problem is probably there. could you post the code for that routine.

-me

Advertisement
Try flushing the output buffer before changing the colors:

cout.flush();
or
cout << flush;

PaladinGLT
PaladinGLT
Well I''m at work right now and when I run the program here, on a Windows 2000 computer, the problem is gone. However at home, on a Windows 98 computer, the problem still occurs.

Now I know that Windows 98 runs an actual representation of DOS compared to Windows 2000''s emulation. I am still curious if it is a memory issue due to the fact that it runs in a DOS window in Windows 98.

I am pretty sure I tried flushing the output buffer and then changing the color immediately right before the problem area.
When I get home I will run the program and post the code for that area if you think it will help...

I still find it odd that anything would cause the middle of say
cout << "This is a test statement";
to start changing colors halfway through writing the word test. It seems like a buffer problem or memory issue.

Thanks for any more input anyone can give me on this. It''s really disappointing me that I can''t give my program the appearance I want it to have!

Does it happen in both fullscreen and windowed mode?

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
This has happened to me before. I think you just need to flush the buffer like others have already said.
Advertisement
Still having the same trouble even with the cout << flush I''m afraid. I would post the code but it wouldn''t really show too much. It would be hard to follow without the classes and class functions it uses anyway, and the entire code is a bit long to post on this board.

Any other suggestions out there? Again, it looked fine when run on Windows 2000. It''s Windows 98 that is giving me the trouble. It happens during a loop which call two class functions from two different classes I created. It will suddenly change to the default system color in mid sentence like I said. As always, your help is appreciated!

are you using threads?

do the classes dictate the color? if so they could be switching things on you. do a search on issues with cout and windows consoles. i know there is a cprintf() function specifically made for windows consoles.

i assume you are sure that there are no buffer overruns or anything else funky? also win2k uses unicode by default (ie when you compile), win98 does not. possibly enabling (or disabling) the use of unicode in the app may fix the problem.
try
SetConsoleTextAttribute(outputh, FOREGROUND_BLUE | FOREGROUND_RED | BACKGROUND_GREEN);
a person,

How would I go about enabling unicode in Windows 98?

This topic is closed to new replies.

Advertisement