// CPainter1View 메시지 처리기
void CPainter1View::OnChangeTool(UINT nID) {
m_nType = (int)GetCurrentMessage()->wParam; //툴바의 항목 리턴
}
void CPainter1View::OnUpdateChageTool(CCmdUI* pCmdUI){
pCmdUI->SetCheck(m_nType == (int)pCmdUI->m_nID);
}
void CPainter1View::OnCPen() {
CColorDialog dig;
if(dig.DoModal()==IDOK){
m_colLine = dig.GetColor();
m_colLineXor = (RGB(GetRValue(m_colLine)^255, GetGValue(m_colLine)^255, GetBValue(m_colLine)^255));
}
}
void CPainter1View::OnUpdatePaintred(CCmdUI *pCmdUI) {
// TODO: Add your command update UI handler code here
m_colLine = (RGB(255,0,0));
m_colLineXor = (RGB(225, 0, 0));
}
void CPainter1View::OnPainter(){
CColorDialog dig;
if(dig.DoModal()==IDOK)
m_colFill = dig.GetColor();
}
void CPainter1View::OnLButtonDown(UINT nFlags, CPoint point) {
// TODO: Add your message handler code here and/or call default
m_pntOld = point;
m_pntCur = point;
SetCapture();
CView::OnLButtonDown(nFlags, point);
}
void CPainter1View::OnLButtonUp(UINT nFlags, CPoint point){
// TODO: Add your message handler code here and/or call default
ReleaseCapture();
CClientDC dc(this);
CBrush brush, *pOldBrush;
if(m_nType == ID_DrawRectangle){
brush.CreateSolidBrush(m_colFill);
pOldBrush = (CBrush *)dc.SelectObject(brush);
dc.Rectangle(m_pntOld.x, m_pntOld.y, point.x, point.y);
} else if(m_nType == ID_DrawCircle) {
brush.CreateSolidBrush(m_colFill);
pOldBrush = (CBrush *)dc.SelectObject(brush);
dc.Ellipse(m_pntOld.x, m_pntOld.y, point.x, point.y);
}
CView::OnLButtonUp(nFlags, point);
}
void CPainter1View::OnMouseMove(UINT nFlags, CPoint point) {
// TODO: Add your message handler code here and/or call default
//왼쪽 버튼 누른 상태
if(nFlags & MK_LBUTTON) {
CClientDC dc(this);
CPen pen, *pOldPen;
CBrush brush, *pOldBrush;
if(m_nType == ID_DrawCurve){
pen.CreatePen(PS_SOLID, 1, m_colLine);
pOldPen = (CPen *)dc.SelectObject(&pen);
dc.MoveTo(m_pntOld.x, m_pntOld.y);
dc.LineTo(point.x,point.y);
m_pntOld = point;
dc.SelectObject(pOldPen);
} else if(m_nType==ID_DrawLine){
pen.CreatePen(PS_SOLID, 1, m_colLineXor);
dc.SelectObject(GetStockObject(NULL_BRUSH));
dc.SetROP2(R2_XORPEN);
pOldPen = (CPen *)dc.SelectObject(&pen);
dc.MoveTo(m_pntOld.x, m_pntOld.y);
dc.LineTo(m_pntCur.x, m_pntCur.y);
dc.MoveTo(m_pntOld.x, m_pntOld.y);
dc.LineTo(point.x, point.y);
dc.SelectObject(pOldPen);
} else if(m_nType == ID_DrawRectangle) {
pen.CreatePen(PS_SOLID, 1, m_colLineXor);
dc.SelectObject(GetStockObject(NULL_BRUSH));
dc.SetROP2(R2_XORPEN);
pOldPen = (CPen *)dc.SelectObject(&pen);
dc.Rectangle(m_pntOld.x, m_pntOld.y, point.x, point.y);
dc.SelectObject(pOldPen);
} else if(m_nType == ID_DrawCircle) {
//펜생성
pen.CreatePen(PS_SOLID,1,m_colLineXor);
dc.SelectObject(GetStockObject(NULL_BRUSH));
dc.SetROP2(R2_XORPEN);
pOldPen = (CPen *)dc.SelectObject(&pen);
dc.Ellipse(m_pntOld.x, m_pntOld.y, m_pntCur.x, m_pntCur.y);
dc.Ellipse(m_pntOld.x, m_pntOld.y, point.x, point.y);
dc.SelectObject(pOldPen);
}
m_pntCur = point;
}
CView::OnMouseMove(nFlags, point);
}
void CPainter1View::OnInitialUpdate(){
CView::OnInitialUpdate();
}
void CPainter1View::OnPaint(){
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CView::OnPaint() for painting messages
}
void CPainter1View::OnUpdatePaintgreen(CCmdUI *pCmdUI) {
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_colLine==RGB(0,255,0));
}
void CPainter1View::OnUpdatePaintblue(CCmdUI *pCmdUI) {
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_colLine == RGB(0,0,255));
}