⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 这是一个能够远程下中国象棋的程序
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "chess.h"

#include "MainFrm.h"
#include "globle.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
	ON_UPDATE_COMMAND_UI(IDD_WAIT, OnUpdateMyPanel)
	ON_UPDATE_COMMAND_UI(IDD_TIMER, OnUpdateTimePanel)
	ON_UPDATE_COMMAND_UI(IDD_AVI, OnUpdateAvi)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	IDD_WAIT,
	IDD_TIMER,
	IDD_AVI,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}
void CMainFrame::OnUpdateTimePanel(CCmdUI *pCmdUI)
{
	pCmdUI->Enable();
	if(g_bEnabled)
	{
		CString s;
		s = g_time.Format("%M:%S");
		TRACE("g_time:%s", g_time.Format("%M:%S"));
		pCmdUI->SetText(s);
	}
	else
		pCmdUI->SetText("0:0");
}

void CMainFrame::OnUpdateMyPanel(CCmdUI *pCmdUI)
{
	pCmdUI->Enable();
	if(g_bEnabled)
		pCmdUI->SetText("GO......");
	else
		pCmdUI->SetText("WAIT......");
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
/*	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
*/
	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndStatusBar.SetPaneInfo(1, IDD_WAIT, SBPS_NORMAL, 60);
	m_wndStatusBar.SetPaneInfo(2, IDD_TIMER, SBPS_NORMAL, 50);
	m_wndStatusBar.SetPaneInfo(3, IDD_AVI, SBPS_NORMAL, 75);
	
//	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	//DockControlBar(&m_wndToolBar);
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.x = 200;
	cs.y = 0;
	cs.cx = 550;
	cs.cy = 700;
	cs.style &= ~WS_MAXIMIZEBOX; 
	//CClientDC dc(this);
	//this->OnPrepareDC(&dc);

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	

	// Do not call CFrameWnd::OnPaint() for painting messages
}


BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
}

BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

void CMainFrame::ActivateFrame(int nCmdShow) 
{
	// TODO: Add your specialized code here and/or call the base class

	CFrameWnd::ActivateFrame(nCmdShow);
}

void CMainFrame::OnSize(UINT nType, int cx, int cy) 
{
	CFrameWnd::OnSize(nType, cx, cy);
	if (m_aviCtrl.GetSafeHwnd() != NULL)
	{
		CRect rc;
		m_wndStatusBar.GetItemRect(3, rc);
		rc.InflateRect(-1,-1);
	// If the window size has changed, resize the window
		if (rc!=m_rectAvi && rc.bottom!=0xffffffff)// && rc.Width()==0x4f)
		{
			m_aviCtrl.MoveWindow(&rc);
			//m_aviCtrl.MoveWindow(CRect(0, 0, 75, 40));
			m_rectAvi = rc;
		}
	}
	// TODO: Add your message handler code here
}

void CMainFrame::OnUpdateAvi(CCmdUI *pCmdUI)
{
	pCmdUI->Enable();
	if(m_aviCtrl.GetSafeHwnd() == NULL)
	{
		DWORD dwStyle = WS_CHILD|WS_VISIBLE|ACS_AUTOPLAY|ACS_TRANSPARENT|ACS_CENTER;
		CRect rect;
		m_wndStatusBar.GetItemRect(3, rect);
		rect.InflateRect(-1, -1);
		if(!rect.IsRectEmpty())
		{
			m_rectAvi = rect;
			m_aviCtrl.Create(dwStyle, rect, &m_wndStatusBar, 0);
			m_aviCtrl.Open(IDR_AVI);
		}
	}
}

void CMainFrame::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CFrameWnd::CalcWindowRect(lpClientRect, nAdjustType);
}

BOOL CMainFrame::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	return CFrameWnd::OnEraseBkgnd(pDC);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -