Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.4 KiB

  1. // CtrlWnd.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CtrlWnd.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. IMPLEMENT_DYNCREATE(CCtrlWnd,CWnd)
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CCtrlWnd
  13. CCtrlWnd::CCtrlWnd()
  14. {
  15. EnableAutomation();
  16. m_wndControl.EnableAutomation();
  17. }
  18. CCtrlWnd::~CCtrlWnd()
  19. {
  20. }
  21. BOOL CCtrlWnd::CreateControl(LPCTSTR lpszControlID)
  22. {
  23. if( ! GetSafeHwnd() || ! ::IsWindow(GetSafeHwnd()) )
  24. {
  25. return FALSE;
  26. }
  27. if( m_wndControl.GetSafeHwnd() && ::IsWindow(m_wndControl.GetSafeHwnd()) )
  28. {
  29. m_wndControl.DestroyWindow();
  30. }
  31. CRect rc;
  32. GetClientRect(&rc);
  33. BOOL bResult = m_wndControl.CreateControl(lpszControlID,NULL,WS_VISIBLE|WS_TABSTOP,rc,this,152);
  34. return bResult;
  35. }
  36. CWnd* CCtrlWnd::GetControl()
  37. {
  38. if( ! GetSafeHwnd() || ! ::IsWindow(GetSafeHwnd()) )
  39. {
  40. return NULL;
  41. }
  42. if( ! m_wndControl.GetSafeHwnd() || !::IsWindow(m_wndControl.GetSafeHwnd()) )
  43. {
  44. return NULL;
  45. }
  46. return &m_wndControl;
  47. }
  48. LPUNKNOWN CCtrlWnd::GetControlIUnknown()
  49. {
  50. if( ! GetSafeHwnd() || ! ::IsWindow(GetSafeHwnd()) )
  51. {
  52. return NULL;
  53. }
  54. if( ! m_wndControl.GetSafeHwnd() || !::IsWindow(m_wndControl.GetSafeHwnd()) )
  55. {
  56. return NULL;
  57. }
  58. LPUNKNOWN pUnk = m_wndControl.GetControlUnknown();
  59. if( pUnk )
  60. {
  61. pUnk->AddRef();
  62. }
  63. return pUnk;
  64. }
  65. BEGIN_MESSAGE_MAP(CCtrlWnd, CWnd)
  66. //{{AFX_MSG_MAP(CCtrlWnd)
  67. ON_WM_PAINT()
  68. ON_WM_SIZE()
  69. ON_WM_CREATE()
  70. //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CCtrlWnd message handlers
  74. int CCtrlWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  75. {
  76. if (CWnd::OnCreate(lpCreateStruct) == -1)
  77. return -1;
  78. ShowWindow(SW_SHOW);
  79. return 0;
  80. }
  81. void CCtrlWnd::OnPaint()
  82. {
  83. CPaintDC dc(this); // device context for painting
  84. if( m_wndControl.GetSafeHwnd() && ::IsWindow(m_wndControl.GetSafeHwnd()) )
  85. return;
  86. CRect r;
  87. GetClientRect(&r);
  88. dc.FillSolidRect(r, GetSysColor(COLOR_3DFACE));
  89. }
  90. void CCtrlWnd::OnSize(UINT nType, int cx, int cy)
  91. {
  92. CWnd::OnSize(nType, cx, cy);
  93. if( ! m_wndControl.GetSafeHwnd() && ! ::IsWindow(m_wndControl.GetSafeHwnd()) )
  94. return;
  95. CRect rc;
  96. GetClientRect(&rc);
  97. m_wndControl.SetWindowPos(NULL,0,0,rc.Width(),rc.Height(),SWP_NOZORDER|SWP_NOMOVE|SWP_SHOWWINDOW);
  98. }
  99. void CCtrlWnd::PostNcDestroy()
  100. {
  101. CWnd::PostNcDestroy();
  102. delete this;
  103. }