winmain() 函数 / c++

发布于 2024-12-22 07:05:04 字数 192 浏览 3 评论 0原文

您能向我解释一下通常写在 WinMain() 函数末尾的这条语句的意义吗:

   return (int) msg.wParam;

我习惯用 return 0; 结束我的控制台应用程序,是吗? Windows 应用程序错误吗?

谢谢。

can you please explain to me the significance of this statement generally written at the end of the WinMain() function:

   return (int) msg.wParam;

Im used to ending my console applications with return 0; is it wrong for windows applications?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

洒一地阳光 2024-12-29 07:05:04

GetMessage() 循环在收到 WM_QUIT< /a> 窗口消息,通常在调用 PostQuitMessage() 函数,它将其 nExitCode 参数描述为应用程序退出代码

如果您想尊重调用 PostQuitMessage() 函数的人的意图,您应该从 main.c 中返回该值。这就是您在返回从上次调用 GetMessage() 中检索到的 wParam 时所做的事情。

The GetMessage() loop stops after receiving a WM_QUIT window message which is normally issued after a call to the PostQuitMessage() function, which describes its nExitCode parameter as the application exit code.

If you want to respect the intent of the person who invoked the PostQuitMessage() function, you should return that value from main. This is what you are doing when you return the wParam retrieved from the last invocation of GetMessage().

书间行客 2024-12-29 07:05:04

来自 WinMain() 文档 (http ://msdn.microsoft.com/en-us/library/windows/desktop/ms633559.aspx):

当收到WM_QUIT消息时终止消息循环。那时
点,您的 WinMain 应该退出应用程序,返回值
传入 WM_QUIT 消息的 wParam 参数。如果 WM_QUIT
作为调用 PostQuitMessage 的结果接收到 wParam 的值
PostQuitMessage 函数的 nExitCode 参数的值。

From the WinMain() docs (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633559.aspx):

Terminate the message loop when it receives a WM_QUIT message. At that
point, your WinMain should exit the application, returning the value
passed in the WM_QUIT message's wParam parameter. If WM_QUIT was
received as a result of calling PostQuitMessage, the value of wParam
is the value of the PostQuitMessage function's nExitCode parameter.

匿名。 2024-12-29 07:05:04

来自 Google 的第一次点击搜索

你的WinMain应该初始化应用程序,显示它的主
窗口,然后进入消息检索和分发循环,即
应用程序其余部分的顶级控制结构
执行。当收到 WM_QUIT 消息时终止消息循环
信息。此时,您的 WinMain 应该退出应用程序,
返回 WM_QUIT 消息的 wParam 参数中传递的值。
如果调用 PostQuitMessage 后收到 WM_QUIT,则
wParam 的值是 PostQuitMessage 函数的值
nExitCode 参数。有关更多信息,请参阅创建消息
循环。

From the first hit of a Google search

Your WinMain should initialize the application, display its main
window, and enter a message retrieval-and-dispatch loop that is the
top-level control structure for the remainder of the application's
execution. Terminate the message loop when it receives a WM_QUIT
message. At that point, your WinMain should exit the application,
returning the value passed in the WM_QUIT message's wParam parameter.
If WM_QUIT was received as a result of calling PostQuitMessage, the
value of wParam is the value of the PostQuitMessage function's
nExitCode parameter. For more information, see Creating a Message
Loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文