呼啦。
我有一个关于放置'销毁功能'的问题。
全局:
HWND g_hInvisible = NULL;
HINSTANCE g_hInstance = NULL;
WinMain代码:
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR lpCmdLine,INT nShows)
{
MSG msg = {0};
WNDCLASSEXW wcMain = {0};
wcMain.cbSize = sizeof(WNDCLASSEXW);
wcMain.style = CS_SAVEBITS;
wcMain.lpfnWndProc = MainWindowProc;
wcMain.hInstance = g_hInstance;
wcMain.lpszClassName = L"MAINCLASS";
RegisterClassEx(&wcMain);
HWND hMainWindow = CreateWindowEx(0, L"MAINCLASS", L"Main Class Window", WS_OVERLAPPEDWINDOW, 100, 100, 100, 100, NULL, NULL, g_hInstance, NULL);
InvisibleWindowInit();
InvisibleWindowTerminate(); // <<< PLACE HERE ?
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
InvisibleWindowTerminate(); // <<< OR PLACE HERE ?
return (int) msg.wParam;
}
InvisibleWindowInit的代码:
BOOL InvisibleWindowInit()
{
WNDCLASSEXW wcInvisible = {0};
wcInvisible.cbSize = sizeof(WNDCLASSEXW);
wcInvisible.style = CS_SAVEBITS;
wcInvisible.lpfnWndProc = InvisibleWindowProc;
wcInvisible.hInstance = g_hInstance;
wcInvisible.lpszClassName = L"INVISIBLE";
RegisterClassEx(&wcInvisible);
g_hInvisible = CreateWindowEx(0, L"INVISIBLE", L"INVISIBLE", WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, g_hInstance, NULL);
if (g_hInvisible == NULL)
{
dError = GetLastError();
return FALSE;
}
return TRUE;
}
InvisibleWindowTerminate的代码:
VOID InvisibleWindowTerminate()
{
DestroyWindow(hInvisible);
g_hInvisible = NULL;
}
我想在另一段代码中调用 InvisibleWindowTerminate
那么在消息循环之前或之后哪个地方更好?
谢谢。