LuvSea

[MFC 기초] 자동생성 클래스 분석 - CMainFrame 본문

sTudy

[MFC 기초] 자동생성 클래스 분석 - CMainFrame

사랑海 2009. 10. 13. 19:49
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
[출처] http://myhome.hanafos.com/~log0/mfc/mfc04.htm
CMainFrame클래스 Mainfrm.cpp를 열어보면 앞의 CWinApp에서 다루어 본 BEGIN_MESSAGE_MAP가 또 나오는데, 앞의 것과 틀린것은 없다.



BEGIN_MESSAGE_MAP(CMainFrame. CFrameWnd) 

//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the Classwizard will add and remove
mapping macros here.
// DO NOT EDIT what you see in these blocks
of generated code !
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

아래의 indicators는 상태창에 나타나는 string의 ID값이다.
ID_SEPARATOR는 라인을 그어서 분리시키고 ID_INDICATOR_CAPS는 CapsLock키를, ID_INDICATOR_NUM은
NumLock키를, ID_INDICATOR_SCRLS는 SrollLock키를 각각 ON/OFF 상태를 확인하는 ID이다.
프로그램 실행시 키들을 눌러보면 상태창 오른쪽에 나타난다.


static UNIT indicators[] =
{ 
    ID_SEPARATOR, //status line indicator
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL, 
}; 


CMainFrame::CMainFrame()
{ 
    // TODO: add member initialization code here 
}
// 메인 프레임의 생성자이다.  현재는 비어 있는 상태이다. 


CMainFrame::~CMainFrame()
{
} 
// 다음은 메인프레임의 소멸자입니다.


OnCreate 함수는 메인 프레임이 만들어질 때 실행된다.
아버지 클래스인 CFrameWnd것을 사용하지 않고 자기 것, 즉 virtual로 사용한다는 것.

int CMainFrame::OnCreate(LPCREATESTRUCT 1pCreateStruct)
{
    //아버지 클래스의 OnCreate를 먼저 실행하고
    if (CFrameWnd:: OnCreate(1pCreateStruct) == -1) 
        return -1; 
    
    //도구바를  만들고
    if (!m_WndToolBar.Create(this) || !m_WndToolBar.LoadToolBar(IDR_MAINFRAME)) 
    { 
        TRACEO("Failed to create toolbar\n");
        return -1;       // fail to create 
    }

    //상태창을 만들고
    if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UNIT))) 
    { 
        TRACEO("Failed to create status  bar\n");
        return -1;       // fail to create 
    }
    // TODO: Delete these there three lines if you don't want the toolbar to
    //br dockable 
아래의 코드는 메뉴바를 도킹 가능한 메뉴바로 만드는 코드이다. 이 또한 이 프로젝트 AppWizard
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY); 

return 0; 

CWinApp클래스에서 CMainFrame 프로그램이 실행될 수 있도록 프레임을 로드하였다.
CMainFrame의 OnCreate 함수는 CWinApp의 Initinstance 함수의 if(!pMainFrame->LoadFrame(IDR_MAINFRAME)) 가 실행되면 후에 수행되는 함수이다.
OnCreate 함수는 실행될 때 필요한 여러 가지 일을 수행 하는 함수이고,
위의 내용은 메인 프레임에 있는 메뉴와 도구바 그리고 상태창 등을 메인 프레임에 등록하는 것이다.
지금까지 내용으로 CWinApp 클래스에서 메인 프레임을 만들고 CMainFrame에 도구바와 메뉴와 상 태바를 등록했다.
Comments