-1

我一直在看这里的教程:http: //msdn.microsoft.com/en-us/library/bb384843.aspx,但我在某一点上真的很困惑。

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

return (int) msg.wParam;

我不知道他们在那里返回做什么。我知道 return 只适用于一个值。为什么有2个东西?我看过其他教程,他们似乎都在使用return msg.wParam;

4

3 回答 3

3

它将值msg.wParam转换为 int。正如您在函数声明中看到的:

int WINAPI WinMain(HINSTANCE hInstance,
               HINSTANCE hPrevInstance,
               LPSTR lpCmdLine,
               int nCmdShow)

返回类型是int. 我不确切知道该属性的类型是什么wParam,但它可能不是一个int,所以它必须显式地转换为一个 int 或者它不会编译。

于 2012-04-13T19:25:52.337 回答
0

该代码可能是返回int. 由于msg.wParam不能隐式转换为int,因此需要显式转换。它基本上相当于:

int ret = (int)msg.wParam;
return ret;
于 2012-04-13T19:28:46.813 回答
0

为什么有2件事

没有两件事:只有变量(类型 为 a )的wParam字段转换为。msgMSGstructint

于 2012-04-13T19:32:27.080 回答