INT_PTR CALLBACK CBasePropertyPage::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CBasePropertyPage *pPropertyPage; switch (uMsg) { case WM_INITDIALOG: _SetWindowLongPtr(hwnd, DWLP_USER, lParam); // This pointer may be NULL when calculating size pPropertyPage = (CBasePropertyPage *) lParam; if (pPropertyPage == NULL) { return (LRESULT) 1; } pPropertyPage->m_Dlg = hwnd; } // This pointer may be NULL when calculating size pPropertyPage = _GetWindowLongPtr<CBasePropertyPage*>(hwnd, DWLP_USER); if (pPropertyPage == NULL) { return (LRESULT) 1; } return pPropertyPage->OnReceiveMessage(hwnd,uMsg,wParam,lParam); }
LRESULT CALLBACK BaseWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { BaseWindow *pWin = NULL; if (uMsg == WM_NCCREATE) { // When we create the window, we pass in a pointer to this class // as part of the CREATESTRUCT structure. LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam; pWin = (BaseWindow*)lpcs->lpCreateParams; // Set the window handle. pWin->m_hwnd = hwnd; // Set the pointer to the class as user data. _SetWindowLongPtr(hwnd, GWLP_USERDATA, pWin); } else { // Get the pointer to the class. pWin = _GetWindowLongPtr<BaseWindow*>(hwnd, GWLP_USERDATA); } if (pWin) { return pWin->OnReceiveMessage(uMsg, wParam, lParam); } else { return DefWindowProc(hwnd, uMsg, wParam, lParam); } }
//----------------------------------------------------------------------------- // Name: DialogProc() // Desc: DialogProc for the dialog. This is a static class method. // // lParam: Pointer to the CBaseDialog object. // // The CBaseDialog class specifies lParam when it calls DialogBoxParam. We store the // pointer as user data in the window. // // (Note: The DirectShow CBasePropertyPage class uses the same technique.) //----------------------------------------------------------------------------- INT_PTR CALLBACK CBaseDialog::DialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CBaseDialog *pDlg = 0; // Pointer to the dialog class that manages the dialog if (msg == WM_INITDIALOG) { // Get the pointer to the dialog object and store it in // the window's user data _SetWindowLongPtr(hDlg, DWLP_USER, lParam); pDlg = (CBaseDialog*)lParam; if (pDlg) { pDlg->m_hDlg = hDlg; pDlg->CalcNcSize(); HRESULT hr = pDlg->OnInitDialog(); if (FAILED(hr)) { pDlg->EndDialog(0); } } return FALSE; } // Get the dialog object from the window's user data pDlg = _GetWindowLongPtr<CBaseDialog*>(hDlg, DWLP_USER); if (pDlg != NULL) { switch (msg) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: if (pDlg->OnOK()) { pDlg->EndDialog(IDOK); } return TRUE; case IDCANCEL: if (pDlg->OnCancel()) { pDlg->EndDialog(IDCANCEL); } return TRUE; default: return pDlg->OnCommand((HWND)lParam, LOWORD(wParam), HIWORD(wParam)); } break; case WM_NOTIFY: return pDlg->OnNotify((NMHDR*)lParam); default: return pDlg->OnReceiveMsg(msg, wParam, lParam); } } else { return FALSE; } }