CustomDlg.cpp
上传用户:ywlong9188
上传日期:2022-05-31
资源大小:2656k
文件大小:3k
- // CustomDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "drawobj.h"
- #include "projdoc.h"
- #include "projview.h"
- #include "CustomDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCustomDlg dialog
- CCustomDlg::CCustomDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CCustomDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CCustomDlg)
- m_index = -1;
- //}}AFX_DATA_INIT
- m_pView = NULL;
- m_pList = NULL;
- }
- void CCustomDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCustomDlg)
- DDX_Control(pDX, IDC_COMBO1, m_combox);
- DDX_CBIndex(pDX, IDC_COMBO1, m_index);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CCustomDlg, CDialog)
- //{{AFX_MSG_MAP(CCustomDlg)
- ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCustomDlg message handlers
- BOOL CCustomDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- POSITION pos = m_list.GetHeadPosition();
- while(pos!=NULL)
- {
- m_combox.AddString(m_list.GetNext(pos));
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CCustomDlg::OnSelchangeCombo1()
- {
- UpdateData(TRUE);
- CClientDC dc(this);
-
- dc.SetMapMode(MM_ANISOTROPIC);
- dc.SetViewportExt(dc.GetDeviceCaps(LOGPIXELSX),
- dc.GetDeviceCaps(LOGPIXELSY));
- dc.SetWindowExt(100, -100);
- dc.OffsetViewportOrg(0,0);
-
- CRect rect(CPoint(10,-20),CSize(100,-100));
- dc.LPtoDP(rect);
- InvalidateRect(rect,TRUE);
- }
- void CCustomDlg::PrepareView(CProjView* pView)
- {
- ASSERT_VALID(pView);
-
- m_pView = pView;
- if(!(((pView->GetDocument())->m_customList).IsEmpty()))
- m_pList = &((pView->GetDocument())->m_customList);
- }
- void CCustomDlg::OnPaint()
- {
- int nWidth,nHeight;
- float xRate,yRate;
- CPaintDC dc(this); // device context for painting
-
- dc.SetMapMode(MM_ANISOTROPIC);
- dc.SetViewportExt(dc.GetDeviceCaps(LOGPIXELSX),
- dc.GetDeviceCaps(LOGPIXELSY));
- dc.SetWindowExt(100, -100);
- dc.OffsetViewportOrg(0,0);
- if(m_pList != NULL)
- {
- if(m_index >= 0)
- {
- POSITION pos = m_pList->FindIndex(m_index);
- CDrawObj* pObj = (m_pList->GetAt(pos));
- CRect rect;
- CRect originalRect = pObj->m_position;
- pObj->CustomRect(rect);
- rect.NormalizeRect();
-
- xRate = rect.Width()*1.0/rect.Height();
- yRate = rect.Height()*1.0/rect.Width();
-
- nWidth = (abs(rect.Width())>abs(rect.Height()))?100:abs(100*xRate);
- nHeight = (abs(rect.Width())<abs(rect.Height()))?100:abs(100*yRate);
-
- pObj->m_position = CRect(CPoint(10,-20),CSize(nWidth,-nHeight));
- pObj->OriginalRect(pObj->m_position,originalRect);
- pObj->MoveTo(pObj->m_position,m_pView);
- pObj->Draw(&dc);
- }
- }
- }