- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
eDrawDlg.cpp
资源名称:eDraw2 [点击查看]
上传用户:fjzzwyy
上传日期:2007-01-14
资源大小:244k
文件大小:20k
源码类别:
绘图程序
开发平台:
Visual C++
- // eDrawDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "eDraw.h"
- #include "eDrawDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEDrawDlg dialog
- CEDrawDlg::CEDrawDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CEDrawDlg::IDD, pParent)
- {
- m_BGBrush.CreateSolidBrush(RGB(255,255,255));
- //{{AFX_DATA_INIT(CEDrawDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CEDrawDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEDrawDlg)
- DDX_Control(pDX, IDC_SBARCTRLAXIS, m_statusAxis);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CEDrawDlg, CDialog)
- //{{AFX_MSG_MAP(CEDrawDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_CTLCOLOR()
- ON_WM_SETCURSOR()
- ON_WM_LBUTTONDBLCLK()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_OUTBAR_NOTIFY, OnOutbarNotify)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEDrawDlg message handlers
- BOOL CEDrawDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- DWORD dwf = CGfxOutBarCtrl::fDragItems|CGfxOutBarCtrl::fEditGroups|CGfxOutBarCtrl::fEditItems|CGfxOutBarCtrl::fRemoveGroups|
- CGfxOutBarCtrl::fRemoveItems|CGfxOutBarCtrl::fAddGroups|CGfxOutBarCtrl::fAnimation;
- // |CGfxOutBarCtrl::fSelHighlight;
- wndBar.Create(WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN, CRect(550,0,650,550),this,12345 , dwf);
- wndBar.SetOwner(this);
- CBitmap bm1,bm2,bm3;
- bm1.LoadBitmap(IDB_IMAGELIST);
- imaLarge.Create( 36, 36, ILC_COLOR24,8, 8 );
- imaLarge.Add(&bm1,RGB(0,0,0));
- bm2.LoadBitmap(IDB_IMAGEDISABLELIST);
- imaDisable.Create( 36,36,ILC_COLOR24,8,8 );
- imaDisable.Add(&bm2,RGB(0,0,0));
- bm3.LoadBitmap(IDB_IMAGESUNKENLIST);
- imaSunken.Create( 36,36,ILC_COLOR24,8,8 );
- imaSunken.Add(&bm3,RGB(255,255,255));
- // imaLarge.Create(IDB_IMAGELIST, 36, 0, RGB(127,127,127));
- imaSmall.Create(IDB_SMALL_IMAGELIST, 16, 0, RGB(0,128,128));
- wndBar.SetImageList(&imaLarge, CGfxOutBarCtrl::fLargeIcon);
- wndBar.SetImageList(&imaSmall, CGfxOutBarCtrl::fSmallIcon);
- wndBar.SetImageList(&imaDisable, CGfxOutBarCtrl::fDisableIcon);
- wndBar.SetImageList(&imaSunken,CGfxOutBarCtrl::fSunkenIcon);
- wndBar.SetAnimationTickCount(20);
- wndBar.SetAnimSelHighlight(200);
- wndBar.AddFolder("操作", 0);
- wndBar.AddFolder("直线", 1);
- wndBar.AddFolder("多边形 填充", 2);
- wndBar.AddFolder("二次曲线", 3);
- wndBar.InsertItem(0, 0, "打开存档", 0, 0,ENABLE);
- wndBar.InsertItem(0, 1, "保存档案", 1, 0,ENABLE);
- wndBar.InsertItem(0, 2, "擦除部分", 2, 0);
- wndBar.InsertItem(0, 3, "擦除全部", 3, 0);
- wndBar.InsertItem(0, 4, "设画笔色", 4, 0);
- wndBar.InsertItem(0, 5, "关于eDraw", 5, 0);
- wndBar.InsertItem(0, 6, "退出程序", 6, 0);
- wndBar.InsertItem(1, 0, "自由画线", 7,0);
- wndBar.InsertItem(1, 1, "逐点比较法",8,0);
- wndBar.InsertItem(1, 2, "DDA算法", 9,0);
- wndBar.InsertItem(1, 3, "Bresenham", 10,0);
- wndBar.InsertItem(1, 4, "粗线算法", 11,0);
- wndBar.InsertItem(1, 5, "虚线算法", 12,0);
- wndBar.InsertItem(2, 0, "画多边形", 13, 0);
- wndBar.InsertItem(2, 1, "判定凹凸性", 14, 0);
- wndBar.InsertItem(2, 2, "种子填充", 15, 0);
- wndBar.InsertItem(2, 3, "扫描线填充", 16, 0);
- wndBar.InsertItem(2, 4, "边标志填充", 17, 0);
- wndBar.InsertItem(3, 0, "画圆", 18, 0);
- wndBar.InsertItem(3, 1, "圆弧", 19, 0);
- wndBar.InsertItem(3, 2, "椭圆", 20, 0);
- wndBar.InsertItem(3, 3, "椭圆弧", 21, 0);
- wndBar.InsertItem(3, 4, "抛物线", 22, 0);
- wndBar.InsertItem(3, 5, "双曲线", 23, 0);
- wndBar.SetItemState(1,1,ENABLE);
- wndBar.SetSelFolder(0);
- CDC * pDC = GetDC();
- CRect clientRect(0,0,550,550);
- int cx = clientRect.Width();
- int cy = clientRect.Height();
- CDC memDC;
- memDC.CreateCompatibleDC(pDC);
- currentClientBmp.CreateCompatibleBitmap(pDC,
- cx,
- cy);
- memDC.SelectObject(¤tClientBmp);
- memDC.PatBlt(0,0,
- cx,cy,
- RGB(255,255,255));
- memDC.DeleteDC();
- m_isDrawing=false;
- m_CurrentPenColor=RGB(0,0,0);
- m_CurrentBGColor=RGB(255,255,255);
- m_PolyPointCount=0;m_LastPolyPointCount;
- m_Step=0;
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CEDrawDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CEDrawDlg::OnPaint()
- {
- RestoreClientFromDC();
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CEDrawDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CEDrawDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- CDC* pDC=GetDC();
- // TODO: Add your message handler code here and/or call default
- CString axis;
- axis.Format("X=%ld Y=%ld",point.x,point.y);
- m_statusAxis.SetSimpleText(axis);
- if (!m_isDrawing) return;
- switch (m_DrawMode){
- case DRAWMODE_ERASE:
- {
- m_isDrawing = true;
- CPen pen,* oldpen;
- pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
- oldpen = pDC->SelectObject(&pen);
- CBrush brush,* oldbrush;
- brush.CreateSolidBrush(RGB(255,255,255));
- oldbrush = pDC->SelectObject(&brush);
- pDC->Rectangle(point.x,point.y,
- point.x+14,point.y+11);
- pDC->SelectObject(oldpen);
- pDC->SelectObject(oldbrush);
- }
- break;
- case DRAWMODE_LINE:
- if (m_LineMode!=LINEMODE_FREE)
- RestoreClientFromDC();
- switch(m_LineMode){
- case LINEMODE_FREE:
- DrawLine_BresenHam(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
- StartPoint.x=point.x;StartPoint.y=point.y;
- break;
- case LINEMODE_BPB:
- DrawLine_BPB(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
- break;
- case LINEMODE_DDA:
- DrawLine_DDA(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
- break;
- case LINEMODE_BRESENHAM:
- DrawLine_BresenHam(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
- break;
- case LINEMODE_BROKEN:
- DrawLine_BresenHam_Broken(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
- break;
- case LINEMODE_THICK:
- DrawLine_Thick(pDC,StartPoint.x,StartPoint.y,point.x,point.y,10,m_CurrentPenColor);
- break;
- }
- break;
- case DRAWMODE_POLY:
- RestoreClientFromDC();
- if (m_PolyPointCount>0)
- DrawLine_BresenHam(pDC,m_PolyPoint[m_PolyPointCount-1].x,m_PolyPoint[m_PolyPointCount-1].y,point.x,point.y,m_CurrentPenColor);
- break;
- case DRAWMODE_CIRCLE:
- {
- RestoreClientFromDC();
- int minx=StartPoint.x>point.x?point.x:StartPoint.x;
- int maxx=StartPoint.x<point.x?point.x:StartPoint.x;
- int miny=StartPoint.y>point.y?point.y:StartPoint.y;
- int maxy=StartPoint.y<point.y?point.y:StartPoint.y;
- if ((maxx-minx)>(maxy-miny))
- DrawCircle(pDC,minx+(maxx-minx)/2,
- miny+(maxy-miny)/2,(maxx-minx)/2,m_CurrentPenColor);
- else
- DrawCircle(pDC,minx+(maxx-minx)/2,
- miny+(maxy-miny)/2,(maxy-miny)/2,m_CurrentPenColor);
- }
- break;
- case DRAWMODE_ELLIPSE:
- {
- RestoreClientFromDC();
- int minx=StartPoint.x>point.x?point.x:StartPoint.x;
- int maxx=StartPoint.x<point.x?point.x:StartPoint.x;
- int miny=StartPoint.y>point.y?point.y:StartPoint.y;
- int maxy=StartPoint.y<point.y?point.y:StartPoint.y;
- DrawEllipse(pDC,minx+(maxx-minx)/2,
- miny+(maxy-miny)/2,(maxx-minx)/2,(maxy-miny)/2,m_CurrentPenColor);
- }
- break;
- case DRAWMODE_PIPO:
- {
- if (m_Step==2) {
- RestoreClientFromDC();
- DrawPipo(pDC,StartPoint.x,StartPoint.y,point.x,point.y,EndPoint.x,EndPoint.y,m_CurrentPenColor);
- }
- }
- break;
- }
- CDialog::OnMouseMove(nFlags, point);
- }
- BOOL CEDrawDlg::SaveCurrentClientToDC()
- {
- CDC * pDC = GetDC();
- CDC memDC;
- CRect clientRect(0,0,550,550);
- int cx = clientRect.Width();
- int cy = clientRect.Height();
- memDC.CreateCompatibleDC(pDC);
- memDC.SelectObject(¤tClientBmp);
- memDC.BitBlt(0,0,cx,
- cy,pDC,clientRect.left,clientRect.top,SRCCOPY);
- memDC.DeleteDC();
- ReleaseDC(pDC);
- return TRUE;
- }
- BOOL CEDrawDlg::RestoreClientFromDC()
- {
- CDC * pDC = GetDC();
- CRect clientRect(0,0,550,550);
- CDC memDC;
- memDC.CreateCompatibleDC(pDC);
- memDC.SelectObject(¤tClientBmp);
- int cx = clientRect.Width();
- int cy = clientRect.Height();
- pDC->BitBlt(clientRect.left,clientRect.top,cx,cy,
- &memDC,0,0,SRCCOPY);
- memDC.DeleteDC();
- ReleaseDC(pDC);
- return TRUE;
- }
- long CEDrawDlg::OnOutbarNotify(WPARAM wParam, LPARAM lParam)
- {
- CDC* pDC=GetDC();
- switch (wParam)
- {
- case NM_OB_ITEMCLICK: //项双击处理
- // cast the lParam to an integer to get the clicked item
- {
- int index = (int) lParam; //当前双击项的索引值
- int curFolder;
- curFolder = wndBar.GetSelFolder(); //当前组的索引值
- if(wndBar.GetItemState(curFolder,index)==DISABLE)
- break;
- //以下为要各个功能的接入处
- switch(curFolder)
- {
- case 0: //operation
- switch(index)
- {
- case 0: //open
- {
- CFileDialog Fdlg(TRUE,"BMP",0, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
- "位图文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||");
- if (Fdlg.DoModal()==IDOK){
- bitmap.LoadBMP(Fdlg.GetFileName());
- bitmap.DrawImg(pDC,0,0,bitmap.m_Width,bitmap.m_Height);
- }
- }
- SaveCurrentClientToDC();
- break;
- case 1:
- {
- CFileDialog FDlg(FALSE,"BMP",0, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
- "位图文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||");
- if (FDlg.DoModal()==IDOK){
- bitmap.SaveBMP(pDC,0,0,bitmap.m_Width,bitmap.m_Height,FDlg.GetFileName());
- }
- }
- break;
- case 2:
- m_DrawMode=DRAWMODE_ERASE;
- m_CursorMode=CURSORMODE_ERASE;
- SendMessage(WM_SETCURSOR);
- break;
- case 3:
- ClearClient();
- break;
- case 4:
- {
- CColorDialog dlg;
- dlg.DoModal();
- m_CurrentPenColor=dlg.GetColor();
- }
- break;
- case 5:
- {
- SetCapture();
- CAboutDlg about;
- about.DoModal();
- ReleaseCapture();
- }
- break;
- case 6:
- /* CPen pen;
- pen.CreatePen(PS_SOLID,10,RGB(0,0,0));
- pDC->SelectObject(&pen);
- pDC->MoveTo(200,200);
- pDC->LineTo(200,200);
- pen.DeleteObject();*/
- if(AfxMessageBox("确认退出吗?",MB_OKCANCEL)==IDOK)
- exit(0);
- break;
- }
- break;
- case 1:
- m_DrawMode=DRAWMODE_LINE;
- m_CursorMode=CURSORMODE_PEN;
- switch(index)
- {
- case 0:
- m_LineMode=LINEMODE_FREE;
- break;
- case 1:
- m_LineMode=LINEMODE_BPB;
- break;
- case 2:
- m_LineMode=LINEMODE_DDA;
- break;
- case 3:
- m_LineMode=LINEMODE_BRESENHAM;
- break;
- case 4:
- m_LineMode=LINEMODE_THICK;
- break;
- case 5:
- m_LineMode=LINEMODE_BROKEN;
- break;
- }
- break;
- case 2:
- switch(index){
- case 0:
- m_DrawMode=DRAWMODE_POLY;
- m_CursorMode=CURSORMODE_PEN;
- break;
- case 1:
- DecidePolygonUpper(m_LastPolyPointCount,m_PolyPoint);
- break;
- case 2:
- m_DrawMode=DRAWMODE_FILL;
- m_CursorMode=CURSORMODE_FILL;
- break;
- case 3:
- m_CursorMode=CURSORMODE_STANDARD;
- if(m_LastPolyPointCount==NULL) AfxMessageBox("请先画一多边形!");
- else{
- PointType *pts;
- int ymax=m_PolyPoint[0].y;
- pts= (PointType *) malloc(sizeof(PointType)*m_LastPolyPointCount);
- for(int i=0;i<m_LastPolyPointCount;i++){
- pts[i].x =m_PolyPoint[i].x;
- pts[i].y =m_PolyPoint[i].y;
- if(m_PolyPoint[i].y>ymax) ymax=m_PolyPoint[i].y;
- }
- if(pts==NULL) AfxMessageBox("pts is null!");
- else scanFill(pDC,m_LastPolyPointCount,pts,ymax,m_CurrentPenColor);
- SaveCurrentClientToDC();
- }
- break;
- case 4:
- m_CursorMode=CURSORMODE_STANDARD;
- if(m_LastPolyPointCount==0) AfxMessageBox("请先画一多边形!");
- else edgeflagscan(pDC,m_PolyPoint,m_LastPolyPointCount,m_CurrentPenColor);
- SaveCurrentClientToDC();
- break;
- }
- break;
- case 3:
- switch(index){
- case 0:
- m_DrawMode=DRAWMODE_CIRCLE;
- m_CursorMode=CURSORMODE_CROSS;
- break;
- case 2:
- m_DrawMode=DRAWMODE_ELLIPSE;
- m_CursorMode=CURSORMODE_CROSS;
- break;
- case 5:
- m_DrawMode=DRAWMODE_PIPO;
- m_CursorMode=CURSORMODE_CROSS;
- break;
- }
- }
- }
- }
- return 0;
- }
- void CEDrawDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CDC* pDC=GetDC();
- CRect rect;
- GetWindowRect(&rect);
- rect.right-=105;rect.bottom-=30;
- rect.top+=25;rect.left+=5;
- // TODO: Add your message handler code here and/or call default
- switch (m_DrawMode){
- case DRAWMODE_ERASE:
- {
- m_isDrawing = true;
- CPen pen,* oldpen;
- pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
- oldpen = pDC->SelectObject(&pen);
- CBrush brush,* oldbrush;
- brush.CreateSolidBrush(RGB(255,255,255));
- oldbrush = pDC->SelectObject(&brush);
- pDC->RoundRect(point.x,point.y,
- point.x+14,point.y+11,5,5);
- pDC->SelectObject(oldpen);
- pDC->SelectObject(oldbrush);
- }
- break;
- case DRAWMODE_LINE:
- //if (m_LineMode!=LINEMODE_FREE) RestoreClientFromDC();
- StartPoint.x=point.x;StartPoint.y=point.y;
- ClipCursor(&rect);
- m_isDrawing=true;
- break;
- case DRAWMODE_POLY:
- if (m_PolyPointCount==0){
- m_PolyPoint[0].x=point.x;m_PolyPoint[0].y=point.y;
- m_PolyPointCount++;
- m_isDrawing=true;
- ClipCursor(&rect);
- }else{
- m_PolyPoint[m_PolyPointCount].x=point.x;m_PolyPoint[m_PolyPointCount].y=point.y;
- SaveCurrentClientToDC();
- m_PolyPointCount++;
- }
- break;
- case DRAWMODE_FILL:
- BeginWaitCursor();
- m_isDrawing=true;
- SeedFill(pDC,point,m_CurrentPenColor);
- m_isDrawing=false;
- SaveCurrentClientToDC();
- EndWaitCursor();
- break;
- case DRAWMODE_CIRCLE:
- case DRAWMODE_ELLIPSE:
- StartPoint.x=point.x;StartPoint.y=point.y;
- ClipCursor(&rect);
- m_isDrawing=true;
- break;
- case DRAWMODE_PIPO:
- if (m_Step==0) {
- StartPoint.x=point.x;StartPoint.y=point.y;
- pDC->SetPixelV(point.x,point.y,m_CurrentPenColor);
- m_Step++;
- m_isDrawing=true;
- break;
- }
- if (m_Step==1) {
- EndPoint.x=point.x;EndPoint.y=point.y;
- pDC->SetPixelV(point.x,point.y,m_CurrentPenColor);
- m_Step++;
- break;
- }
- if (m_Step==2) {
- SaveCurrentClientToDC();
- m_Step=0;
- m_isDrawing=false;
- break;
- }
- break;
- }
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CEDrawDlg::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDC* pDC=GetDC();
- // TODO: Add your message handler code here and/or call default
- switch (m_DrawMode){
- case DRAWMODE_ERASE:
- m_isDrawing=false;
- SaveCurrentClientToDC();
- break;
- case DRAWMODE_LINE:
- SaveCurrentClientToDC();
- m_isDrawing=false;
- ClipCursor(NULL);
- break;
- case DRAWMODE_CIRCLE:
- case DRAWMODE_ELLIPSE:
- SaveCurrentClientToDC();
- m_isDrawing=false;
- ClipCursor(NULL);
- break;
- }
- CDialog::OnLButtonUp(nFlags, point);
- }
- BOOL CEDrawDlg::ClearClient()
- {
- CDC* pDC=GetDC();
- CRect clientRect(0,0,550,550);
- int cx = clientRect.Width();
- int cy = clientRect.Height();
- CDC memDC;
- memDC.CreateCompatibleDC(pDC);
- memDC.SelectObject(¤tClientBmp);
- memDC.PatBlt(0,0,
- cx,cy,
- m_CurrentBGColor);
- memDC.DeleteDC();
- Invalidate();
- m_isDrawing=false;
- return TRUE;
- }
- HBRUSH CEDrawDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- // TODO: Change any attributes of the DC here
- // TODO: Return a different brush if the default is not desired
- return m_BGBrush;
- }
- BOOL CEDrawDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- // TODO: Add your message handler code here and/or call default
- if (nHitTest!=HTCLIENT){
- HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_STANDARD);
- SetCursor(hcursor);
- return true;
- }
- if (m_CursorMode==CURSORMODE_STANDARD) {
- HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_STANDARD);
- SetCursor(hcursor);
- return true;
- }
- if (m_CursorMode==CURSORMODE_PEN) {
- HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_PEN);
- SetCursor(hcursor);
- return true;
- }
- if (m_CursorMode==CURSORMODE_FILL) {
- HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_FILL);
- SetCursor(hcursor);
- return true;
- }
- if (m_CursorMode==CURSORMODE_CROSS) {
- HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_CROSSCUR);
- SetCursor(hcursor);
- return true;
- }
- if (m_CursorMode==CURSORMODE_ERASE) {
- HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_ERASE);
- SetCursor(hcursor);
- return true;
- }
- return CDialog::OnSetCursor(pWnd, nHitTest, message);
- }
- void CEDrawDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDC* pDC=GetDC();
- switch (m_DrawMode){
- case DRAWMODE_POLY:
- DrawLine_BresenHam(pDC,m_PolyPoint[0].x,m_PolyPoint[0].y,point.x,point.y,m_CurrentPenColor);
- SaveCurrentClientToDC();
- m_isDrawing=false;
- m_LastPolyPointCount=m_PolyPointCount;
- m_PolyPointCount=0;
- ClipCursor(NULL);
- }
- CDialog::OnLButtonDblClk(nFlags, point);
- }