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()
基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
