📄 eastdrawview.cpp
字号:
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
if(pMainFrame->m_wndStyleBar.IsWindowVisible())
{
pMainFrame->ShowFontBar(true);
if(this->m_LBDownTimes==1)
{
this->m_LBDownTimes=2;
this->m_pCurrentUnit->OnLButtonDown(&dc,this,0);
}
}
if(!pMainFrame->m_wndStyleBar.IsWindowVisible())
{
pMainFrame->ShowFontBar(true);
this->m_LBDownTimes=0;
}
//m_pTextEdit->ShowWindow(true);
m_CurrentDrawTool=Text_Tool;
m_CurrentDrawStatus=Draw_Status;
this->m_LBDownTimes=0;
}
void CEastDrawView::GetFontInfo(LPTSTR pszFaceName, int &nSize)
{
/// CHARFORMAT cf = GetCharFormatSelection ();
//::lstrcpy (pszFaceName, cf.dwMask & CFM_FACE ? cf.szFaceName : _T (""));
// nSize = cf.dwMask & CFM_SIZE ? cf.yHeight : -1;
}
void CEastDrawView::OnCharBold()
{
// TODO: Add your command handler code here
CMainFrame*pMainFrame=(CMainFrame*)::AfxGetMainWnd();
pMainFrame->m_wndStyleBar.OnCharBold();
}
void CEastDrawView::OnCharItalic()
{
// TODO: Add your command handler code here
CMainFrame*pMainFrame=(CMainFrame*)::AfxGetMainWnd();
pMainFrame->m_wndStyleBar.OnCharItalic();
}
void CEastDrawView::OnCharUnderline()
{
// TODO: Add your command handler code here
CMainFrame*pMainFrame=(CMainFrame*)::AfxGetMainWnd();
pMainFrame->m_wndStyleBar.OnCharUnderline();
}
void CEastDrawView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CClientDC dc(this);
this->OnPrepareDC(&dc);
dc.SetWindowOrg(m_CenterPoint);
//dc.DPtoLP(&point);
// TODO: Add your message handler code here
if(m_CurrentDrawStatus!=Select_Status)
m_pCurrentUnit->OnContextMenu(pWnd,point);
if(m_CurrentDrawStatus==Select_Status)
{
CMenu menuTextEdit;
menuTextEdit.LoadMenu(IDR_MENU_Delete);
menuTextEdit.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,pWnd);
}
}
void CEastDrawView::OnMenuitemOk()
{
// TODO: Add your command handler code here
CClientDC dc(this);
OnPrepareDC(&dc);
dc.SetWindowOrg(m_CenterPoint);
m_pCurrentUnit->OnMenuitemOk(&dc,this);
}
BOOL CEastDrawView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if(m_CurrentDrawStatus==Draw_Status||m_CurrentDrawStatus==Change_Status||m_CurrentDrawStatus==Select_Color_Status)
SetCursor(AfxGetApp()->LoadCursor(ID_Draw));
if(m_CurrentDrawStatus==Drag_Status||m_CurrentDrawStatus==Select_Status)
SetCursor(AfxGetApp()->LoadCursor(ID_Change));
return true;
//return CScrollView::OnSetCursor(pWnd, nHitTest, message);
}
void CEastDrawView::ShowFontBar(BOOL isShow)
{
CMainFrame*pMainFrame=(CMainFrame*)::AfxGetMainWnd();
pMainFrame->ShowFontBar(isShow);
}
void CEastDrawView::OnCirCu()
{
// TODO: Add your command handler code here
CClientDC dc(this);
this->OnPrepareDC(&dc);
dc.SetWindowOrg(m_CenterPoint);
this->m_pCurrentUnit->OnMenuitemCirCu(&dc,this);
}
void CEastDrawView::OnUpdateCirCu(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck();
}
void CEastDrawView::SetMousePosText(CPoint Logpoint,CPoint Devpoint)
{
CMainFrame*pMainFrame=(CMainFrame*)::AfxGetMainWnd();
pMainFrame->SetMousePosText(Logpoint,Devpoint);
}
void CEastDrawView::DrawAxis(CDC*pDC)
{
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
CPen*OldPen=pDC->SelectObject(&pen);
int oldRop=pDC->SetROP2(R2_NOTXORPEN);
pDC->MoveTo(m_CenterPoint.x+2,0);
pDC->LineTo(GetTotalSize().cx+m_CenterPoint.x-2,0);
pDC->MoveTo(0,m_CenterPoint.y+2);
pDC->LineTo(0,GetTotalSize().cy+m_CenterPoint.y-2);
pDC->SelectObject(OldPen);
pDC->SetROP2(oldRop);
}
BOOL CEastDrawView::SaveDIB(CBitmap*pbitmap, CFile&file)
{
CClientDC dc(this);
OnPrepareDC(&dc);
dc.SetWindowOrg(m_CenterPoint);
CDC*pViewDC=&dc;
CEastDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBitmap*Oldmap;
CBitmap Bitmap;
CDC memDC;
Bitmap.CreateCompatibleBitmap(pViewDC,this->GetTotalSize().cx,this->GetTotalSize().cy);
memDC.CreateCompatibleDC(pViewDC);
memDC.SetMapMode(pViewDC->GetMapMode());
Oldmap=memDC.SelectObject(&Bitmap);
memDC.SetWindowOrg(m_CenterPoint);
memDC.PatBlt(m_CenterPoint.x,m_CenterPoint.y,GetTotalSize().cx,GetTotalSize().cy,WHITENESS);
this->DrawAll(&memDC);
if(this->m_HaveAxis)
this->DrawAxis(&memDC);
::GdiFlush();
memDC.SelectObject(Oldmap);
memDC.DeleteDC();
BITMAPFILEHEADER bmfHdr;
bmfHdr.bfType=0x4d42;
int sizeHdr=sizeof(BITMAPINFOHEADER);
LPBITMAPINFOHEADER lpBI=( LPBITMAPINFOHEADER)::GlobalAlloc(LMEM_FIXED,sizeHdr);
if(!lpBI)
{
AfxMessageBox("内存申请失败,请稍后再试");
}
BYTE *pDib;
BYTE *pDib2;
pDib=(BYTE*)::GlobalAlloc(LMEM_FIXED,GetTotalSize().cx*GetTotalSize().cy*4);
if(!pDib)
{
AfxMessageBox("内存申请失败,请稍后再试");
}
lpBI->biSize=(LONG)sizeof(BITMAPINFOHEADER);
lpBI->biWidth=(LONG)this->GetTotalSize().cx;
lpBI->biHeight=(LONG)this->GetTotalSize().cy;
lpBI->biPlanes=1;
lpBI->biBitCount=32;
lpBI->biCompression=BI_RGB;
lpBI->biSizeImage=0;
lpBI->biXPelsPerMeter=0;
lpBI->biYPelsPerMeter=0;
lpBI->biClrUsed=0;
lpBI->biClrImportant=0;
Bitmap.GetBitmapBits(GetTotalSize().cx*GetTotalSize().cy*4,pDib);
pDib2=(BYTE*)::GlobalAlloc(LMEM_FIXED,GetTotalSize().cx*GetTotalSize().cy*4);
if(!pDib2)
{
AfxMessageBox("内存申请失败,请稍后再试");
}
for(int j=0;j<GetTotalSize().cy;j++)
for(int i=0;i<GetTotalSize().cx*4;i++)
{
pDib2[i+j*GetTotalSize().cx*4]=pDib[GetTotalSize().cx*(GetTotalSize().cy-1-j)*4+i];
}
::GlobalFree(pDib);
bmfHdr.bfSize=(DWORD) (sizeof(BITMAPFILEHEADER) +
sizeHdr +GetTotalSize().cx*GetTotalSize().cy*4);
bmfHdr.bfReserved1=bmfHdr.bfReserved2=0;
bmfHdr.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeHdr;
try
{
file.Write((LPVOID)&bmfHdr,sizeof(BITMAPFILEHEADER));
file.Write((LPVOID)lpBI,sizeHdr);
file.WriteHuge((LPVOID)pDib2,GetTotalSize().cx*GetTotalSize().cy*4);
}
catch(CException*Fe)
{
Fe->ReportError();
Fe->Delete();
return false;
}
::GlobalFree(lpBI);
::GlobalFree(pDib2);
return true;
}
void CEastDrawView::DeleteSelect()
{
this->ExchangeSave();
CClientDC dc(this);
this->OnPrepareDC(&dc);
dc.SetWindowOrg(m_CenterPoint);
CDC*pDC=&dc;
CEastDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int oldrop=pDC->SetROP2(R2_NOTXORPEN);
for(int i=0;i<pDoc->m_PolygonArray.GetSize();i++)
{
CPolygon*pPolygon=(CPolygon*)pDoc->m_PolygonArray.GetAt(i);
if(pPolygon->m_HaveFindFirst)
{
pPolygon->ShowSelectPoint(pDC);
pPolygon->DrawStatic(pDC);
pDoc->m_PolygonArray.RemoveAt(i);
delete pPolygon;
i--;
}
}
for(i=0;i<pDoc->m_TextArray.GetSize();i++)
{
CText*pText=(CText*)pDoc->m_TextArray.GetAt(i);
if(pText->m_HaveFindFirst)
{
pText->ShowSelectPoint(pDC);
//pText->DrawStatic(pDC);
CPoint point=pText->m_PositionPoint;
pDC->LPtoDP(&point);
this->InvalidateRect(CRect(point,CPoint(point.x+pText->m_Width,point.y+pText->m_Hight)));
pDoc->m_TextArray.RemoveAt(i);
delete pText;
i--;
}
}
for(i=0;i<pDoc->m_PolyBezierArray.GetSize();i++)
{
CPolyBezier*pPolyBezier=(CPolyBezier*)pDoc->m_PolyBezierArray.GetAt(i);
if(pPolyBezier->m_HaveFindFirst)
{
pPolyBezier->ShowSelectPoint(pDC);
pPolyBezier->DrawStatic(pDC);
pDoc->m_PolyBezierArray.RemoveAt(i);
delete pPolyBezier;
i--;
}
}
for(i=0;i<pDoc->m_DLineArray.GetSize();i++)
{
CDLine*pDLine=(CDLine*)pDoc->m_DLineArray.GetAt(i);
if(pDLine->m_HaveFindFirst)
{ pDLine->ShowSelectPoint(pDC);
pDLine->DrawStatic(pDC);
pDoc->m_DLineArray.RemoveAt(i);
delete pDLine;
i--;
}
}
for(i=0;i<pDoc->m_CurveArray.GetSize();i++)
{
CCurve*pCurve=(CCurve*)pDoc->m_CurveArray.GetAt(i);
if(pCurve->m_HaveFindFirst)
{
pCurve->ShowSelectPoint(pDC);
pCurve->DrawStatic(pDC);
pDoc->m_CurveArray.RemoveAt(i);
delete pCurve;
i--;
}
}
for(i=0;i<pDoc->m_RectangleArray.GetSize();i++)
{
CRectangle*pRectangle=(CRectangle*)pDoc->m_RectangleArray.GetAt(i);
if(pRectangle->m_HaveFindFirst)
{
pRectangle->ShowSelectPoint(pDC);
pRectangle->DrawStatic(pDC);
pDoc->m_RectangleArray.RemoveAt(i);
delete pRectangle;
i--;
}
}
for(i=0;i<pDoc->m_RoundRectangleArray.GetSize();i++)
{
CRoundRectangle*pRoundRectangle=(CRoundRectangle*)pDoc->m_RoundRectangleArray.GetAt(i);
if(pRoundRectangle->m_HaveFindFirst)
{
pRoundRectangle->ShowSelectPoint(pDC);
pRoundRectangle->DrawStatic(pDC);
pDoc->m_RoundRectangleArray.RemoveAt(i);
delete pRoundRectangle;
i--;
}
}
for(i=0;i<pDoc->m_EllipseArray.GetSize();i++)
{
CEllipse*pEllipse=(CEllipse*)pDoc->m_EllipseArray.GetAt(i);
if(pEllipse->m_HaveFindFirst)
{ pEllipse->ShowSelectPoint(pDC);
pEllipse->DrawStatic(pDC);
pDoc->m_EllipseArray.RemoveAt(i);
delete pEllipse;
i--;
}
}
for(i=0;i<pDoc->m_RoundArray.GetSize();i++)
{
CRound*pRound=(CRound*)pDoc->m_RoundArray.GetAt(i);
if(pRound->m_HaveFindFirst)
{
pRound->ShowSelectPoint(pDC);
pRound->DrawStatic(pDC);
pDoc->m_RoundArray.RemoveAt(i);
delete pRound;
i--;
}
}
for(i=0;i<pDoc->m_LiEllipseArray.GetSize();i++)
{
CEllipse*pLiEllipse=(CEllipse*)pDoc->m_LiEllipseArray.GetAt(i);
if(pLiEllipse->m_HaveFindFirst)
{
pLiEllipse->ShowSelectPoint(pDC);
pLiEllipse->DrawStatic(pDC);
pDoc->m_LiEllipseArray.RemoveAt(i);
delete pLiEllipse;
i--;
}
}
for(i=0;i<pDoc->m_RoundArcArray.GetSize();i++)
{
CRoundArc*pRoundArc=(CRoundArc*)pDoc->m_RoundArcArray.GetAt(i);
if(pRoundArc->m_HaveFindFirst)
{
pRoundArc->ShowSelectPoint(pDC);
pRoundArc->DrawStatic(pDC);
pDoc->m_RoundArcArray.RemoveAt(i);
delete pRoundArc;
i--;
}
}
for(i=0;i<pDoc->m_EllipseArcArray.GetSize();i++)
{
CEllipseArc*pEllipseArc=(CEllipseArc*)pDoc->m_EllipseArcArray.GetAt(i);
if(pEllipseArc->m_HaveFindFirst)
{ pEllipseArc->ShowSelectPoint(pDC);
pEllipseArc->DrawStatic(pDC);
pDoc->m_EllipseArcArray.RemoveAt(i);
delete pEllipseArc;
i--;
}
}
pDC->SetROP2(oldrop);
}
void CEastDrawView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar==VK_DELETE)
this->DeleteSelect();
CScrollView::OnKeyUp(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -