Reduce C style casts
[TortoiseGit.git] / src / Utils / MiscUI / BaseDialog.cpp
blob38e1a9b7df0724c876fa34f706ac1be922ff5fe4
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.
20 #include "stdafx.h"
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);
34 return m_hwnd;
37 void CDialog::InitDialog(HWND hwndDlg, UINT iconID)
39 HWND hwndOwner;
40 RECT rc, rcDlg, rcOwner;
42 hwndOwner = ::GetParent(hwndDlg);
43 if (!hwndOwner)
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)
62 CDialog* pWnd;
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
75 if (pWnd)
77 LRESULT lRes = pWnd->DlgFunc(hwndDlg, uMsg, wParam, lParam);
78 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, lRes);
79 return lRes;
81 else
82 return DefWindowProc(hwndDlg, uMsg, wParam, lParam);