Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
These are the same values used to initialize the window class. Using these values as
initialized above, you can register the window class as follows:
CMainFrame::CMainFrame()
{
// Declare a window class variable
WNDCLASS WndCls;
WndCls.style = CS_VREDRAW | CS_HREDRAW;
WndCls.lpfnWndProc = AfxWndProc;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hInstance = AfxGetInstanceHandle();
WndCls.hIcon = AfxGetApp()->LoadStandardIcon(IDI_WARNING);
WndCls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
WndCls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WndCls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
AfxRegisterWndClass(WndCls.style, WndCls.hCursor,
WndCls.hbrBackground, WndCls.hIcon);
}
Practical Learning: Registering a Window
- Just above the return line of the WinMain() function, register the class using the
RegisterClassEx() function:
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX WndClsEx;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&WndClsEx);
return 0;
}
//---------------------------------------------------------------------------
- Save All
10.2 Window Creation.........................................................................................
10.2.1..The Main Window..............................................................................
The WNDLCLASS and the WNDCLASSEX classes are only used to initialize the
application window class. To display a window, that is, to give the user an object to work
with, you must create a window object. This window is the object the user uses to interact
with the computer.