1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
4 // Copyright (C) 2003-2007 - Stefan Kueng
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "BaseDialog.h"
22 #include "LoadIconEx.h"
24 INT_PTR
CDialog::DoModal(HINSTANCE hInstance
, int resID
, HWND hWndParent
)
26 hResource
= hInstance
;
27 return DialogBoxParam(hInstance
, MAKEINTRESOURCE(resID
), hWndParent
, &CDialog::stDlgFunc
, (LPARAM
)this);
30 HWND
CDialog::Create(HINSTANCE hInstance
, int resID
, HWND hWndParent
)
32 hResource
= hInstance
;
33 m_hwnd
= CreateDialogParam(hInstance
, MAKEINTRESOURCE(resID
), hWndParent
, &CDialog::stDlgFunc
, (LPARAM
)this);
37 void CDialog::InitDialog(HWND hwndDlg
, UINT iconID
)
40 RECT rc
, rcDlg
, rcOwner
;
42 hwndOwner
= ::GetParent(hwndDlg
);
44 hwndOwner
= ::GetDesktopWindow();
46 GetWindowRect(hwndOwner
, &rcOwner
);
47 GetWindowRect(hwndDlg
, &rcDlg
);
48 CopyRect(&rc
, &rcOwner
);
50 OffsetRect(&rcDlg
, -rcDlg
.left
, -rcDlg
.top
);
51 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
52 OffsetRect(&rc
, -rcDlg
.right
, -rcDlg
.bottom
);
54 SetWindowPos(hwndDlg
, HWND_TOP
, rcOwner
.left
+ (rc
.right
/ 2), rcOwner
.top
+ (rc
.bottom
/ 2), 0, 0, SWP_NOSIZE
);
55 auto hIcon
= LoadIconEx(hResource
, MAKEINTRESOURCE(iconID
), ::GetSystemMetrics(SM_CXICON
), ::GetSystemMetrics(SM_CYICON
));
56 ::SendMessage(hwndDlg
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
57 hIcon
= LoadIconEx(hResource
, MAKEINTRESOURCE(iconID
), ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
));
58 ::SendMessage(hwndDlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
)hIcon
);
61 INT_PTR CALLBACK
CDialog::stDlgFunc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
64 if (uMsg
== WM_INITDIALOG
)
66 // get the pointer to the window from lpCreateParams
67 SetWindowLongPtr(hwndDlg
, GWLP_USERDATA
, lParam
);
68 pWnd
= reinterpret_cast<CDialog
*>(lParam
);
69 pWnd
->m_hwnd
= hwndDlg
;
71 // get the pointer to the window
72 pWnd
= GetObjectFromWindow(hwndDlg
);
74 // if we have the pointer, go to the message handler of the window
75 // else, use DefWindowProc
78 LRESULT lRes
= pWnd
->DlgFunc(hwndDlg
, uMsg
, wParam
, lParam
);
79 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, lRes
);
83 return DefWindowProc(hwndDlg
, uMsg
, wParam
, lParam
);