📄 lwq6231view.cpp
字号:
void CLWQ6231View::OnColorPink()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_PINK;
}
void CLWQ6231View::OnColorRed()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_RED;
}
void CLWQ6231View::OnColorWhite()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_WHITE;
}
void CLWQ6231View::OnColorYellow()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_YELLOW;
}
void CLWQ6231View::OnUpdateEditCut(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(virtualline);
}
void CLWQ6231View::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bClip);
}
void CLWQ6231View::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(virtualline);
}
void CLWQ6231View::Selected_Copy()
{
if (showgrid)
Grid();
CClientDC dc(this);
CDC memDC;
CRect rect;
GetWindowRect(rect);
long width = m_pSelect->GetWidth();
long height = m_pSelect->GetHeight();
long x = m_pSelect->GetX();
long y = m_pSelect->GetY();
memDC.CreateCompatibleDC(&dc);
dc.OffsetViewportOrg(x, y);
m_pSelect->map_select.CreateCompatibleBitmap(&dc, width, height);
CBitmap* pOldBitmap = memDC.SelectObject(&m_pSelect->map_select);
memDC.BitBlt(0, 0, width, height, &dc, 0, 0, SRCCOPY);
memDC.SelectObject(pOldBitmap);
if(showgrid)
Grid();
}
void CLWQ6231View::Back_Copy()
{
if (showgrid)
Grid();
CClientDC dc(this);
CDC memDC;
CRect rect;
GetWindowRect(rect);
CBitmap *pOldBitmap;
memDC.CreateCompatibleDC(&dc);
m_pSelect->backmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height());
pOldBitmap = memDC.SelectObject(&m_pSelect->backmap);
memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, 0, 0, SRCCOPY);
memDC.SelectObject(pOldBitmap);
if(showgrid)
Grid();
}
void CLWQ6231View::Back_CutCopy()
{
if (showgrid)
Grid();
CClientDC dc(this);
CDC memDC;
CRect rect;
GetWindowRect(rect);
CBitmap *pOldBitmap;
long width = m_pSelect->GetWidth();
long height = m_pSelect->GetHeight();
long x = m_pSelect->GetX();
long y = m_pSelect->GetY();
memDC.CreateCompatibleDC(&dc);
m_pSelect->backmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height());
pOldBitmap = memDC.SelectObject(&m_pSelect->backmap);
memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, 0, 0, SRCCOPY);
memDC.BitBlt(x, y, width, height, &dc, 0, 0, WHITENESS);
memDC.SelectObject(pOldBitmap);
if(showgrid)
Grid();
}
void CLWQ6231View::OnUpdateSelect(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_nMouseMode==IDT_SELECT);// TODO: Add your command update UI handler code here
}
void CLWQ6231View::SaveInStack()
{
if(m_pSelect)
{
if (virtualline)
{
m_pSelect->Clear(GetDC());
}
}
if (showgrid)
Grid();
CClientDC dc(this);
CDC memDC;
CRect rect;
CBitmap bitmap,b1;
// b1=bitmap;
HBITMAP bm;
GetWindowRect(rect);
CBitmap *pOldBitmap;
memDC.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height());
pOldBitmap = memDC.SelectObject(&bitmap);
memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, 0, 0, SRCCOPY);
bm=(HBITMAP)bitmap.GetSafeHandle();
// bitmap.Attach();
m_pStack->Add(bm);
memDC.SelectObject(pOldBitmap);
bitmap.Detach();
if(showgrid)
Grid();
if(m_pSelect)
{
if (virtualline)
{
m_pSelect->Clear(GetDC());
}
}
}
void CLWQ6231View::OnEditRedo()
{
//释放选中的对象,销去虚线框
if(m_pSelect)
{
if (virtualline)
m_pSelect->Clear(GetDC());
delete m_pSelect;
m_pSelect=NULL;
}
virtualline=false;
//////////////////////////
if (showgrid)
Grid();
CDC dc;
CDC * pDC = GetDC();
if(!dc.CreateCompatibleDC(pDC))
return;
BITMAP bm;
CBitmap cb1;
cb1.Attach(m_pStack->Redo());
cb1.GetBitmap(&bm);
dc.SelectObject(&cb1);
pDC->BitBlt(0,0, bm.bmWidth, bm.bmHeight, &dc, 0, 0, SRCCOPY);
cb1.Detach();
}
void CLWQ6231View::OnEditUndo()
{
//释放选中的对象,销去虚线框
if(m_pSelect)
{
if (virtualline)
m_pSelect->Clear(GetDC());
delete m_pSelect;
m_pSelect=NULL;
}
virtualline=false;
///////////////////////////////////
if (showgrid)
Grid();
CDC dc;
CDC * pDC = GetDC();
if(!dc.CreateCompatibleDC(pDC))
return;
BITMAP bm;
CBitmap cb1;
cb1.Attach(m_pStack->Undo());
cb1.GetBitmap(&bm);
dc.SelectObject(&cb1);
pDC->BitBlt(0,0, bm.bmWidth, bm.bmHeight, &dc, 0, 0, SRCCOPY);
cb1.Detach();
}
void CLWQ6231View::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_pStack->CanUndo());
}
void CLWQ6231View::OnUpdateEditRedo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_pStack->CanRedo());
}
void CLWQ6231View::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CView::OnPaint() for painting messages
if(m_bFirstSave)
{
SaveInStack();
m_bFirstSave = false;
}
CDC* pDC = GetDC();
if( m_pStack->CanUndo() )
{
CDC dc;
if(!dc.CreateCompatibleDC(pDC))
return;
BITMAP bm;
CBitmap cb;
cb.Attach(m_pStack->Pop());
cb.GetBitmap(&bm);
dc.SelectObject(&cb);
pDC->BitBlt(0,0, bm.bmWidth, bm.bmHeight, &dc, 0, 0, SRCCOPY);
cb.Detach();
}
//如果以前选中并有虚线,则再现窗口时出现虚线
if (m_pSelect&&virtualline)
m_pSelect->Clear(pDC);
/////////////////////////////////////////
if(showgrid) Grid();
}
void CLWQ6231View::OnCurve()
{
// TODO: Add your command handler code here
m_nMouseMode = IDT_CURVE;
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurArrow);//修改缺省光标
}
void CLWQ6231View::OnPoly()
{
// TODO: Add your command handler code here
m_nMouseMode = IDT_POLY;
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurCross);//修改缺省光标
}
void CLWQ6231View::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CLWQ6231Doc* pDoc = GetDocument();
CDC* pDC = GetDC();//获得DC
if(m_nMouseMode == IDT_POLY && m_usrCurrentObject)
{
m_usrCurrentObject->EndPoint(pDC);
SaveInStack();
::ClipCursor(NULL);//释放鼠标锁定
delete m_usrCurrentObject;
m_bDrawing = false;
m_usrCurrentObject = NULL;
}
ReleaseDC(pDC);//释放DC资源
CView::OnLButtonDblClk(nFlags, point);
}
void CLWQ6231View::OnWidthNormal()
{
// TODO: Add your command handler code here
m_iPenWidth = WIDTH_NORMAL;
}
void CLWQ6231View::OnWidthThin()
{
// TODO: Add your command handler code here
m_iPenWidth = WIDTH_THIN;
}
void CLWQ6231View::OnWidthWide()
{
// TODO: Add your command handler code here
m_iPenWidth = WIDTH_WIDE;
}
void CLWQ6231View::OnFillFalse()
{
// TODO: Add your command handler code here
m_bFill = false;
}
void CLWQ6231View::OnFillTrue()
{
// TODO: Add your command handler code here
m_bFill = true;
}
void CLWQ6231View::OnUpdateWidthNormal(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_iPenWidth == WIDTH_NORMAL);
}
void CLWQ6231View::OnUpdateWidthThin(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_iPenWidth == WIDTH_THIN);
}
void CLWQ6231View::OnUpdateWidthWide(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_iPenWidth == WIDTH_WIDE);
}
void CLWQ6231View::OnUpdateFillFalse(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bFill == false);
}
void CLWQ6231View::OnUpdateFillTrue(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bFill == true);
}
void CLWQ6231View::OnExamineColor()
{
// TODO: Add your command handler code here
}
void CLWQ6231View::OnExamineTool()
{
// TODO: Add your command handler code here
}
void CLWQ6231View::Grid()
{
// m_pStack->New();
CDC *pdc = GetDC();
CRect rect;
GetWindowRect(rect);
int w=rect.Width();
int h=rect.Height();
COLORREF XorColor = pdc->GetBkColor()^RGB(128,128,128) ;
CPen pen(PS_SOLID, 1, XorColor), *oldpen;
int oldmode = pdc->GetROP2();
oldpen = pdc->SelectObject(&pen);
pdc->SetROP2(R2_XORPEN);
for(int i=0;i<12;i++)
{
pdc->MoveTo(0,(i*w)/12);
pdc->LineTo(w,i*w/12);
pdc->MoveTo(w*i/12,0);
pdc->LineTo(w*i/12,h);
}
//以下恢复DC
pdc->SetROP2(oldmode);
pdc->SelectObject(oldpen);
pen.DeleteObject();//释放笔资源
}
void CLWQ6231View::Ongrid()
{
// TODO: Add your command handler code here
Grid();
showgrid=showgrid?false:true;
}
void CLWQ6231View::OnUpdateColorRed(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nCurrentColor == UD_RED);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -