PropPageFrame.cpp
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:4k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /********************************************************************
  2. *
  3. * Copyright (c) 2002 Sven Wiegand <mail@sven-wiegand.de>
  4. *
  5. * You can use this and modify this in any way you want,
  6. * BUT LEAVE THIS HEADER INTACT.
  7. *
  8. * Redistribution is appreciated.
  9. *
  10. * $Workfile:$
  11. * $Revision: 1.1 $
  12. * $Modtime:$
  13. * $Author: gabest $
  14. *
  15. * Revision History:
  16. * $History:$
  17. *
  18. *********************************************************************/
  19. #include "stdafx.h"
  20. #include "PropPageFrame.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. namespace TreePropSheet
  27. {
  28. //-------------------------------------------------------------------
  29. // class CPropPageFrame
  30. //-------------------------------------------------------------------
  31. CPropPageFrame::CPropPageFrame()
  32. : m_bShowCaption(FALSE),
  33. m_nCaptionHeight(0),
  34. m_hCaptionIcon(NULL),
  35. m_dwMsgFormat(DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE)
  36. {
  37. }
  38. CPropPageFrame::~CPropPageFrame()
  39. {
  40. }
  41. /////////////////////////////////////////////////////////////////////
  42. // Operations
  43. void CPropPageFrame::ShowCaption(BOOL bEnable)
  44. {
  45. m_bShowCaption = bEnable;
  46. SafeUpdateWindow(CalcCaptionArea());
  47. }
  48. BOOL CPropPageFrame::GetShowCaption() const
  49. {
  50. return m_bShowCaption;
  51. }
  52. void CPropPageFrame::SetCaption(LPCTSTR lpszCaption, HICON hIcon /*= NULL*/)
  53. {
  54. m_strCaption = lpszCaption;
  55. m_hCaptionIcon = hIcon;
  56. SafeUpdateWindow(CalcCaptionArea());
  57. }
  58. CString CPropPageFrame::GetCaption(HICON *pIcon /* = NULL */) const
  59. {
  60. if (pIcon)
  61. *pIcon = m_hCaptionIcon;
  62. return m_strCaption;
  63. }
  64. void CPropPageFrame::SetCaptionHeight(int nCaptionHeight)
  65. {
  66. m_nCaptionHeight = nCaptionHeight;
  67. SafeUpdateWindow(CalcCaptionArea());
  68. }
  69. int CPropPageFrame::GetCaptionHeight() const
  70. {
  71. return m_nCaptionHeight;
  72. }
  73. void CPropPageFrame::SetMsgText(LPCTSTR lpszMsg)
  74. {
  75. m_strMsg = lpszMsg;
  76. SafeUpdateWindow(CalcMsgArea());
  77. }
  78. CString CPropPageFrame::GetMsgText() const
  79. {
  80. return m_strMsg;
  81. }
  82. void CPropPageFrame::SetMsgFormat(DWORD dwFormat)
  83. {
  84. m_dwMsgFormat = dwFormat;
  85. SafeUpdateWindow(CalcMsgArea());
  86. }
  87. DWORD CPropPageFrame::GetMsgFormat() const
  88. {
  89. return m_dwMsgFormat;
  90. }
  91. /////////////////////////////////////////////////////////////////////
  92. // Overridable implementation helpers
  93. void CPropPageFrame::Draw(CDC *pDc)
  94. {
  95. if (GetShowCaption())
  96. DrawCaption(pDc, CalcCaptionArea(), m_strCaption, m_hCaptionIcon);
  97. DrawMsg(pDc, CalcMsgArea(), m_strMsg, m_dwMsgFormat);
  98. }
  99. CRect CPropPageFrame::CalcMsgArea()
  100. {
  101. ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
  102. CRect rectMsg;
  103. GetWnd()->GetClientRect(rectMsg);
  104. if (GetShowCaption())
  105. rectMsg.top+= GetCaptionHeight();
  106. return rectMsg;
  107. }
  108. void CPropPageFrame::DrawMsg(CDC *pDc, CRect rect, LPCTSTR lpszMsg, DWORD dwFormat) 
  109. {
  110. CFont *pPrevFont = dynamic_cast<CFont*>(pDc->SelectStockObject(DEFAULT_GUI_FONT));
  111. int nPrevBkMode = pDc->SetBkMode(TRANSPARENT);
  112. pDc->DrawText(GetMsgText(), rect, GetMsgFormat());
  113. pDc->SetBkMode(nPrevBkMode);
  114. pDc->SelectObject(pPrevFont);
  115. }
  116. CRect CPropPageFrame::CalcCaptionArea()
  117. {
  118. ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
  119. CRect rectCaption;
  120. GetWnd()->GetClientRect(rectCaption);
  121. if (!GetShowCaption())
  122. rectCaption.bottom = rectCaption.top;
  123. else
  124. rectCaption.bottom = rectCaption.top+GetCaptionHeight();
  125. return rectCaption;
  126. }
  127. void CPropPageFrame::DrawCaption(CDC *pDc, CRect rect, LPCTSTR lpszCaption, HICON hIcon) 
  128. {
  129. // should be implemented by specialized classes
  130. }
  131. /////////////////////////////////////////////////////////////////////
  132. // Implementation helpers
  133. void CPropPageFrame::SafeUpdateWindow(LPCRECT lpRect /* = NULL */)
  134. {
  135. if (!IsWindow(GetWnd()->GetSafeHwnd()))
  136. return;
  137. GetWnd()->InvalidateRect(lpRect, TRUE);
  138. }
  139. } //namespace TreePropSheet