Dave's Brain

Browse - programming tips - wtl simple modal dialog

Date: 2010feb1
Platform: WTL, ATL
Language: C++

Q.  How get I do a dialog with WTL?

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 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;r.bottom+=1;
		wnd.MoveWindow(&r, TRUE);
		return 0;
	}

	LRESULT OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		EndDialog(IDOK);
		return 0;
	}

};
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.