2 #include "BaseDialog.h"
\r
5 INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent)
\r
7 hResource = hInstance;
\r
8 return DialogBoxParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);
\r
11 void CDialog::InitDialog(HWND hwndDlg, UINT iconID)
\r
14 RECT rc, rcDlg, rcOwner;
\r
16 hwndOwner = ::GetParent(hwndDlg);
\r
17 if (hwndOwner == NULL)
\r
18 hwndOwner = ::GetDesktopWindow();
\r
20 GetWindowRect(hwndOwner, &rcOwner);
\r
21 GetWindowRect(hwndDlg, &rcDlg);
\r
22 CopyRect(&rc, &rcOwner);
\r
24 OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
\r
25 OffsetRect(&rc, -rc.left, -rc.top);
\r
26 OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
\r
28 SetWindowPos(hwndDlg, HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE);
\r
29 HICON hIcon = (HICON)::LoadImage(hResource, MAKEINTRESOURCE(iconID), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE|LR_SHARED);
\r
30 ::SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
\r
31 ::SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
\r
34 INT_PTR CALLBACK CDialog::stDlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
37 if (uMsg == WM_INITDIALOG)
\r
39 // get the pointer to the window from lpCreateParams
\r
40 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
\r
41 pWnd = (CDialog*)lParam;
\r
42 pWnd->m_hwnd = hwndDlg;
\r
44 // get the pointer to the window
\r
45 pWnd = GetObjectFromWindow(hwndDlg);
\r
47 // if we have the pointer, go to the message handler of the window
\r
48 // else, use DefWindowProc
\r
51 LRESULT lRes = pWnd->DlgFunc(hwndDlg, uMsg, wParam, lParam);
\r
52 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, lRes);
\r
56 return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
\r