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

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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值