www.gusucode.com > VC++三子棋游戏源码(类似五子棋)-源码程序 > VC++三子棋游戏源码(类似五子棋)-源码程序\code\GameFrame.cpp
//Download by http://www.NewXing.com // GameFrame.cpp : implementation file // #include "stdafx.h" #include "GameView.h" #include "GameFrame.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CGameFrame BEGIN_MESSAGE_MAP(CGameFrame, CFrameWnd) //{{AFX_MSG_MAP(CGameFrame) ON_WM_CREATE() ON_WM_PAINT() ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() CGameFrame::CGameFrame(CWnd* pWnd, RECT rcWnd) { pGameView = NULL; pWebAdvertView =NULL; pUserListView = NULL; pChatView = NULL; bFirstRun =TRUE; try { Create(NULL, "", WS_CHILD | WS_VISIBLE, rcWnd, pWnd, NULL, NULL); } catch(...) { ::AfxMessageBox("无法创建游戏窗口", MB_OK | MB_ICONERROR); } } CGameFrame::~CGameFrame() { } ///////////////////////////////////////////////////////////////////////////// // CGameFrame message handlers BOOL CGameFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { if (NULL == m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE; m_wndSplitter.CreateView(0, 0, //设置GameView RUNTIME_CLASS(CGameView), CSize(600,400), pContext); RECT rect; memset(&rect, 0, sizeof(RECT)); this->GetClientRect(&rect); //拆分右边的栏 if(NULL == m_wndRightSplitter.CreateStatic(&m_wndSplitter, 2, 1, WS_CHILD|WS_VISIBLE, m_wndSplitter.IdFromRowCol(0, 1))) return FALSE; m_wndRightSplitter.CreateView(0, 0, RUNTIME_CLASS(CUserListView), CSize(250,200), pContext); // m_wndRightSplitter.CreateView(1, 0, RUNTIME_CLASS(CHtmlViewEx), // CSize(250,300), pContext); m_wndRightSplitter.CreateView(1, 0, RUNTIME_CLASS(CChatView), CSize(250,100), pContext); SetActiveView((CView*)m_wndSplitter.GetPane(0, 0)); pGameView = (CGameView*)m_wndSplitter.GetPane(0, 0); pUserListView = (CUserListView*)m_wndRightSplitter.GetPane(0, 0); ////pWebAdvertView =(CHtmlViewEx*)m_wndRightSplitter.GetPane(1, 0); pChatView =(CChatView*)m_wndRightSplitter.GetPane(1, 0); // SAFE_CHECKWND(pWebAdvertView) { //pWebAdvertView->Navigate2("www.GameHigh.net", 0, NULL); // pWebAdvertView->Navigate2("about:blank", 0, NULL); } return TRUE; } int CGameFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; this->ModifyStyleEx(WS_EX_OVERLAPPEDWINDOW , 0, 0); return 0; } void CGameFrame::OnPaint() { CPaintDC dc(this); // device context for painting if(bFirstRun) { bFirstRun =FALSE; RECT rect; memset(&rect, 0, sizeof(RECT)); this->GetClientRect(&rect); CSplitterWnd* pWnd =&m_wndSplitter; SAFE_CHECKWND(pWnd) { pWnd->SetColumnInfo(0, (rect.right/4)*3-15, 1); pWnd->SetColumnInfo(1, (rect.right/4)+15, 1); pWnd->RecalcLayout(); } } } void CGameFrame::OnSize(UINT nType, int cx, int cy) { CFrameWnd::OnSize(nType, cx, cy); if(bFirstRun) return; if(!bFirstRun) bFirstRun = TRUE; SAFE_CHECKWND(pGameView) { RECT rect; memset(&rect, 0, sizeof(RECT)); pGameView->GetClientRect(&rect); } } CView *CGameFrame::GetView(int nView) { CView *pView = NULL; switch(nView) { case 0: { pView = pGameView; break; } case 1: { pView = pWebAdvertView; break; } case 2: { pView = pChatView; break; } } return pView; } /////////////////////////////////////////////////////////