int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpArgs, int iCmdShow)
{
WNDCLASSEX wc;
...
RegisterClassEx(&wc);
const int cx = 640;
const int cy = 480;
// center of the screen
int x = (GetSystemMetrics(SM_CXSCREEN) - cx) / 2;
int y = (GetSystemMetrics(SM_CXSCREEN) - cy) / 2;
CreateWindow(..., x, y, cx, cy, ...);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
但是我在想,如果我把它们放在作用域中,它们是否仍然会在消息循环期间使用内存?例如:
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpArgs, int iCmdShow)
{
{
WNDCLASSEX wc;
...
RegisterClassEx(&wc);
const int cx = 640;
const int cy = 480;
// center of the screen
int x = (GetSystemMetrics(SM_CXSCREEN) - cx) / 2;
int y = (GetSystemMetrics(SM_CXSCREEN) - cy) / 2;
CreateWindow(..., x, y, cx, cy, ...);
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
也许如果我将它们放入两个函数中,并在winmain中调用它们,例如:
wnd_register(hInst);
wnd_create(hInst);
那会阻止他们使用内存吗?