HowTo hide Console Window with WinAPI?

余生颓废 提交于 2019-12-01 14:25:59

Just call FreeConsole() get rid of it and AllocConsole() to create a new one.

You'd do better to create a new Visual Studio project based on 'Win32 Project' instead of 'Win32 Console Application'. Then a console will not be created automatically. (You can still create one in code if you want to.) This will set the /SUBSYSTEM:WINDOWS compiler setting amongst others.

You don't have to create a GUI in a non-console application, and you don't have to have a WndProc() function.

In response to "@Ian Goldby Could you give me the link to the source code of how to do that?"

There isn't any source code as such. Just create a new Visual C++ Win32 Project (not Win32 Console Application). In the Wizard make sure 'Windows application' is selected. The wizard will generate lots of template code, but you can delete all of this except for the skeleton of the _tWinMain() function. This is the function that will be called when your application starts up. Just paste your own code in here.

Alternatively, check the 'Empty project' box in the last stage of the wizard, and supply your own main.c file and your own _tWinMain() function. You might find this easier.

Either way, your application will run just as before except that, because it is a GUI application rather than a Console application, the OS won't automatically create a Console window for it when it starts up. (So obviously functions like printf/scanf etc won't work.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!