1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2007 - Stefan Kueng
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "BaseDialog.h"
\r
23 INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent)
\r
25 hResource = hInstance;
\r
26 return DialogBoxParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);
\r
29 HWND CDialog::Create(HINSTANCE hInstance, int resID, HWND hWndParent)
\r
31 hResource = hInstance;
\r
32 m_hwnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);
\r
36 void CDialog::InitDialog(HWND hwndDlg, UINT iconID)
\r
39 RECT rc, rcDlg, rcOwner;
\r
41 hwndOwner = ::GetParent(hwndDlg);
\r
42 if (hwndOwner == NULL)
\r
43 hwndOwner = ::GetDesktopWindow();
\r
45 GetWindowRect(hwndOwner, &rcOwner);
\r
46 GetWindowRect(hwndDlg, &rcDlg);
\r
47 CopyRect(&rc, &rcOwner);
\r
49 OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
\r
50 OffsetRect(&rc, -rc.left, -rc.top);
\r
51 OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
\r
53 SetWindowPos(hwndDlg, HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE);
\r
54 HICON hIcon = (HICON)::LoadImage(hResource, MAKEINTRESOURCE(iconID), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE|LR_SHARED);
\r
55 ::SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
\r
56 ::SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
\r
59 INT_PTR CALLBACK CDialog::stDlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
62 if (uMsg == WM_INITDIALOG)
\r
64 // get the pointer to the window from lpCreateParams
\r
65 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
\r
66 pWnd = (CDialog*)lParam;
\r
67 pWnd->m_hwnd = hwndDlg;
\r
69 // get the pointer to the window
\r
70 pWnd = GetObjectFromWindow(hwndDlg);
\r
72 // if we have the pointer, go to the message handler of the window
\r
73 // else, use DefWindowProc
\r
76 LRESULT lRes = pWnd->DlgFunc(hwndDlg, uMsg, wParam, lParam);
\r
77 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, lRes);
\r
81 return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
\r