📄 lwq6231view.cpp
字号:
void CLWQ6231View::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CSize size(1280, 1024);//设置绘图区范围为:1280*1024
// SetScrollSizes(MM_TEXT, size);
}
void CLWQ6231View::OnUpdateArrow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nMouseMode == IDT_ARROW);
}
void CLWQ6231View::OnUpdateLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nMouseMode == IDT_LINE);
}
void CLWQ6231View::OnUpdateRectangle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nMouseMode == IDT_RECTANGLE);
}
void CLWQ6231View::OnUpdateEllipse(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nMouseMode == IDT_ELLIPSE);
}
void CLWQ6231View::OnUpdateCircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nMouseMode == IDT_CIRCLE);
}
void CLWQ6231View::OnUpdatePline(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nMouseMode == IDT_PLINE);
}
void CLWQ6231View::OnUpdateFont(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nMouseMode == IDT_FONT);
}
void CLWQ6231View::OnLine()
{
// TODO: Add your command handler code here
m_nMouseMode = IDT_LINE;
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurCross);//修改缺省光标
}
void CLWQ6231View::OnRectangle()
{
// TODO: Add your command handler code here
m_nMouseMode = IDT_RECTANGLE;
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurCross);//修改缺省光标
}
void CLWQ6231View::OnEllipse()
{
// TODO: Add your command handler code here
m_nMouseMode = IDT_ELLIPSE;
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurCross);//修改缺省光标
}
void CLWQ6231View::OnCircle()
{
// TODO: Add your command handler code here
m_nMouseMode = IDT_CIRCLE;
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurCross);//修改缺省光标
}
void CLWQ6231View::OnFont()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
LOGFONT m_lFont;
COLORREF m_cTextColor;
CFont myFont;
CFont* pOldFont;
CFontDialog FontDlg;
FontDlg.m_cf.lpLogFont = &m_lFont;
FontDlg.m_cf.rgbColors = m_cTextColor;
FontDlg.m_cf.Flags != CF_INITTOLOGFONTSTRUCT;
if( FontDlg.DoModal() == IDOK )
{
FontDlg.GetCurrentFont(&m_lFont);
m_cTextColor = FontDlg.GetColor();
}
CString str;
CTextDlg TextDlg;
// CRect rect(TextDlg.m_ctrEdit.GetClientRect());
if( TextDlg.DoModal() == IDOK )
{
CRect rect(TextDlg.m_iPosX, TextDlg.m_iPosY,
TextDlg.m_iPosX + 100, TextDlg.m_iPosY + 100);
str = TextDlg.m_sText;
myFont.CreateFontIndirect(&m_lFont);
pOldFont = pDC->SelectObject(&myFont);
pDC->SetTextColor(m_cTextColor);
pDC->DrawText(str, rect, 0);
pDC->SelectObject(pOldFont);
SaveInStack();
}
}
void CLWQ6231View::OnFileNew()
{
// TODO: Add your command handler code here
// m_strName = name;
m_usrCurrentObject = NULL;
// m_pStack->Clear();
m_bDrawing=false;
m_nMouseMode = IDT_LINE;
m_usrCurrentObject = NULL;
m_nCurrentColor = UD_RED;
m_iPenWidth = WIDTH_THIN;
m_bFill = false;
m_pSelect = NULL; //没有选中区域
m_bClip = false; //剪贴扳为空
virtualline=false;
delete m_pStack;
m_pStack =new Stack(3); //栈的大小
m_bFirstSave = true; //可以保存空白屏幕
showgrid = false;
CDC* pDC = GetDC();
CRect rect;
GetClientRect(&rect);
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, WHITENESS);
OnPaint();
}
void CLWQ6231View::OnUpdateDelete(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_nMouseMode == IDT_ARROW && m_usrCurrentObject != NULL);
//当选中图元时,才可使用删除功能
}
void CLWQ6231View::OnSelect()
{
// TODO: Add your command handler code here
m_nMouseMode = IDT_SELECT;
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurArrow);//修改缺省光标
}
void CLWQ6231View::OnEditCopy()
{
// TODO: Add your command handler code here
if (showgrid)
Grid();
if( !m_pSelect )
return;
m_bClip = true;
CBitmap bitmap;
CClientDC dc(this);
CDC memDC;
CRect 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+1, y+1);
bitmap.CreateCompatibleBitmap(&dc, width-1, height-1);
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
memDC.BitBlt(0, 0, width, height, &dc, 0, 0, SRCCOPY);
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP, bitmap.GetSafeHandle());
CloseClipboard();
//m_pSelect->copied=true;
memDC.SelectObject(pOldBitmap);
bitmap.Detach();
virtualline=true;
if (showgrid) Grid();
}
void CLWQ6231View::OnEditCut()
{
if (showgrid) Grid();
if( !m_pSelect )
return;
CDC *pdc = GetDC();
m_bClip = true;
CBitmap bitmap;
CClientDC dc(this);
CDC memDC;
CRect rect;
GetWindowRect(rect);
m_pSelect->Clear(pdc);
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);
bitmap.CreateCompatibleBitmap(&dc, width, height);
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
memDC.BitBlt(0, 0, width, height, &dc, 0, 0, SRCCOPY);
OpenClipboard();
EmptyClipboard();
SetClipboardData (CF_BITMAP, bitmap.GetSafeHandle() );
CloseClipboard();
dc.OffsetViewportOrg(-x, -y);
if (!(m_pSelect->copied))//如果剪切的还没复制过就变白
{
pdc->BitBlt(x, y, width+1, height+1, &dc, 0, 0, WHITENESS);
Back_Copy();
memDC.SelectObject(pOldBitmap);
bitmap.Detach();
//bit1=bitmap;
}
else //如果剪切的已经复制,不变白
{
CDC* pDC = GetDC();
CDC dc;
CClientDC pdc(this);
if(!dc.CreateCompatibleDC(pDC))
return;
BITMAP bm;
m_pSelect->backmap.GetBitmap(&bm);
CBitmap *pOldBitmap=dc.SelectObject(&m_pSelect->backmap);
pdc.BitBlt(0,0,bm.bmWidth, bm.bmHeight, &dc, 0, 0, SRCCOPY);
dc.SelectObject(&pOldBitmap);
}
m_pSelect->Set(pdc,-width,-height,width,height);
if (showgrid)
Grid();
virtualline=false;
SaveInStack();
}
void CLWQ6231View::OnEditPaste()
{
// TODO: Add your command handler code here
CDC dc;
CDC * pDC = GetDC();
if (virtualline)
if (m_pSelect)
m_pSelect->Clear(pDC);
m_pSelect = new CDrawSelect(m_nCurrentColor);
Back_Copy();//保存背景图
if(!dc.CreateCompatibleDC(pDC))
return;
BITMAP bm;
HBITMAP hBitmap;
OpenClipboard();
hBitmap = (HBITMAP)GetClipboardData(CF_BITMAP);
m_pSelect->map_select.Detach();
m_pSelect->map_select.Attach(hBitmap);
m_pSelect->map_select.GetBitmap(&bm);
dc.SelectObject(&m_pSelect->map_select);
pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dc, 0, 0, SRCCOPY);
CloseClipboard();
m_pSelect->Set(pDC,0,0,bm.bmWidth,bm.bmHeight);
m_bDrawing=false;
m_pSelect->copied=true;
virtualline=true;
}
void CLWQ6231View::OnFileSave()
{
// TODO: Add your command handler code here
CClientDC dc(this);
CDC memDC;
CRect rect;
GetClientRect(rect);
memDC.CreateCompatibleDC(&dc);
CBitmap bm;
int Width = rect.Width();
int Height = rect.Height();
bm.CreateCompatibleBitmap(&dc, Width, Height);
CBitmap* pOld = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, Width, Height, &dc, 0, 0, SRCCOPY);
memDC.SelectObject(pOld);
BITMAP btm;
bm.GetBitmap(&btm);
DWORD size = btm.bmWidthBytes * btm.bmHeight;
LPSTR lpData = (LPSTR)GlobalAllocPtr(GPTR, size);
BITMAPFILEHEADER bfh;
/////////////////////////////////////////////
BITMAPINFOHEADER bih;
bih.biBitCount = btm.bmBitsPixel;
bih.biClrImportant = 0;
bih.biClrUsed = 0;
bih.biCompression = 0;
bih.biHeight = btm.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = size;
bih.biWidth = btm.bmWidth;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
//bm.GetBitmapBits(size,lpData);//此函数在处理5-5-5模式的16位色下会出现颜色混乱
bfh.bfReserved1 = bfh.bfReserved2 = 0;
bfh.bfType = ((WORD)('M'<< 8)|'B');
bfh.bfSize = 54 + size;
bfh.bfOffBits = 54;
CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.*|*.*|"));
if (dlg.DoModal()!=IDOK)
return;
CFile bf;
CString ss=dlg.GetPathName();
if(bf.Open(ss, CFile::modeCreate | CFile::modeWrite))
{
bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER));
bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER));
bf.WriteHuge(lpData, size);
bf.Close();
AfxMessageBox("保存成功");
}
GlobalFreePtr(lpData);
}
void CLWQ6231View::OnFileOpen()
{
// TODO: Add your command handler code here
CDC dc;
CDC * pDC = GetDC();
if(!dc.CreateCompatibleDC(pDC))
return;
CBitmap b;
BITMAP bm;
CString path;
CFileDialog dlg(true,_T("BMP"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.*|*.*|"));
if (dlg.DoModal()==IDOK)
{
path =dlg.GetPathName();
}
else
return;
HBITMAP hbmp = (HBITMAP)LoadImage(NULL, _T(path), IMAGE_BITMAP,
0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
b.Attach(hbmp);
b.GetBitmap(&bm);
dc.SelectObject(&b);
pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dc, 0, 0, SRCCOPY);
}
void CLWQ6231View::OnColorBlack()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_BLACK;
}
void CLWQ6231View::OnColorBlue()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_BLUE;
if(m_usrCurrentObject && m_usrCurrentObject->m_bSelected)
{//更新当前选择图元的显示
m_usrCurrentObject->SetPenColor(m_nCurrentColor);
Invalidate();
}
}
void CLWQ6231View::OnColorCyan()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_CYAN;
}
void CLWQ6231View::OnColorGray()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_GRAY;
}
void CLWQ6231View::OnColorGreen()
{
// TODO: Add your command handler code here
m_nCurrentColor = UD_GREEN;
if(m_usrCurrentObject && m_usrCurrentObject->m_bSelected)
{//更新当前选择图元的显示
m_usrCurrentObject->SetPenColor(m_nCurrentColor);
Invalidate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -