DrawSetDlg.cpp
上传用户:do_tie
上传日期:2007-11-03
资源大小:1095k
文件大小:5k
- // DrawSetDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "GandyDraw.h"
- #include "DrawSetDlg.h"
- // CDrawSetDlg 对话框
- IMPLEMENT_DYNAMIC(CDrawSetDlg, CDialog)
- CDrawSetDlg::CDrawSetDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CDrawSetDlg::IDD, pParent)
- , m_iPenStyle(0)
- , m_iDrawStyle(0)
- , m_iHatchStyle(0)
- , m_BmpPathName(_T(""))
- , m_iPenWidth(0)
- , m_ComboIndex(0)
- , m_DrawRadio(0)
- , m_bIsFill(false)
- , m_iBrushStyle(0)
- , m_iBruStyle(0)
- , m_iBruHatchStyle(0)
- {
- ///CBitmap m_Bmp = new CBitmap();
- m_Bmp.LoadBitmapW(IDB_BITMAP_MM);
- CheckRadioButton(IDC_RADIO2,IDC_RADIO8,IDC_RADIO2);
- CheckRadioButton(IDC_RADIO12,IDC_RADIO15,IDC_RADIO12);
- }
- CDrawSetDlg::~CDrawSetDlg()
- {
- }
- void CDrawSetDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Text(pDX, IDC_PEN_WIDTH, m_iPenWidth);
- DDV_MinMaxInt(pDX, m_iPenWidth, 1, 100);
- DDX_CBIndex(pDX, IDC_PEN_STYLE_COMBO, m_ComboIndex);
- DDX_Radio(pDX, IDC_RADIO2, m_DrawRadio);
- DDX_Check(pDX, IDC_CHECK_FILL, m_bIsFill);
- DDX_Radio(pDX, IDC_RADIO12, m_iBruStyle);
- DDX_CBIndex(pDX, IDC_BRUSH_STR_COMBO, m_iBruHatchStyle);
- }
- BEGIN_MESSAGE_MAP(CDrawSetDlg, CDialog)
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_PEN_COLOR, &CDrawSetDlg::OnBnClickedPenColor)
- ON_BN_CLICKED(IDC_BRUSH_COLOR, &CDrawSetDlg::OnBnClickedBrushColor)
- ON_BN_CLICKED(IDOK, &CDrawSetDlg::OnBnClickedOk)
- END_MESSAGE_MAP()
- // CDrawSetDlg 消息处理程序
- void CDrawSetDlg::ShowImg(UINT ID, HBITMAP hBmp)
- {
- CWnd* pWnd = GetDlgItem(ID);
- CDC* pDC = pWnd->GetDC();
- CRect rect;
- pWnd->GetClientRect(&rect);
- pDC->FillSolidRect(&rect,RGB(128,128,128));
- pWnd->Invalidate();
- pWnd->UpdateWindow();
- BITMAP bs;
- GetObject(hBmp, sizeof(bs), &bs);
- CDC dc;
- if(dc.CreateCompatibleDC(pDC)) {
- int x0, y0, w, h;
- float rx = (float)bs.bmWidth / rect.right,
- ry = (float)bs.bmHeight / rect.bottom;
- if (rx >= ry) {
- x0 = 0; w = rect.right;
- h = (int)(bs.bmHeight / rx + 0.5);
- y0 = (rect.bottom - h) / 2;
- }
- else {
- y0 = 0; h = rect.bottom;
- w = (int)(bs.bmWidth / ry + 0.5);
- x0 = (rect.right - w) / 2;
- }
- ::SelectObject(dc.GetSafeHdc(), hBmp);
- pDC->SetStretchBltMode(HALFTONE);
- pDC->StretchBlt(x0, y0, w, h, &dc, 0, 0, bs.bmWidth, bs.bmHeight, SRCCOPY);
- SetDlgItemInt(IDC_BRUSH_BMP_WIDTH, bs.bmWidth);
- SetDlgItemInt(IDC_BRUSH_BMP_HEIGHT, bs.bmHeight);
- }
- }
- void CDrawSetDlg::FillColor(UINT ID, COLORREF col)
- {
- CWnd* pWnd = GetDlgItem(ID);
- CDC* pDC = pWnd->GetDC();
- pDC->SelectObject(new CPen(PS_SOLID, 1, RGB(0, 0, 0)));
- pDC->SelectObject(new CBrush(col));
- CRect rect;
- pWnd->GetClientRect(&rect);
- pWnd->Invalidate();
- pWnd->UpdateWindow();
- pDC->RoundRect(&rect, CPoint(8, 8));
- }
- void CDrawSetDlg::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: 在此处添加消息处理程序代码
- // 不为绘图消息调用 CDialog::OnPaint()
- FillColor(IDC_PEN_COLOR, m_PenColor);
- FillColor(IDC_BRUSH_COLOR, m_BrushColor);
- if(m_BmpPathName)
- {
- HBITMAP hBmp = (HBITMAP)LoadImage(NULL, m_BmpPathName,
- IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |
- LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
- if (hBmp != NULL) {
- BITMAP bm;
- GetObject(hBmp, sizeof(bm), &bm);
- long cb = bm.bmBitsPixel * bm.bmHeight * bm.bmWidthBytes;
- bm.bmBits = new char[cb];
- GetBitmapBits(hBmp, cb, bm.bmBits);
- m_Bmp.CreateBitmapIndirect(&bm);
- }
- }
-
- ShowImg(IDC_SHOWIMG,m_Bmp);
- }
- void CDrawSetDlg::OnBnClickedPenColor()
- {
- // TODO: 在此添加控件通知处理程序代码
- CColorDialog colDlg(m_PenColor);
- if (colDlg.DoModal() == IDOK) {
- m_PenColor = colDlg.GetColor();
- Invalidate();
- UpdateWindow();
- }
- }
- void CDrawSetDlg::OnBnClickedBrushColor()
- {
- // TODO: 在此添加控件通知处理程序代码
- CColorDialog colDlg(m_BrushColor);
- if (colDlg.DoModal() == IDOK) {
- m_BrushColor = colDlg.GetColor();
- Invalidate();
- UpdateWindow();
- }
- }
- void CDrawSetDlg::OnBnClickedOk()
- {
- /*switch(m_ComboIndex)
- {
- case 0:
- m_iPenStyle = PS_SOLID;
- break;
- case 1:
- m_iPenStyle = PS_DASH;
- break;
- case 2:
- m_iPenStyle = PS_DOT;
- break;
- case 3:
- m_iPenStyle = PS_DASHDOT;
- break;
- case 4:
- m_iPenStyle = PS_DASHDOTDOT;
- break;
- default:
- break;
- }*/
- m_iPenStyle = m_ComboIndex;
- Invalidate();
- UpdateData(true);
- if(m_bIsFill) //根据复选项在确定是否是实心
- {
- m_iBrushStyle = 1;
- }
- else
- {
- m_iBrushStyle = 0;
- }
- OnOK();
- }
- BOOL CDrawSetDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: 在此添加额外的初始化
- CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_PEN_STYLE_COMBO);
- pCB->AddString(L"实线");
- pCB->AddString(L"点线");
- pCB->AddString(L"虚线");
- pCB->AddString(L"虚点线");
- pCB->AddString(L"虚点点线");
- pCB->SetCurSel(m_ComboIndex);
- if(m_iBrushStyle == 1)
- {
- CheckDlgButton(IDC_CHECK_FILL, 1);
- }
- CComboBox* pCB1 = (CComboBox*)GetDlgItem(IDC_BRUSH_STR_COMBO);
- pCB1->AddString(L"水平线");
- pCB1->AddString(L"垂直线");
- pCB1->AddString(L"正斜线");
- pCB1->AddString(L"反斜线");
- pCB1->AddString(L"十字线");
- pCB1->AddString(L"斜十字线");
- pCB1->SetCurSel(m_iBruHatchStyle);
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }