Introduction
This is a very simple class that will automatically center a WTL property sheet. One frequently-asked question in the various WTL forums is "How do I centre a CPropertySheet
object?". Most people tend to add a GetParent().CenterWindow()
call to the first page in the property sheet, but in my mind this is a little awkward.
Instead, simply #include "propertysheetex.h"
and use CPropertySheetEx
as a drop in replacement for the standard WTL CPropertySheet
class.
Code
The actual code for the class is straightforward:
class CPropertySheetEx : public CPropertySheet
{
private:
bool m_bCentered;
public:
CPropertySheetEx(WTL::_U_STRINGorID title =
(LPCTSTR)NULL, UINT uStartPage = 0, HWND hWndParent = NULL)
: CPropertySheet(title, uStartPage, hWndParent), m_bCentered(false)
{
}
BEGIN_MSG_MAP(CPropertySheetEx)
MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
CHAIN_MSG_MAP(CPropertySheet)
END_MSG_MAP()
LRESULT OnShowWindow(UINT , WPARAM wParam,
LPARAM , BOOL& bHandled)
{
if (wParam == TRUE)
Center();
bHandled = FALSE;
return 0;
}
void Center(void)
{
if (!m_bCentered)
{
CenterWindow();
m_bCentered = true;
}
}
};