User forums > Help

Small bug in Win GUI Project wizard

<< < (2/3) > >>

tiwag:

--- Quote from: MortenMacFly on August 02, 2006, 10:18:49 pm ---
--- Quote from: tiwag on August 02, 2006, 09:58:23 pm ---(there are existing some tricks, how you can redirect stdout to this console window,
but it is not standard and doesn't work with the supplied samples)

--- End quote ---
That's right, I for myself use a concept similar to http://www.codeproject.com/debug/debugcon.asp for debugging to the console within a Win32 application but yes, within the Win32GUI example this is not done, indeed.

(Edit: What I mean hereby is that there are often other methods used within Win32 indeed.)

--- End quote ---

what i've meant was, that in linux you can use a number of puts("debug message"); in your GUI program
and you'll see them printed in the console (if it exists or you start your program from a console)
and you can redirect them to a file for your debug purposes.

in windoze this does not work by default, if you doesn't create your own debug-console in your program,
you have to catch the already existing consoles PID and then you can redirect stdout to that window ...
then it "works"

i saw some code for this in the past somewhere, but i can't find it at the moment ... i have to look for again.

mandrav:

--- Quote from: tiwag on August 03, 2006, 04:35:31 am ---i saw some code for this in the past somewhere, but i can't find it at the moment ... i have to look for again.

--- End quote ---


--- Code: (cpp) ---void CodeBlocksApp::InitDebugConsole()
{
#ifdef __WXMSW__
    #ifdef __CBDEBUG__
        // Remember to compile as a console application!
        AllocConsole();
        HANDLE myhandle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD co = {80,2000};
SetConsoleScreenBufferSize(myhandle, co);
fprintf(stdout,"CONSOLE DEBUG ACTIVATED\n");
// wxLogWindow *myerr = new wxLogWindow(NULL,"debug");
    #endif
#endif
}

--- End code ---

tiwag:
@mandrav
your code produces a new console window in any case, isn't it ?

there exists another trick that you compile your program as normal GUI program,

then it checks, if it was started from a console window,
and if this is the case, it redirects stdout & stderr to this
already existing console window.

then you have a normal gui program,
and when started from a console, you get all your debug messages
which you simply send with puts() or printf()

cpprooky:
I see ! That's OK for me
I must say that your last messages goes widely over my knowledges !! So, I'll accept this is a good thing for debug target !!

tiwag:
ok i've found the solution in order to give Win32-GUI-apps a linux-like behaviour ( but it needs at least WinXP )

with AttachConsole()

--- Code: ---    AttachConsole(ATTACH_PARENT_PROCESS);
    freopen("CON", "wt", stdout); // redirects stdout

--- End code ---
you can attach the GUI app to an existing console window, if there exists one,
with other words, if it was started from the commandline from a console window.

attached is a sample project which demonstrates this

run the Release build from a console window and enjoy the debug messages :D


the code which i can't find anymore did that AttachConsole-stuff also for older Windozes like Win98, ME, NT etc...
if you use MinGW-win32api-3.7 the headers already contain the needed defines,
otherwise i've added them to the code and you need to enable them.

[attachment deleted by admin]

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version