Dave's Brain

Browse - Programming Tips - How do I use a C++ for a dialog when non using MFC?

Date: 2014apr22
Platform: win32/64
OS: Windows
Language: C++

Q.  How do I use a C++ for a dialog when non 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); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, 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.