Sign in to follow this  

VS2005 standard output and Win32 window simultaneously

This topic is 3546 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You can nCmdShow by calling GetStartupInfo() and reading the dwFlags and wShowWindow members of the STARTUPINFO structure.

Share this post


Link to post
Share on other sites

This topic is 3546 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this