Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 3: Windows Resources



  1. After viewing the window, close it and return to MSVC.


3.9.3 Frame Loading........................................................................................


So far, in order to create a window, we learned to use the CFrameWnd::Create()
method. Because that method does not recognize resources, we resolved to use the
AfxRegisterWndClass() function to register the necessary resources before calling the
CFrameWnd::Create() method. The MFC library provides another, simpler, technique
to create a window. This is done using the CFrameWnd::LoadFrame() method.

To create a window with one simple call, first create the necessary resources, namely an
accelerator table, a menu, an icon, a string table (and possible a toolbar). The only rule to
follow is that all of these resources must have the same name. As a habit, the common
name used for resources is IDR_MAINFRAME.

The syntax of the LoadFrame() method is:

BOOL LoadFrame(UINT nIDResource,
DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,
CWnd* pParentWnd = NULL,
CCreateContext* pContext = NULL );

The only required argument to the LoadFrame() method is the identifier shared by the
resources. Like the Create() method, you can use LoadFrame() to specify the style of
the window. Its characteristics are specified as the dwDefaultStyle argument. If this
window has a parent, you can specify it using the pParentWnd argument.

Practical Learning: Loading a Frame



  1. Create a new project named Frame Loader and stored in C:\Programs\MSVC
    Exercises
    Make sure you create it as a Windows Application with an Empty Project

  2. Access the application's settings or properties and specify that you want to use MFC
    As A Shared DLL

Free download pdf