【发布时间】:2015-09-17 10:46:12
【问题描述】:
我已经阅读了十多页,解释了如何将 Win32 控制台应用程序转换为无需短暂打开和关闭控制台窗口即可运行的 Windows 应用程序,但我太初学者了,无法让它工作.
例如,在 VC2010 中,我在此处描述的项目属性中进行了两项更改:
convert a console app to a windows app
并将 Main 更改为 WinMain,但当然会从编译器收到错误消息。
在其他页面之后,我还尝试创建一个控制台应用程序,然后在 Win32 应用程序向导中,并将应用程序类型更改为 Windows 应用程序,但我不知道下一步该做什么。我尝试将 int Main 更改为 int CALLBACK WinMain,但这当然也不起作用。
有没有人可以帮助初学者解决这个问题?这是我认为我的代码编辑的相关部分:完整的代码,对于任何想知道这是做什么的人来说,在这里:
https://www.dropbox.com/s/1h8x1k2zv0lc5d1/vPasteCPlus.txt?dl=0
#include <stdafx.h>
#include <windows.h>
#include <iostream>
#include <fstream>
#include <codecvt> // for wstring_convert
#include <locale> // for codecvt_byname
using namespace std;
// helper to get path to this application
string ExePath() {
char buffer[MAX_PATH];
GetModuleFileNameA( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
return string( buffer ).substr( 0, pos);
}
int main(int argc, char* argv[])
{
// get the command-line argument if any, and do various things
}
再次为这个初学者问题道歉。我对 C++ 的唯一经验是编写控制台应用程序,我们将不胜感激地接受任何建议。
【问题讨论】:
-
“无需短暂打开和关闭控制台窗口即可运行的应用程序”。我知道有数以千计的合法用途......但我不禁想知道......
-
and changed Main to WinMain but of course got error messages from the compiler.有什么错误?此外,您可以从一个 Windows 应用程序开始,而不创建任何窗口。 -
或者,您可以使用this program 使用隐藏窗口启动您的控制台程序。