您的位置:首页 > 产品设计 > UI/UE

Convert a console project into a Win32 GUI project or the other way around.

2011-06-24 22:50 302 查看
Jeffrey Richter mentioned in his classical Programming application for Windows, 4th edition that if a developer made a mistake by creating a Win32 project when what he really meant was a Console project, he has at least the following 2 options to fix it. (Jeffery Richter mentioned 4 options actually. But the first 2 are not interesting at all.)

Click on the Link tab of the Project Settings dialog box and change the /SUBSYSTEM:WINDOWS switch to /SUBSYSTEM :CONSOLE. This is an easy way to fix the problem; few people are aware that this is all they have to do.

Click on the Link tab of the Project Settings dialog box and delete the /SUBSYSTEM:WINDOWS switch entirely. This is my favorite choice because it gives you the most flexibility. Now, the linker will simply do the right thing based on which function you implement in your source code. I have no idea why this isn't the default when you create a new Win32 Application or Win32 Console Application project with Visual C++'s Developer Studio.

Reader may come to the conclusion that the project type, or consequently the application type, is determined by the entry point function name you choose. If you use main(), you'll get a console project and get an console application in the end, if you choose WinMain(), you'll get a Win32 project and a Win32 application in the end.

 

Not necessarily. The above statement is only true when the /ENTRY option is not used for the linker. With this option, you can specify any function name as the Entry Point Function of your application. If you do so, whether your application will be a console application or a Win32 application will be solely determined by the /SUBSYSTEM option.

 

This means, it's completely OK to have a GUI application that starts with a main() function. It's also completely OK to have a console application that starts with a WinMain() function. Name doesn't matter!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐