Author Topic: Small bug in Win GUI Project wizard  (Read 8134 times)

cpprooky

  • Guest
Small bug in Win GUI Project wizard
« on: August 02, 2006, 03:25:40 pm »
When I create à Win32 GUI project, in the Project properties, the build target type is set to "Console application" instead of "GUI application" ! This is not a very important bug, I agree, but that's boring to have to change that setting for every new project !
could you change that easily ?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Small bug in Win GUI Project wizard
« Reply #1 on: August 02, 2006, 05:14:10 pm »
could you change that easily ?
No, because it's not a bug but a feature. If you look into it, only the debug target is set to be a console project. This is on purpose as many debug information you issue within a GUI application are actually send to the console. This is a usual concept (have a look at several debug macros) and if you declare the debug target as GUI application you would not see the messages printed to the console.
So we won't chnage this because it's by design. Anyway, if you don't like this feature you can disable it in the wizard script easily. Just right-click on the script, edit it and change the debug target creation to how it's done in the release target:
Change the line:
Code
        target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
into:
Code
        target.SetTargetType(ttExecutable); // ttExecutable: no console

With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Small bug in Win GUI Project wizard
« Reply #2 on: August 02, 2006, 09:58:23 pm »
you have to say additionally, that debug info sent to the console stdout is working in linux,
but not in windows, where this console is quite useless.
(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)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Small bug in Win GUI Project wizard
« Reply #3 on: August 02, 2006, 10:18:49 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)
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.)
« Last Edit: August 02, 2006, 10:28:41 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

takeshimiya

  • Guest
Re: Small bug in Win GUI Project wizard
« Reply #4 on: August 03, 2006, 02:16:55 am »
A solution to redirect output to the console in Windows is:

  • For example in SDL, which by default redirects to a file, just add this below main():
Code: cpp
freopen("CON", "wt", stdout); // redirects stdout
freopen("CON", "wt", stderr); // redirects stderr
« Last Edit: August 03, 2006, 02:19:41 am by Takeshi Miya »

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Small bug in Win GUI Project wizard
« Reply #5 on: August 03, 2006, 04:35:31 am »
(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)
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.)

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.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Small bug in Win GUI Project wizard
« Reply #6 on: August 03, 2006, 08:17:17 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.

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
}
Be patient!
This bug will be fixed soon...

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Small bug in Win GUI Project wizard
« Reply #7 on: August 03, 2006, 08:25:31 am »
@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

  • Guest
Re: Small bug in Win GUI Project wizard
« Reply #8 on: August 03, 2006, 09:13:36 am »
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 !!

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Small bug in Win GUI Project wizard
« Reply #9 on: August 03, 2006, 11:12:16 am »
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
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]
« Last Edit: August 03, 2006, 11:15:21 am by tiwag »

hairy

  • Guest
Re: Small bug in Win GUI Project wizard
« Reply #10 on: November 10, 2006, 06:39:59 pm »
can u teach me how to use this GUI application