www.pudn.com > fanccMSNr.src.rar > MainFrm.cpp
// MainFrm.cpp : CMainFrame Ŭ·¡½ºÀÇ ±¸Çö
//
#include "stdafx.h"
#include "DumbMessenger.h"
#include "LoginDialog.h"
#include "NotConnectedView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CLOSE()
ON_WM_CREATE()
END_MESSAGE_MAP()
// CMainFrame »ý¼º/¼Ò¸ê
CMainFrame::CMainFrame()
{
currentView=NULL;
}
CMainFrame::~CMainFrame()
{
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: CREATESTRUCT cs¸¦ ¼öÁ¤ÇÏ¿© ¿©±â¿¡¼
// Window Ŭ·¡½º ¶Ç´Â ½ºÅ¸ÀÏÀ» ¼öÁ¤ÇÕ´Ï´Ù.
return TRUE;
}
// CMainFrame Áø´Ü
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame ¸Þ½ÃÁö 󸮱â
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
// ±âº» Ŭ·¡½º°¡ ½ÇÁ¦ ÀÛ¾÷À» ¼öÇàÇÕ´Ï´Ù.
if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
{
return FALSE;
}
CWinApp* pApp = AfxGetApp();
if (pApp->m_pMainWnd == NULL)
pApp->m_pMainWnd = this;
return TRUE;
}
void CMainFrame::OnClose()
{
CDumbMessengerApp *pApp = reinterpret_cast(AfxGetApp());
// ÁÖ Ã¢ÀÌ ´ÝÈ÷¹Ç·Î Á¤¸® ÀÛ¾÷À» ¼öÇàÇÕ´Ï´Ù.
if (pApp->m_pMainWnd == this)
{
MessengerModel::Status status= pApp->model.getStatus();
if(status!=MessengerModel::NOT_CONNECTED) {
// NOT_CONNECTED°¡ ¾Æ´Ò¶§´Â ·Î±×¾Æ¿ôÇÑ´Ù.
SendMessage(WM_COMMAND, ID_FILE_LOGIN);
}
for (int iCntr=0; iCntr < pApp->m_aryFrames.GetSize(); iCntr++)
{
HWND hFrame = pApp->m_aryFrames.GetAt(iCntr);
if (::IsWindow(hFrame))
::SendMessage(hFrame, WM_CLOSE, 0, 0);
}
}
CFrameWnd::OnClose();
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// ºä¿¡¼ ù° Å©·¢ÀÌ ÇØ´ç ¸í·É¿¡ ³ªÅ¸³ªµµ·Ï ÇÕ´Ï´Ù.
if(currentView!=NULL) {
if (currentView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
}
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// ÇÁ·¹ÀÓÀÇ Å¬¶óÀÌ¾ðÆ® ¿µ¿ªÀ» Â÷ÁöÇÏ´Â ºä¸¦ ¸¸µì´Ï´Ù.
CCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CNotConnectedView);
currentView = STATIC_DOWNCAST(CNotConnectedView, CreateView(&context));
if(currentView==NULL) {
TRACE0("º¸±â âÀ» ¸¸µéÁö ¸øÇß½À´Ï´Ù.\n");
return -1;
}
SetActiveView(currentView);
return 0;
}
void CMainFrame::setView(CRuntimeClass * viewClass)
{
CView* pOldActiveView = GetActiveView();
::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, 32394);// arbitrary number-.-
// create the new view
CCreateContext context;
context.m_pNewViewClass = viewClass;
currentView = STATIC_DOWNCAST(CView, CreateView(&context));
if (currentView != NULL)
{
// the new view is there, but invisible and not active...
currentView->ShowWindow(SW_SHOW);
currentView->OnInitialUpdate();
SetActiveView(currentView);
RecalcLayout();
// finally destroy the old view...
pOldActiveView->DestroyWindow();
}
TRACE("OnChangeView() called\n");
}