Menu

[r122]: / trunk / src / BaseDialog.cpp  Maximize  Restore  History

Download this file

64 lines (53 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "stdafx.h"
#include "BaseDialog.h"
INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent)
{
hResource = hInstance;
return DialogBoxParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);
}
HWND CDialog::Create(HINSTANCE hInstance, int resID, HWND hWndParent)
{
m_hwnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);
return m_hwnd;
}
void CDialog::InitDialog(HWND hwndDlg, UINT iconID)
{
HWND hwndOwner;
RECT rc, rcDlg, rcOwner;
hwndOwner = ::GetParent(hwndDlg);
if (hwndOwner == NULL)
hwndOwner = ::GetDesktopWindow();
GetWindowRect(hwndOwner, &rcOwner);
GetWindowRect(hwndDlg, &rcDlg);
CopyRect(&rc, &rcOwner);
OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
OffsetRect(&rc, -rc.left, -rc.top);
OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
SetWindowPos(hwndDlg, HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE);
HICON hIcon = (HICON)::LoadImage(hResource, MAKEINTRESOURCE(iconID), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE|LR_SHARED);
::SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
::SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
}
INT_PTR CALLBACK CDialog::stDlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CDialog* pWnd;
if (uMsg == WM_INITDIALOG)
{
// get the pointer to the window from lpCreateParams
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
pWnd = (CDialog*)lParam;
pWnd->m_hwnd = hwndDlg;
}
// get the pointer to the window
pWnd = GetObjectFromWindow(hwndDlg);
// if we have the pointer, go to the message handler of the window
// else, use DefWindowProc
if (pWnd)
{
LRESULT lRes = pWnd->DlgFunc(hwndDlg, uMsg, wParam, lParam);
SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, lRes);
return lRes;
}
else
return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.