📄 mdrowpenview.cpp
字号:
pDC->Arc(CRect(m_pStartPoint,m_pEndPoint),m_pStartPoint,EndPoint);
ReleaseDC(pDC);
break;
case 5:
pDC->SetROP2(R2_COPYPEN);
pDC->Rectangle(CRect(m_pStartPoint,m_pEndPoint));
ReleaseDC(pDC);
break;
case 6:
pDC->SetROP2(R2_COPYPEN);
long NewLenth;
NewLenth = sqrtf((m_pEndPoint.x-m_pStartPoint.x)*(m_pEndPoint.x-m_pStartPoint.x)+
(m_pEndPoint.y-m_pStartPoint.y)*(m_pEndPoint.y-m_pStartPoint.y));
pDC->Ellipse(m_pStartPoint.x+NewLenth,m_pStartPoint.y-NewLenth,m_pStartPoint.x-NewLenth,
m_pStartPoint.y+NewLenth);
ReleaseDC(pDC);
break;
case 7:
pDC->SetROP2(R2_COPYPEN);
m_pEndPoint = point;
pDC->Ellipse(CRect(m_pStartPoint,m_pEndPoint));
break;
ReleaseDC(pDC);
}
switch (m_nFlag)
{
case 1:
{
Line *pLinenext = (Line*)malloc(sizeof(Line));
pLinenext->Startpoint = m_pStartPoint;
pLinenext->EndPoint = m_pEndPoint;
pLinenext->nPenSize = m_nPenSize;
pLinenext->nmyBlue = nBlue;
pLinenext->nmyGreen = nGreen;
pLinenext->nmyRed = nRed;
pLinenext->next = NULL;
p->next = pLinenext;
p = pLinenext;
break;
}
case 2:
break;
case 3:
{
Line *pzNext= (Line*)malloc(sizeof(Line));
pzNext->Startpoint = m_pzStarpoint;
pzNext->EndPoint = m_pzEndpoint;
pzNext->nPenSize = m_nPenSize;
pzNext->nmyBlue = nBlue;
pzNext->nmyGreen = nGreen;
pzNext->nmyRed = nRed;
pzNext->next = NULL;
zp->next = pzNext;
zp = pzNext;
break;
}
case 4:
break;
case 5:
{
Line *pzNext= (Line*)malloc(sizeof(Line));
pzNext->Startpoint = m_pStartPoint;
pzNext->EndPoint = m_pEndPoint;
pzNext->nPenSize = m_nPenSize;
pzNext->nmyBlue = nBlue;
pzNext->nmyGreen = nGreen;
pzNext->nmyRed = nRed;
pzNext->next = NULL;
rp->next = pzNext;
rp = pzNext;
break;
}
case 6:
{
Line *pzNext= (Line*)malloc(sizeof(Line));
pzNext->Startpoint = m_pStartPoint;
pzNext->EndPoint = m_pEndPoint;
pzNext->nPenSize = m_nPenSize;
pzNext->nmyBlue = nBlue;
pzNext->nmyGreen = nGreen;
pzNext->nmyRed = nRed;
pzNext->next = NULL;
cp->next = pzNext;
cp = pzNext;
break;
}
case 7:
{
Line *pzNext= (Line*)malloc(sizeof(Line));
pzNext->Startpoint = m_pStartPoint;
pzNext->EndPoint = m_pEndPoint;
pzNext->nPenSize = m_nPenSize;
pzNext->nmyBlue = nBlue;
pzNext->nmyGreen = nGreen;
pzNext->nmyRed = nRed;
pzNext->next = NULL;
ep->next = pzNext;
ep = pzNext;
break;
}
}
m_pzStarpoint = m_pzEndpoint;
m_bFlag = false;
CView::OnLButtonUp(nFlags, point);
}
void CMDrowPenView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC * pDC = GetDC();
CPen mypen;
CPen *mOldPen ;
mypen.CreatePen(PS_COSMETIC, m_nPenSize, RGB(nRed,nGreen,nBlue));
mOldPen = &mypen;
pDC->SelectObject(mOldPen);
CBrush *pbrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); //用刷子防止画的封闭图形是实心的,
pDC->SelectObject(pbrush); // 因为画图模式SetROP2(R2_NOT)
CBrush * pOldBrush = (CBrush *)pDC->SelectStockObject(NULL_BRUSH);
if (m_bFlag)
{
m_pEndPoint = point;
switch (m_nFlag)
{
case 1:
pDC->SetROP2(R2_NOT);
m_pEndPoint = point;
pDC->MoveTo(m_pStartPoint);
pDC->LineTo(m_oldPoint);
pDC->MoveTo(m_pStartPoint);
pDC->LineTo(m_pEndPoint);
m_oldPoint = point;
ReleaseDC(pDC);
break;
case 2:
m_pEndPoint = point;
pDC->MoveTo(m_pStartPoint);
pDC->LineTo(m_pEndPoint);
m_pStartPoint = m_pEndPoint;
ReleaseDC(pDC);
break;
case 3:
pDC->SetROP2(R2_NOT);
m_pzEndpoint = point;
pDC->MoveTo(m_pzStarpoint);
pDC->LineTo(mOldPoint);
pDC->MoveTo(m_pzStarpoint);
pDC->LineTo(m_pzEndpoint);
mOldPoint = point;
break;
case 4:
ReleaseDC(pDC);
break;
case 5:
pDC->SetROP2(R2_NOT);
pDC->Rectangle(CRect(m_pStartPoint,m_oldPoint));
pDC->Rectangle(CRect(m_pStartPoint,m_pEndPoint));
m_oldPoint = point;
ReleaseDC(pDC);
break;
case 6:
pDC->SetROP2(R2_NOT);
LONG lenth;
long NewLenth;
m_pEndPoint = point;
lenth = sqrtf((m_oldPoint.x-m_pStartPoint.x)*(m_oldPoint.x-m_pStartPoint.x)+
(m_oldPoint.y-m_pStartPoint.y)*(m_oldPoint.y-m_pStartPoint.y));
NewLenth = sqrtf((m_pEndPoint.x-m_pStartPoint.x)*(m_pEndPoint.x-m_pStartPoint.x)+
(m_pEndPoint.y-m_pStartPoint.y)*(m_pEndPoint.y-m_pStartPoint.y));
pDC->Ellipse(m_pStartPoint.x+lenth,m_pStartPoint.y-lenth,m_pStartPoint.x-lenth,m_pStartPoint.y+lenth);
pDC->Ellipse(m_pStartPoint.x+NewLenth,m_pStartPoint.y-NewLenth,m_pStartPoint.x-NewLenth,
m_pStartPoint.y+NewLenth);
m_oldPoint = point;
ReleaseDC(pDC);
break;
case 7:
pDC->SetROP2(R2_NOT);
m_pEndPoint = point;
pDC->Ellipse(CRect(m_pStartPoint,m_oldPoint));
pDC->Ellipse(CRect(m_pStartPoint,m_pEndPoint));
m_oldPoint = point;
ReleaseDC(pDC);
break;
}
}
CString str;
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CStatusBar* pStatus = &pFrame->m_wndStatusBar;
if (pStatus)
{
str.Format("X = %d",point.x); //把各种变量格式化输出到一个字符串变量里。
pStatus->SetPaneText(2,str); //设置第三个状态栏,
str.Format("Y = %d",point.y);
pStatus->SetPaneText(3,str); //设置第四个状态栏
}
}
void CMDrowPenView::OnDrawLine()
{
// TODO: Add your command handler code here
m_nFlag = 1;
}
void CMDrowPenView::OnDrowThread()
{
// TODO: Add your command handler code here
m_nFlag = 2;
}
void CMDrowPenView::OnDrowMline()
{
// TODO: Add your command handler code here
m_nFlag = 3;
}
void CMDrowPenView::OnDrowArc()
{
// TODO: Add your command handler code here
m_nFlag = 4;
}
void CMDrowPenView::OnDrowCecle()
{
// TODO: Add your command handler code here
m_nFlag = 6;
}
void CMDrowPenView::OnDorwRect()
{
// TODO: Add your command handler code here
m_nFlag = 5;
}
void CMDrowPenView::OnDrowEllipse()
{
// TODO: Add your command handler code here
m_nFlag = 7;
}
void DrawRect(CDC *pDC, CPoint *Startpoint, CPoint *Endpoint)
{
}
void CMDrowPenView::OnSize()
{
// TODO: Add your command handler code here
CsizeDlg SetSize;
int nResponse =SetSize.DoModal();
if (nResponse == IDOK)
{
m_nPenSize = SetSize.m_nSize;
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
}
void CMDrowPenView::OnColor()
{
// TODO: Add your command handler code here
SetColorDlg SetColor;
int nResponse = SetColor.DoModal();
if (nResponse = IDOK)
{
nRed = SetColor.m_nRedValue;
nGreen = SetColor.m_nGreenValue;
nBlue = SetColor.m_nBlueValue;
}
}
void CMDrowPenView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
m_nPenSize = 1;
nBlue = 0;
nGreen = 0;
nRed = 0;
nCount = 0;
head = (Line*)malloc(sizeof(Line));
head->next = NULL;
p = head;
zhead = (Line*)malloc(sizeof(Line));
zhead->next = NULL;
zp = zhead;
chead = (Line*)malloc(sizeof(Line));
chead->next = NULL;
cp = chead;
rhead = (Line*)malloc(sizeof(Line));
rhead->next = NULL;
rp = rhead;
ehead = (Line*)malloc(sizeof(Line));
ehead->next = NULL;
ep = ehead;
}
void CMDrowPenView::OnUpdateXY(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -