Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals


WndClsEx.lpszClassName = StrClassName;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

RegisterClassEx(&WndClsEx);

hWnd = CreateWindowEx(0,
StrClassName, );

return 0;
}
//---------------------------------------------------------------------------


  1. Save All


10.2.3..The Window Name.............................................................................


We saw in Lesson 2 that every window should have a name to easily identify it. For a
main window, the name displays on the title bar of the frame.

The name is passed as the lpWindowName argument of either the CreateWindow() or
the CreateWindowEx() functions. To do this, you can provide a null-terminated string to
the argument or declare a global string. Here is an example:

const char *ClsName = "WndFund";
const char *WndName = "Application Name";

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM
lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS WndCls;

...


RegisterClass(&WndCls);

CreateWindow(ClsName, WndName,
}

If you are creating an MFC application, to provide a name for the window, pass a null-
terminated string as the second argument of the CFrameWnd::Create() method:

CMainFrame::CMainFrame()
{
WNDCLASS WndCls;
const char *StrWndName = "Application Name";

...


const char *StrClass = AfxRegisterWndClass(WndCls.style, WndCls.hCursor,
WndCls.hbrBackground, WndCls.hIcon);

Create(StrClass, StrWndName);
}
Free download pdf