WCL::DlgResult DIALOGPROC CDialog::DlgProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { // Store the return values for this message. BOOL bMsgHandled = false; LRESULT lMsgResult = 0; try { CDialog* pDialog; // Get the window object. pDialog = static_cast<CDialog*>(CWnd::s_WndMap.Find(hWnd)); // Do we have a mapping? if (pDialog == nullptr) { // Time to initialise? // NB: We will receive other messages first. if (iMsg == WM_INITDIALOG) { // Get object from LPARAM. pDialog = reinterpret_cast<CDialog*>(lParam); // // This function can be called recursively so we need to use // the program stack to hold the return values for each // message whilst it is being precessed. // // Push the existing messages' return values onto the stack. BOOL* pbMsgHandled = pDialog->MsgHandledBuffer(&bMsgHandled); LRESULT* plMsgResult = pDialog->MsgResultBuffer (&lMsgResult); // Save handle/result. pDialog->m_hWnd = hWnd; pDialog->MsgHandled(true); pDialog->MsgResult (0); // Setup Window mapping. CWnd::s_WndMap.Add(*pDialog); // Centre only if modal. if (pDialog->m_bModal) pDialog->Centre(); // Initialise child controls. pDialog->InitControls(); pDialog->InitGravityTable(); // Now call initialise method. pDialog->OnCreate(pDialog->ClientRect()); // Pop the old messages' return values back off the stack. pDialog->MsgHandledBuffer(pbMsgHandled); pDialog->MsgResultBuffer (plMsgResult); } } else { // // This function can be called recursively so we need to use // the program stack to hold the return values for each // message whilst it is being precessed. // // Push the existing messages' return values onto the stack. BOOL* pbMsgHandled = pDialog->MsgHandledBuffer(&bMsgHandled); LRESULT* plMsgResult = pDialog->MsgResultBuffer (&lMsgResult); // Call real message handler. pDialog->WndProc(hWnd, iMsg, wParam, lParam); // Pop the old messages' return values back off the stack. pDialog->MsgHandledBuffer(pbMsgHandled); pDialog->MsgResultBuffer (plMsgResult); } } catch (const Core::Exception& e) { WCL::ReportUnhandledException( TXT("Unexpected exception caught in DlgProc()\n\n") TXT("Message: H=0x%p M=0x%08X W=0x%08X L=0x%08X\n\n%s"), hWnd, iMsg, wParam, lParam, e.twhat()); } catch (const std::exception& e) { WCL::ReportUnhandledException( TXT("Unexpected exception caught in DlgProc()\n\n") TXT("Message: H=0x%p M=0x%08X W=0x%08X L=0x%08X\n\n%hs"), hWnd, iMsg, wParam, lParam, e.what()); } catch (...) { WCL::ReportUnhandledException( TXT("Unexpected unknown exception caught in DlgProc()\n\n") TXT("Message: H=0x%p M=0x%08X W=0x%08X L=0x%08X"), hWnd, iMsg, wParam, lParam); } // Set the return value. ::SetWindowLongPtr(hWnd, DWLP_MSGRESULT, lMsgResult); // Return if msg was handled. return bMsgHandled; }