Replacing WinMain() with main() function in Win32 programs(在 Win32 程序中用 main() 函数替换 WinMain())
问题描述
我在 StackOverflow 和 Google 上搜索了一点,但没有找到这个想法.我想用这种类型的用户编程来启动我的应用程序:
I searched a little bit on StackOverflow and Google but couldn't get the idea. I want to start my application with this type of user programming:
int main()
{
Window App("Test", 640, 480);
while(App.IsOpen())
{
// Do the stuff
}
}
但这是不可能的,因为我应该将 hInstance 和 hPrevInstance 和其他参数传递给 WinMain 函数.实际上,我设计了一个 Window 类,使窗口创建更容易一些.我在 SFML 上看到了这个实现,但我不知道它是怎么做到的.
But this isn't possible because I should pass the hInstance and hPrevInstance and other parameters to a WinMain function. Actually there is a Window class which I designed to make the window creation a little bit easier. I saw this implementation on SFML but I don't know how it did come to this.
现在我使用的是通常的方式:
Right now I'm using the usual way:
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR, int)
{
Window App(hInst, hPrevInst, "Test", 640, 480);
while(App.IsOpen())
{
// Do the stuff
}
}
谢谢.
推荐答案
您可以在windows"中使用标准的 main应用程序(即 GUI 子系统 Windows 应用程序),即使使用 Microsoft 工具,如果您将以下内容添加到 Microsoft 链接器选项:
You can use standard main in a "windows" app (that is, a GUI subsystem Windows application) even with the Microsoft tools, if you add the following to the Microsoft linker options:
/subsystem:windows /ENTRY:mainCRTStartup
请注意,这对于 GNU 工具链来说不是必需的.
Note that this is not necessary for the GNU toolchain.
对于 Microsoft 工具,您也可以将其添加到主文件中:
Still for the Microsoft tools you can alternatively add this to your main file:
#ifdef _MSC_VER
# pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
James McNellis 告诉您如何获取 hInstance.
James McNellis tells you how to get the hInstance.
这篇关于在 Win32 程序中用 main() 函数替换 WinMain()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Win32 程序中用 main() 函数替换 WinMain()
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
