📄 code_frag.txt
字号:
doc:
成员变量
COLORREF m_clrGrid[4][4];
COLORREF m_clrCurrentColor;
BOOL CTstDocViewDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
m_clrGrid[i][j]=RGB(255,255,255);
m_clrCurrentColor=RGB(255,0,0);
return TRUE;
}
void CTstDocViewDoc::OnColorRed()
{
// TODO: Add your command handler code here
m_clrCurrentColor=RGB(255,0,0);
}
void CTstDocViewDoc::OnUpdateColorRed(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(m_clrCurrentColor==RGB(255,0,0));
}
COLORREF CTstDocViewDoc::GetSquare(int i, int j)
{
return m_clrGrid[i][j];
}
COLORREF CTstDocViewDoc::GetCurrentColor()
{
return m_clrCurrentColor;
}
void CTstDocViewDoc::SetSquare(int i, int j, COLORREF color)
{
m_clrGrid[i][j]=color;
this->SetModifiedFlag(true);
this->UpdateAllViews(NULL);
}
void CTstDocViewView::OnDraw(CDC* pDC)
{
CTstDocViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->SetMapMode(MM_LOENGLISH);
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
COLORREF color=pDoc->GetSquare(i,j);
CBrush brush(color);
int x1=(j*100)+50;
int y1=(i*-100)-50;
int x2=x1+100;
int y2=y1-100;
CRect rect(x1,y1,x2,y2);
pDC->FillRect(rect,&brush);
}
}
for(int x=50;x<=450;x+=100){
pDC->MoveTo(x,-50);
pDC->LineTo(x,-450);
}
for(int y=-50;y>=-450;y-=100){
pDC->MoveTo(50,y);
pDC->LineTo(450,y);
}
}
void CTstDocViewView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CView::OnLButtonDown(nFlags, point);
CClientDC dc(this);
dc.SetMapMode(MM_LOENGLISH);
CPoint pos=point;
dc.DPtoLP(&pos);
if(pos.x>=50 && pos.x<=450 && pos.y<=-50 && pos.y>=-450){
int i=(-pos.y-50)/100;
int j=(pos.x-50)/100;
CTstDocViewDoc* pDoc=this->GetDocument();
COLORREF clrCurrentColor=pDoc->GetCurrentColor();
pDoc->SetSquare(i,j,clrCurrentColor);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -