Click here to Skip to main content
15,914,444 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Loading small, built-in icons Pin
14-Jun-01 8:03
suss14-Jun-01 8:03 
GeneralRe: Loading small, built-in icons Pin
Ben Burnett14-Jun-01 9:19
Ben Burnett14-Jun-01 9:19 
Generalprint preview and multi frame app Pin
SAWilde14-Jun-01 6:35
SAWilde14-Jun-01 6:35 
GeneralSplitter window using C and NOT C++ Pin
14-Jun-01 6:33
suss14-Jun-01 6:33 
GeneralRe: Splitter window using C and NOT C++ Pin
Tomasz Sowinski15-Jun-01 0:01
Tomasz Sowinski15-Jun-01 0:01 
Generalarray of checkboxes Pin
14-Jun-01 6:18
suss14-Jun-01 6:18 
GeneralRe: array of checkboxes Pin
Carlos Antollini14-Jun-01 6:27
Carlos Antollini14-Jun-01 6:27 
Generalfine, don't answer my question, see if i care Pin
Amit Jain14-Jun-01 5:29
Amit Jain14-Jun-01 5:29 
Previously I asked if there was a way to separate the colors for stdout & stderr when writing to a console. I never got a response. Cry | :(( So in the unlikely event someone else was wondering about this, check it:

You need these headers:

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

When you fire up a console (using AllocConsole(), and when you're done call FreeConsole()), get the stdout & stderr handles by doing:

HANDLE hStdOutput;
HANDLE hStdError;

Then you can use the following routine just like fprintf. Now, if your routine is doing a ton of processing and suddenly an error pops up, your machine hangs, then reboots itself, you'll have a shot at seeing what went wrong! (especially when the reboot tends to wipe your logs)

//only goes to stdout or stderr!!!
int myfprintf(FILE *stream, const char *format, ...)
{
DWORD numwritten;
char *str;
va_list args; //variable argument list
va_start(args, format);

str = new char[strlen(format)*10 + 1]; // <- you're screwed if this isn't enough mem
//sprintf(str, "%s", format);
memset(str, '\0', sizeof(char));
vsprintf(str, format, args);

if (stream == stdout)
{
SetConsoleTextAttribute (hStdOutput, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
WriteConsole (hStdOutput, str, strlen (str), &numwritten, NULL);
}
else if (stream == stderr)
{
SetConsoleTextAttribute (hStdError, FOREGROUND_GREEN);
WriteConsole (hStdError, str, strlen (str), &numwritten, NULL);
}
delete[] str;
return (numwritten);
}

I've only tried this on NT Workstation 4 & Win98se, lemme know what you think... Rose | [Rose]

--
Peace,
Amit Jain
GeneralRe: fine, don't answer my question, see if i care Pin
Tim Deveaux14-Jun-01 14:59
Tim Deveaux14-Jun-01 14:59 
GeneralRe: fine, don't answer my question, see if i care Pin
Amit Jain15-Jun-01 4:13
Amit Jain15-Jun-01 4:13 
GeneralSerialization question Pin
mr200314-Jun-01 4:15
mr200314-Jun-01 4:15 
GeneralRe: Serialization question Pin
Ben Burnett14-Jun-01 8:01
Ben Burnett14-Jun-01 8:01 
GeneralRe: Serialization question Pin
markkuk14-Jun-01 20:46
markkuk14-Jun-01 20:46 
Questionhow to set the IP address during programming Pin
14-Jun-01 3:07
suss14-Jun-01 3:07 
AnswerRe: how to set the IP address during programming Pin
Carlos Antollini14-Jun-01 4:26
Carlos Antollini14-Jun-01 4:26 
AnswerRe: it's tough! Pin
Masaaki Onishi14-Jun-01 6:55
Masaaki Onishi14-Jun-01 6:55 
GeneralRe: it's tough! Pin
15-Jun-01 1:53
suss15-Jun-01 1:53 
GeneralRe: it's tough! Pin
Masaaki Onishi15-Jun-01 3:59
Masaaki Onishi15-Jun-01 3:59 
GeneralCompare structures Pin
User 665814-Jun-01 1:36
User 665814-Jun-01 1:36 
GeneralRe: Compare structures Pin
Monty14-Jun-01 2:15
Monty14-Jun-01 2:15 
GeneralRe: Compare structures Pin
Bryan Pietrzak14-Jun-01 12:16
Bryan Pietrzak14-Jun-01 12:16 
GeneralRe: Compare structures Pin
Monty14-Jun-01 20:48
Monty14-Jun-01 20:48 
GeneralRe: Compare structures Pin
Bryan Pietrzak15-Jun-01 3:59
Bryan Pietrzak15-Jun-01 3:59 
GeneralCListCtrl tooltips behind the dialog box Pin
Monty14-Jun-01 1:31
Monty14-Jun-01 1:31 
GeneralRe: CListCtrl tooltips behind the dialog box Pin
Tomasz Sowinski14-Jun-01 2:02
Tomasz Sowinski14-Jun-01 2:02 

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.