Programming Tips - Windows Template Library (WTL): present a dialog

Date: 2010feb1 Platform: WTL, ATL, Windows Template Library Language: C++ Q. Windows Template Library (WTL): present a dialog A. I got these two examples from the "WTL Developer's Guide". When I copied the code from the PDF the indenting was lost so I am adding a slight bit of value by presenting it here with the indenting corrected.
class MySimpleDialog : public CSimpleDialog<IDD_SIMPLE> { public: MySimpleDialog(): m_bButton(BST_CHECKED){} BEGIN_MSG_MAP(MySimpleDialog) COMMAND_ID_HANDLER(IDOK, OnOk) COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) END_MSG_MAP() UINT m_bButton; LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { CheckDlgButton(IDC_SIMPLE_CHECKBOX, m_bButton); return 0; } LRESULT OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { m_bButton = IsDlgButtonChecked(IDC_SIMPLE_CHECKBOX); OnCloseCmd(wNotifyCode, wID, hWndCtl, bHandled); return 0; } };
class MyModalDialog : public CDialogImpl<MyModalDialog> { public: MyModalDialog(){} enum { IDD = IDD_MODAL_DIALOG }; BEGIN_MSG_MAP(MyModalDialog) COMMAND_ID_HANDLER(IDOK, OnOk) COMMAND_ID_HANDLER(IDC_CTL_RELOCATE_BUTTON, OnRelocate) END_MSG_MAP() LRESULT OnRelocate(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { RECT r; CWindow wnd(GetDlgItem(IDC_CTL_RELOCATE_BUTTON)); wnd.GetWindowRect(&r); r.left += 1; r.top += 1; r.right += 1; .bottom += 1; wnd.MoveWindow(&r, TRUE); return 0; } LRESULT OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { EndDialog(IDOK); return 0; } };