Introduction
This article describes how to use WTL's CPropertySheetImpl
template as a wizard-style resizable propertysheet view. See the companion article "WTL CPropertySheet as a Resizable View" for background information about how the resizable propertysheet operates.
Property Sheet
The wizard-style property sheet class, CWizView
, provides a Wizard 97 style property sheet. Wizard 97 style offers two static controls as separators and supports a bitmap image in the header section. CWizView
also supports the older Wizard style, which supplies one static control as a separator between property pages and wizard buttons. The static control IDs are listed below.
#define ATL_IDC_STATIC1 0x3026
#define ATL_IDC_STATIC2 0x3027
We use the lower static control's location to set the height of property pages. All of the wizard buttons, both static controls, and the propertysheet tab control are added to the propertysheet dialog resize map as follows. Note the various combinations of MOVE and SIZE, as these are important to proper operation of the sizing mechanism. Also, the tab control must be last as it controls the size and placement of the property pages.
BEGIN_DLGRESIZE_MAP(CWizView)
DLGRESIZE_CONTROL(ID_WIZBACK, DLSZ_MOVE_X | DLSZ_MOVE_Y)
DLGRESIZE_CONTROL(ID_WIZNEXT, DLSZ_MOVE_X | DLSZ_MOVE_Y)
DLGRESIZE_CONTROL(IDCANCEL, DLSZ_MOVE_X | DLSZ_MOVE_Y)
DLGRESIZE_CONTROL(ID_WIZFINISH, DLSZ_MOVE_X | DLSZ_MOVE_Y)
DLGRESIZE_CONTROL(ATL_IDC_STATIC1, DLSZ_SIZE_X | DLSZ_MOVE_Y)
DLGRESIZE_CONTROL(ATL_IDC_STATIC2, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(ATL_IDC_TAB_CONTROL, DLSZ_SIZE_X | DLSZ_MOVE_Y)
END_DLGRESIZE_MAP()
Tab Control
The tab control receives sizing messages from the propertysheet. The tab control WM_WINDOWPOSCHANGED
message handler sizes the property pages by calling a user defined message, WM_RESIZEPAGE
. Note the use of SendMessage()
here.
LRESULT OnWindowPosChanged(UINT, WPARAM, LPARAM lParam, BOOL&)
{
LPWINDOWPOS lpWP = (LPWINDOWPOS)lParam;
::SendMessage(m_hWnd, WM_RESIZEPAGE, 0, lpWP->cx);
return 0; }
The tab control is hidden when the property sheet is in wizard-style. To change tabs, the Next and Back buttons send TCM_SETCURSEL
messages to the tab control. Unfortunately, the built-in code also resizes the pages to their original dimensions everytime the tab is changed. Therefore, we process the current selection message to reset them to the desired size. Note the use of PostMessage()
here. Resizing must occur after the tab change completes.
LRESULT OnSetCurSel(UINT, WPARAM, LPARAM, BOOL& bHandled)
{
RECT rc;
GetClientRect(&rc);
::PostMessage(m_hWnd, WM_RESIZEPAGE, 0, rc.right);
bHandled = false;
return 0; }
This user defined message handler contains the property page resize code.
LRESULT OnResizePage(UINT, WPARAM, LPARAM lParam, BOOL&)
{
CWizView sheet;
sheet.m_hWnd = GetParent();
RECT rc;
CStatic st = sheet.GetDlgItem(ATL_IDC_STATIC1);
st.GetWindowRect(&rc);
sheet.ScreenToClient(&rc);
int nBottom = rc.top - 15;
DWORD dwFlags = sheet.GetPshStyle();
dwFlags |= PSH_WIZARD97;
if (dwFlags == sheet.GetPshStyle())
nBottom -= 60;
::SetWindowPos(sheet.GetActivePage(), NULL, 0, 0, lParam, nBottom, SWP_NOMOVE);
sheet.m_hWnd = NULL;
return 0; }
Terms Of Use
The sample project and property sheet/page classes available with this article are free. Use them however you wish.
THIS SOFTWARE IS DISTRIBUTED AS-IS, WITHOUT WARRANTIES OF ANY KIND.