VS2005 standard output and Win32 window simultaneously

Started by
5 comments, last by SiCrane 16 years ago
I have a question that I would (out of my relative ignorance of Win32) assume has a fairly simple solution. How can one keep the command line output window default to VS applications after using Win32 to create a GUI? I would like to have it for debugging purposes and upon creating a Win32 window, VS no longer opens this output window.
Advertisement
AllocConsole should do the trick.

Don't forget the cleanup.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks, that's exactly what I wanted, I'll derive streambuf and redirect cout and such to the console.
You don't even need to do that, if you don't want. You can just set your project to link to the console subsystem rather than Windows (it's in the linker settings), and add in the standard "int main" entry-point. Then just make sure your main calls WinMain and you can do all your regular GUI stuff, and stdout will go to the console.
That works as well MJP. I relinked my application with the console subsystem option selected and added the standard int main(...) entry point. At first I wasn't sure what values to use when calling WinMain, but it turns out that most of the values passed are ignored in Windows 2000/NT/XP/Vista (at least from what I read on random posts), so I used WinMain(NULL, NULL, NULL, 0) and my application launched without a problem. So, this should work fine as I have no interest in coding for pre-Windows 2000 machine. Also, this will only be used for debug output . I'm weary of using a precarious setup like that, where I blindly send parameters to WinMain, in a release :).

Thank you both for your replies.
You don't need to fill in the parameters to WinMain if you don't want, since they're all things that you can retrieve anyway through Win32 functions. For example you can get a handle to your app's module (hInstance) by calling GetModuleHandle(NULL). You can get the command line via GetCommandLine. hPrevInstance is always NULL in 32-bit Windows, so you can ignore that completely. The only one that you can't get (or at least, that I don't know how to get) is the nCmdShow parameter. This is supposed to tell your app whether or not to show its main window when being called by another application. But since this is only for a debug build, you obviously don't need to worry about that.
You can nCmdShow by calling GetStartupInfo() and reading the dwFlags and wShowWindow members of the STARTUPINFO structure.

This topic is closed to new replies.

Advertisement