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"
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 HICON hIcon
= (HICON
)::LoadImage(hResource
, MAKEINTRESOURCE(iconID
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
|LR_SHARED
);
56 ::SendMessage(hwndDlg
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
57 ::SendMessage(hwndDlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
)hIcon
);
60 INT_PTR CALLBACK
CDialog::stDlgFunc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
63 if (uMsg
== WM_INITDIALOG
)
65 // get the pointer to the window from lpCreateParams
66 SetWindowLongPtr(hwndDlg
, GWLP_USERDATA
, lParam
);
67 pWnd
= reinterpret_cast<CDialog
*>(lParam
);
68 pWnd
->m_hwnd
= hwndDlg
;
70 // get the pointer to the window
71 pWnd
= GetObjectFromWindow(hwndDlg
);
73 // if we have the pointer, go to the message handler of the window
74 // else, use DefWindowProc
77 LRESULT lRes
= pWnd
->DlgFunc(hwndDlg
, uMsg
, wParam
, lParam
);
78 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, lRes
);
82 return DefWindowProc(hwndDlg
, uMsg
, wParam
, lParam
);