Programming Tips - win32: use a C++ for a dialog when NOT using MFC

Date: 2014apr22 Platform: win32/64 OS: Windows Language: C++ Q. win32: use a C++ for a dialog when NOT using MFC A. Make a class you pass around using GetDialogData();
class NonMfcDlg { HWND m_hDlg; void Init(); void Command(const WPARAM, const LPARAM); static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM, LPARAM); static int DoModal(HINSTANCE, HWND hParent); }; NonMfcDlg::Init() { // Whatever you want } INT_PTR NonMfcDlg::Command(const WPARAM wParam, const LPARAM lParam) { // Whatever you want return TRUE; } INT_PTR CALLBACK NonMfcDlg::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { NonMfcDlg *dlg = (NonMfcDlg *)lParam; SetDialogData(hDlg, dlg); dlg->m_hDlg = hDlg; dlg->Init(); } return TRUE; case WM_COMMAND: { NonMfcDlg *dlg = (NonMfcDlg *) GetDialogData(hDlg); return dlg->Command(wParam, lParam); } } return FALSE; } void NonMfcDlg::DoModal(HINSTANCE hInstance, HWND hParent) { NonMfcDlg dlg; // Make an instance of our class. It will automatically go away when we are done. DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_NonMfcDlg), hParent, NonMfcDlg::DlgProc, (LPARAM)&dlg); }