Menu

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

Download this file

159 lines (135 with data), 4.7 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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// CommitMonitor - simple checker for new commits in svn repositories
// Copyright (C) 2007 - Stefan Kueng
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "stdafx.h"
#include "BaseDialog.h"
INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent)
{
m_bPseudoModal = false;
hResource = hInstance;
return DialogBoxParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);
}
INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent, UINT idAccel)
{
m_bPseudoModal = true;
hResource = hInstance;
m_hwnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(resID), hWndParent, &CDialog::stDlgFunc, (LPARAM)this);
// deactivate the parent window
if (hWndParent)
::EnableWindow(hWndParent, FALSE);
ShowWindow(m_hwnd, SW_SHOW);
// Main message loop:
MSG msg;
HACCEL hAccelTable = LoadAccelerators(hResource, MAKEINTRESOURCE(idAccel));
BOOL bRet = TRUE;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
break;
}
else
{
if (!TranslateAccelerator(m_hwnd, hAccelTable, &msg) &&
!IsDialogMessage(m_hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
// re-enable the parent window
if (hWndParent)
::EnableWindow(hWndParent, TRUE);
DestroyWindow(m_hwnd);
return msg.wParam;
}
BOOL CDialog::EndDialog(HWND hDlg, INT_PTR nResult)
{
if (m_bPseudoModal)
::PostQuitMessage(nResult);
return ::EndDialog(hDlg, nResult);
}
HWND CDialog::Create(HINSTANCE hInstance, int resID, HWND hWndParent)
{
m_bPseudoModal = true;
hResource = hInstance;
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);
}
void CDialog::AddToolTip(UINT ctrlID, LPTSTR text)
{
TOOLINFO tt;
tt.cbSize = sizeof(TOOLINFO);
tt.uFlags = TTF_IDISHWND|TTF_CENTERTIP|TTF_SUBCLASS;
tt.hwnd = GetDlgItem(*this, ctrlID);
tt.uId = (UINT)GetDlgItem(*this, ctrlID);
tt.lpszText = text;
SendMessage (m_hToolTips, TTM_ADDTOOL, 0, (LPARAM) &tt);
}
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;
// create the tooltip control
pWnd->m_hToolTips = CreateWindowEx(NULL,
TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hwndDlg,
NULL, pWnd->hResource,
NULL);
SetWindowPos(pWnd->m_hToolTips, HWND_TOPMOST,0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
SendMessage(pWnd->m_hToolTips, TTM_SETMAXTIPWIDTH, 0, 600);
SendMessage(pWnd->m_hToolTips, TTM_ACTIVATE, TRUE, 0);
}
// 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.