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

📄 view.cpp

📁 讲mfc的书
💻 CPP
字号:
// View.cpp : implementation of the CBfieldView class
//

#include "stdafx.h"
#include "bfield.h"

#include "bsocket.h"
#include "Doc.h"
#include "View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

///////////////////////
// CBfieldView

IMPLEMENT_DYNCREATE(CBfieldView, CScrollView)

BEGIN_MESSAGE_MAP(CBfieldView, CScrollView)
        //{{AFX_MSG_MAP(CBfieldView)
        ON_WM_LBUTTONDOWN()
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

///////////////////////
// CBfieldView construction/destruction

CBfieldView::CBfieldView()
{
        // TODO: add construction code here

}

CBfieldView::~CBfieldView()
{
}

BOOL CBfieldView::PreCreateWindow(CREATESTRUCT& cs)
{
        // TODO: Modify the Window class or styles here by modifying
        //  the CREATESTRUCT cs

        return CScrollView::PreCreateWindow(cs);
}

///////////////////////
// CBfieldView drawing

void CBfieldView::OnDraw(CDC* pDC)
{
        CBfieldDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        TEXTMETRIC tm;
        COLORREF clr,curcolor;
        pDC->SelectStockObject(ANSI_FIXED_FONT);
        pDC->GetTextMetrics(&tm);
		pDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
// Change default color based on mode (setup/hits)
        clr=pDoc->GetMode()?RGB(0xFF,0,0):RGB(0,0x80,0);
        for (int x=0;x<10;x++)
                for (int y=0;y<10;y++)
                   {
                   char piece[2];
                   piece[1]='\0';
                   piece[0]=pDoc->GetState(x,y);
                   curcolor=clr;
                   // custom colors
                   if (piece[0]=='.') curcolor=RGB(0,0,0);
                   if (piece[0]=='X') curcolor=RGB(0,0,0xFF);
                   pDC->SetTextColor(curcolor);
                   pDC->TextOut(
                     x*tm.tmAveCharWidth*3+
                       tm.tmAveCharWidth,
                     y*tm.tmHeight*3+
                       tm.tmAveCharWidth,piece);
                   }

}

void CBfieldView::OnInitialUpdate()
{
        CScrollView::OnInitialUpdate();
        CSize sizeTotal;
        // TODO: calculate the total size of this view
        CDC *dc=GetDC();
        TEXTMETRIC tm;
        dc->SelectStockObject(ANSI_FIXED_FONT);
        dc->GetTextMetrics(&tm);
// allow for 3 characters per cell plus a border character
        sizeTotal.cx = 31*tm.tmAveCharWidth;
        sizeTotal.cy = 31*tm.tmHeight;
        SetScrollSizes(MM_TEXT, sizeTotal);
// While this code should work, it has problems with the
// new style windows
//      GetParentFrame()->RecalcLayout(TRUE);
//      ResizeParentToFit();

}

///////////////////////
// CBfieldView diagnostics

#ifdef _DEBUG
void CBfieldView::AssertValid() const
{
        CScrollView::AssertValid();
}

void CBfieldView::Dump(CDumpContext& dc) const
{
        CScrollView::Dump(dc);
}

CBfieldDoc* CBfieldView::GetDocument() // non-debug version is inline
{
        ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBfieldDoc)));
        return (CBfieldDoc*)m_pDocument;
}
#endif //_DEBUG

///////////////////////
// CBfieldView message handlers

void CBfieldView::OnLButtonDown(UINT nFlags, CPoint point)
{
        CDC *dc;
        CPoint scrollpos;
        int x,y;
        CBfieldDoc *doc=GetDocument();
        // convert to X,Y
        dc=GetDC();
        TEXTMETRIC tm;
        dc->SelectStockObject(ANSI_FIXED_FONT);
        dc->GetTextMetrics(&tm);
// Account for scrolling
        scrollpos=GetDeviceScrollPosition();
        point+=scrollpos;
        x=(point.x-tm.tmAveCharWidth)/(3*tm.tmAveCharWidth);
        y=(point.y-tm.tmHeight)/(3*tm.tmHeight);
// Pass to Document
        doc->OnClick(x,y);
}

⌨️ 快捷键说明

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