如何使用 Visual Studio 2010 在 Win32 项目中隐藏控制台窗口 [英] How to hide the console window in a Win32 project using Visual Studio 2010

查看:43
本文介绍了如何使用 Visual Studio 2010 在 Win32 项目中隐藏控制台窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在应用程序启动期间创建一个没有控制台窗口或(任何其他窗口)的 exe 应用程序.

I need to create an exe application with no console window or (any other window) during the start up of the application.

我为此尝试了以下方法:

I tried the below for this:

  1. 使用 Visual Studio 2010 创建了一个 Win32 控制台应用程序作为一个空项目.
  2. 在项目中添加了一个头文件stdafx.h"
  3. 向项目添加了一个 cpp 文件并添加了以下代码.
  4. 项目设置是默认的visual stduio.

  1. Using Visual Studio 2010, created a Win32 Console Application as an Empty Project.
  2. Added a header file "stdafx.h" to the project
  3. Added a cpp file to the project and added the below code.
  4. The project settings are visual stduio default.

#include "stdafx.h"
#include <windows.h>  
#include "TlHelp32.h"
#include <iostream>
#include <string>
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{

        return 0;
}

以上代码编译良好.

但是如果我将字符集更改为使用 Unicode 字符集",则会出现以下编译错误.

But if I change the Character Set to "Use Unicode Character Set", I am getting the following compilation error.

错误 C2731:'WinMain':函数不能重载

error C2731: 'WinMain' : function cannot be overloaded

我正在 Windows 7 64 位计算机和 Visual Studio Build 平台作为 x64 构建应用程序.

I am building the application on a Windows 7 64 bit computer and Visual Studio Build platform as x64.

预先感谢您的帮助.

推荐答案

是的,当您使用有效的 UNICODE 构建时,入口点采用 Unicode 字符串作为命令行参数.所以这需要一个不同的声明:

Yes, when you build with UNICODE in effect then the entrypoint takes a Unicode string for the command line argument. So that requires a different declaration:

  int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                        LPWSTR lpCmdLine, int nShowCmd)

或者您可以使用 #include <tchar.h> 以便它以任何方式工作,这些天没有太多意义:

Or you can use #include <tchar.h> so it works either way, not much point to it these days:

  int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                         LPTSTR lpCmdLine, int nCmdShow)

这篇关于如何使用 Visual Studio 2010 在 Win32 项目中隐藏控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆