Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows
LPSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX WndClsEx;
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProc;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hInstance = hInstance;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_CROSS);
WndClsEx.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
return 0;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
//---------------------------------------------------------------------------
- Save All
10.1.7..Window Registration..........................................................................
After initializing the window class, you must make it available to the other controls that
will be part of your application. This process is referred to as registration. If you are
creating a Win32 application using the WNDCLASS structure, to register the window
class, call the RegisterClass(). If you created your window class using the
WNDCLASSEX structure, call the RegisterClassEx() function. Their syntaxes are:
ATOM RegisterClass(CONST WNDCLASS *lpWndClass);
ATOM RegisterClassEx(CONST WNDCLASSEX *lpwcx);
The function simply takes as argument a pointer to a WNDCLASS or WNDCLASSEX.
If you are working on an MFC application, to register your window class, call the
AfxRegisterWndClass() function. Its syntax is:
LPCTSTR AFXAPI AfxRegisterWndClass(UINT nClassStyle, HCURSOR hCursor = 0,
HBRUSH hbrBackground = 0, HICON hIcon = 0);
This function expects the window class, the cursor to use to indicate the position of the
mouse, the color to paint the background, and an icon that represents the application.