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