OSDN Git Service

add Utils
[tortoisegit/TortoiseGitJp.git] / Utils / MiscUI / BaseDialog.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2007 - Stefan Kueng\r
4 \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
9 \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
14 \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
18 //\r
19 #include "stdafx.h"\r
20 #include "BaseDialog.h"\r
21 \r
22 \r
23 INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent)\r
24 {\r
25         hResource = hInstance;\r
26         return DialogBoxParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);\r
27 }\r
28 \r
29 HWND CDialog::Create(HINSTANCE hInstance, int resID, HWND hWndParent)\r
30 {\r
31         hResource = hInstance;\r
32     m_hwnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);\r
33     return m_hwnd;\r
34 }\r
35 \r
36 void CDialog::InitDialog(HWND hwndDlg, UINT iconID)\r
37 {\r
38         HWND hwndOwner; \r
39         RECT rc, rcDlg, rcOwner;\r
40 \r
41         hwndOwner = ::GetParent(hwndDlg);\r
42         if (hwndOwner == NULL)\r
43                 hwndOwner = ::GetDesktopWindow();\r
44 \r
45         GetWindowRect(hwndOwner, &rcOwner); \r
46         GetWindowRect(hwndDlg, &rcDlg); \r
47         CopyRect(&rc, &rcOwner); \r
48 \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
52 \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
57 }\r
58 \r
59 INT_PTR CALLBACK CDialog::stDlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
60 {\r
61         CDialog* pWnd;\r
62         if (uMsg == WM_INITDIALOG)\r
63         {\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
68         }\r
69         // get the pointer to the window\r
70         pWnd = GetObjectFromWindow(hwndDlg);\r
71 \r
72         // if we have the pointer, go to the message handler of the window\r
73         // else, use DefWindowProc\r
74         if (pWnd)\r
75         {\r
76                 LRESULT lRes = pWnd->DlgFunc(hwndDlg, uMsg, wParam, lParam);\r
77                 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, lRes);\r
78                 return lRes;\r
79         }\r
80         else\r
81                 return DefWindowProc(hwndDlg, uMsg, wParam, lParam);\r
82 }\r