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()


基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07