1 /********************************************************************
3 * Copyright (c) 2002 Sven Wiegand <mail@sven-wiegand.de>
5 * You can use this and modify this in any way you want,
6 * BUT LEAVE THIS HEADER INTACT.
8 * Redistribution is appreciated.
18 *********************************************************************/
21 #include "PropPageFrame.h"
26 static char THIS_FILE
[] = __FILE__
;
31 namespace TreePropSheet
35 //-------------------------------------------------------------------
36 // class CPropPageFrame
37 //-------------------------------------------------------------------
39 CPropPageFrame::CPropPageFrame()
40 : m_bShowCaption(FALSE
),
42 m_hCaptionIcon(nullptr),
43 m_dwMsgFormat(DT_CENTER
|DT_VCENTER
|DT_NOPREFIX
|DT_SINGLELINE
),
46 NONCLIENTMETRICS metrics
= { 0 };
47 metrics
.cbSize
= sizeof(NONCLIENTMETRICS
);
48 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &metrics
, FALSE
);
49 m_uiFont
= CreateFontIndirect(&metrics
.lfMessageFont
);
53 CPropPageFrame::~CPropPageFrame()
56 DeleteObject(m_uiFont
);
60 /////////////////////////////////////////////////////////////////////
64 void CPropPageFrame::ShowCaption(BOOL bEnable
)
66 m_bShowCaption
= bEnable
;
67 SafeUpdateWindow(CalcCaptionArea());
71 BOOL
CPropPageFrame::GetShowCaption() const
73 return m_bShowCaption
;
77 void CPropPageFrame::SetCaption(LPCTSTR lpszCaption
, HICON hIcon
/*= nullptr*/)
79 m_strCaption
= lpszCaption
;
80 m_hCaptionIcon
= hIcon
;
81 SafeUpdateWindow(CalcCaptionArea());
85 CString
CPropPageFrame::GetCaption(HICON
* pIcon
/* = nullptr */) const
88 *pIcon
= m_hCaptionIcon
;
93 void CPropPageFrame::SetCaptionHeight(int nCaptionHeight
)
95 m_nCaptionHeight
= nCaptionHeight
;
96 SafeUpdateWindow(CalcCaptionArea());
100 int CPropPageFrame::GetCaptionHeight() const
102 return m_nCaptionHeight
;
106 void CPropPageFrame::SetMsgText(LPCTSTR lpszMsg
)
109 SafeUpdateWindow(CalcMsgArea());
113 CString
CPropPageFrame::GetMsgText() const
119 void CPropPageFrame::SetMsgFormat(DWORD dwFormat
)
121 m_dwMsgFormat
= dwFormat
;
122 SafeUpdateWindow(CalcMsgArea());
126 DWORD
CPropPageFrame::GetMsgFormat() const
128 return m_dwMsgFormat
;
132 /////////////////////////////////////////////////////////////////////
133 // Overridable implementation helpers
135 void CPropPageFrame::Draw(CDC
*pDc
)
137 if (GetShowCaption())
138 DrawCaption(pDc
, CalcCaptionArea(), m_strCaption
, m_hCaptionIcon
);
139 DrawMsg(pDc
, CalcMsgArea(), m_strMsg
, m_dwMsgFormat
);
143 CRect
CPropPageFrame::CalcMsgArea()
145 ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
148 GetWnd()->GetClientRect(rectMsg
);
149 if (GetShowCaption())
150 rectMsg
.top
+= GetCaptionHeight();
156 void CPropPageFrame::DrawMsg(CDC
*pDc
, CRect rect
, LPCTSTR
/*lpszMsg*/, DWORD
/*dwFormat*/)
158 auto hOldFont
= pDc
->SelectObject(m_uiFont
);
159 int nPrevBkMode
= pDc
->SetBkMode(TRANSPARENT
);
161 pDc
->DrawText(GetMsgText(), rect
, GetMsgFormat());
163 pDc
->SetBkMode(nPrevBkMode
);
164 pDc
->SelectObject(hOldFont
);
168 CRect
CPropPageFrame::CalcCaptionArea()
170 ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
173 GetWnd()->GetClientRect(rectCaption
);
174 if (!GetShowCaption())
175 rectCaption
.bottom
= rectCaption
.top
;
177 rectCaption
.bottom
= rectCaption
.top
+GetCaptionHeight();
183 void CPropPageFrame::DrawCaption(CDC
* /*pDc*/, CRect
/*rect*/, LPCTSTR
/*lpszCaption*/, HICON
/*hIcon*/)
185 // should be implemented by specialized classes
189 /////////////////////////////////////////////////////////////////////
190 // Implementation helpers
192 void CPropPageFrame::SafeUpdateWindow(LPCRECT lpRect
/* = nullptr */)
194 if (!IsWindow(GetWnd()->GetSafeHwnd()))
197 GetWnd()->InvalidateRect(lpRect
, TRUE
);
202 } //namespace TreePropSheet