CustomDlg.cpp
上传用户:ywlong9188
上传日期:2022-05-31
资源大小:2656k
文件大小:3k
源码类别:

远程控制编程

开发平台:

C/C++

  1. // CustomDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "drawobj.h"
  5. #include "projdoc.h"
  6. #include "projview.h"
  7. #include "CustomDlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CCustomDlg dialog
  15. CCustomDlg::CCustomDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CCustomDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CCustomDlg)
  19. m_index = -1;
  20. //}}AFX_DATA_INIT
  21. m_pView = NULL;
  22. m_pList = NULL;
  23. }
  24. void CCustomDlg::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CCustomDlg)
  28. DDX_Control(pDX, IDC_COMBO1, m_combox);
  29. DDX_CBIndex(pDX, IDC_COMBO1, m_index);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CCustomDlg, CDialog)
  33. //{{AFX_MSG_MAP(CCustomDlg)
  34. ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  35. ON_WM_PAINT()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CCustomDlg message handlers
  40. BOOL CCustomDlg::OnInitDialog() 
  41. {
  42. CDialog::OnInitDialog();
  43. // TODO: Add extra initialization here
  44. POSITION pos = m_list.GetHeadPosition();
  45. while(pos!=NULL)
  46. {
  47. m_combox.AddString(m_list.GetNext(pos));
  48. }
  49. return TRUE;  // return TRUE unless you set the focus to a control
  50.               // EXCEPTION: OCX Property Pages should return FALSE
  51. }
  52. void CCustomDlg::OnSelchangeCombo1() 
  53. {
  54. UpdateData(TRUE);
  55. CClientDC dc(this);
  56. dc.SetMapMode(MM_ANISOTROPIC);
  57. dc.SetViewportExt(dc.GetDeviceCaps(LOGPIXELSX),
  58. dc.GetDeviceCaps(LOGPIXELSY));
  59. dc.SetWindowExt(100, -100);
  60. dc.OffsetViewportOrg(0,0);
  61. CRect rect(CPoint(10,-20),CSize(100,-100));
  62. dc.LPtoDP(rect);
  63. InvalidateRect(rect,TRUE);
  64. }
  65. void CCustomDlg::PrepareView(CProjView* pView)
  66. {
  67. ASSERT_VALID(pView);
  68. m_pView = pView;
  69. if(!(((pView->GetDocument())->m_customList).IsEmpty()))
  70.        m_pList = &((pView->GetDocument())->m_customList);
  71. }
  72. void CCustomDlg::OnPaint() 
  73. {
  74. int nWidth,nHeight;
  75. float xRate,yRate;
  76. CPaintDC dc(this); // device context for painting
  77. dc.SetMapMode(MM_ANISOTROPIC);
  78. dc.SetViewportExt(dc.GetDeviceCaps(LOGPIXELSX),
  79. dc.GetDeviceCaps(LOGPIXELSY));
  80. dc.SetWindowExt(100, -100);
  81. dc.OffsetViewportOrg(0,0);
  82. if(m_pList != NULL)
  83. {
  84. if(m_index >= 0)
  85. {
  86. POSITION pos = m_pList->FindIndex(m_index);
  87. CDrawObj* pObj = (m_pList->GetAt(pos));
  88. CRect rect;
  89. CRect originalRect = pObj->m_position;
  90. pObj->CustomRect(rect);
  91. rect.NormalizeRect();
  92. xRate = rect.Width()*1.0/rect.Height();
  93. yRate = rect.Height()*1.0/rect.Width();
  94. nWidth = (abs(rect.Width())>abs(rect.Height()))?100:abs(100*xRate);
  95. nHeight = (abs(rect.Width())<abs(rect.Height()))?100:abs(100*yRate);
  96. pObj->m_position = CRect(CPoint(10,-20),CSize(nWidth,-nHeight));
  97. pObj->OriginalRect(pObj->m_position,originalRect);
  98. pObj->MoveTo(pObj->m_position,m_pView);
  99. pObj->Draw(&dc);
  100. }
  101. }
  102. }