Feb 28, 2021, 03:31 AM

News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!



Post reply

The message has the following error or errors that must be corrected before continuing:
Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.

Name:
Email:
Subject:
Message icon:
Verification:
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview

Topic Summary

Posted by sukishan
 - Jul 12, 2009, 10:43 PM
Introduction to Frames

As its name implies, a frame of a window includes the borders, the location, and the dimensions of a window. There are two types of MFC applications: those that use a frame and those that don't. A frame-based application uses a concept known as the Document/View Architecture. This allows the frame to serve as a place holder for other parts of an application (such as the document and the view).

To create a frame, the MFC library provides various classes. One of these is called CFrameWnd and it is the most commonly used frame class. To use a frame, you can derive your own class from CFrameWnd as follows:


class CApplicationFrame : public CFrameWnd
{

};

Because there can be many frames or various types of frames in an application, the first or main frame is usually called CMainFrame, we will follow the same habit but you can call your frame class anything you want:

class CMainFrame : public CFrameWnd
{
};


The skeleton of this frame only serves as a foundation for your class. You must actually create a window frame that would display to the user. To create a window frame, the CFrameWnd class provides the Create() method. Its syntax is:

BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
       DWORD dwStyle = WS_OVERLAPPEDWINDOW, const RECT& rect = rectDefault,
       CWnd* pParentWnd = NULL, LPCTSTR lpszMenuName = NULL, DWORD dwExStyle = 0,
       CCreateContext* pContext = NULL );


As you can see, the only two required arguments are the class name and the window name. We will come back to all these arguments when we study window classes in more detail. For now, a minimum frame can be created by simply passing the class name as NULL and the window name with a null-terminated string. Here is an example:

class CMainFrame : public CFrameWnd
{
public:
    CMainFrame();
};

CMainFrame::CMainFrame()
{
    Create(NULL, "MFC Fundamentals");
}


In order to provide a window to the application, you must create a thread. This would be done using the CWinThread class. To make this a little easy, CWinThread is equipped with a public member variable called m_pMainWnd. This variable can be used to create a thread for the main window of the application. One of its advantages is that it makes sure that your application terminates smoothly when the user decides to close it. CWinThread is the base class of CWinApp and therefore makes m_pMainWnd available to any CWinThread derived class such as CFrameWnd. Based on this, to create a thread for the main window to display, you can assign a pointer of your frame class to m_pMainWnd. After this assignment, m_pMainWnd can be used as the window object to display the frame, which is usually done by calling the ShowWindow() method. This would be done as follows:

BOOL CExerciseApp::InitInstance()
{
    m_pMainWnd = new CMainFrame;
    m_pMainWnd->ShowWindow(SW_NORMAL);

    return TRUE;
}
IT Acumens Web Designing Chennai | GinGly :: Build your Personal Website | CineBuzz :: Cinema News | My Kids Diary :: Gift your Kids Memories :: Book Website @ 349 Rs monthly
Copyright 2005 - 2021 :: IT Acumens :: All Rights Reserved. :: XML Sitemap
ITAcumens Discussion Forum with 2 lakhs post running for 15 years - Powered by IT Acumens Pro Dedicated Server

My Kids Diary