1. 注册窗口
WNDCLASSEX wndClass;
memset(&wndClass, 0, sizeof(WNDCLASSEX));
wndClass.cbSize = sizeof(wndClass);
wndClass.style = CS_VREDRAW | CS_HREDRAW;
wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndClass.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wndClass.lpszClassName = _T("CELLWinApp");
wndClass.lpfnWndProc = myWindowProc;
wndClass.hIcon = LoadIcon(NULL, IDI_ERROR);
wndClass.lpszMenuName = 0;
wndClass.hInstance = mInstance;
RegisterClassEx(&wndClass);
2.创建窗口
mHwnd = CreateWindow(_T("CELLWinApp"), _T("CELLWinApp"), WS_OVERLAPPEDWINDOW, 0, 0,
width, height, 0, 0, mInstance, this);
if (mHwnd == 0) {
goto END;
}
3. 更新并显示
UpdateWindow(mHwnd);
ShowWindow(mHwnd, SW_SHOW);
4.创建消息循环
while (GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
5. 消息循环简单实现
LRESULT CALLBACK CELLWinApp::myWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_CLOSE:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}