Menu

[r32]: / trunk / src / HiddenWindow.cpp  Maximize  Restore  History

Download this file

289 lines (265 with data), 7.2 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include "StdAfx.h"
#include "HiddenWindow.h"
#include "resource.h"
#include "MainDlg.h"
#include "SVN.h"
#include "AppUtils.h"
extern HINSTANCE hInst;
DWORD WINAPI MonitorThread(LPVOID lpParam);
CHiddenWindow::CHiddenWindow(HINSTANCE hInst, const WNDCLASSEX* wcx /* = NULL*/)
: CWindow(hInst, wcx)
, m_ThreadRunning(0)
, m_bMainDlgShown(false)
{
m_hIconNew = LoadIcon(hInst, MAKEINTRESOURCE(IDI_NOTIFYNEW));
m_hIconNormal = LoadIcon(hInst, MAKEINTRESOURCE(IDI_NOTIFYNORMAL));
}
CHiddenWindow::~CHiddenWindow(void)
{
DestroyIcon(m_hIconNew);
DestroyIcon(m_hIconNormal);
Shell_NotifyIcon(NIM_DELETE, &m_SystemTray);
}
bool CHiddenWindow::RegisterAndCreateWindow()
{
WNDCLASSEX wcx;
// Fill in the window class structure with default parameters
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = CWindow::stWinMsgHandler;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hResource;
wcx.hCursor = LoadCursor(NULL, IDC_SIZEWE);
wcx.lpszClassName = ResString(hResource, IDS_APP_TITLE);
wcx.hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_COMMITMONITOR));
wcx.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
wcx.lpszMenuName = MAKEINTRESOURCE(IDC_COMMITMONITOR);
wcx.hIconSm = LoadIcon(wcx.hInstance, MAKEINTRESOURCE(IDI_COMMITMONITOR));
if (RegisterWindow(&wcx))
{
if (Create(WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, NULL))
{
COMMITMONITOR_SHOWDLGMSG = RegisterWindowMessage(_T("CommitMonitor_ShowDlgMsg"));
COMMITMONITOR_CHANGEDINFO = RegisterWindowMessage(_T("CommitMonitor_ChangedInfo"));
COMMITMONITOR_TASKBARCALLBACK = RegisterWindowMessage(_T("CommitMonitor_TaskbarCallback"));
ShowWindow(m_hwnd, SW_HIDE);
ShowTrayIcon();
return true;
}
}
return false;
}
INT_PTR CHiddenWindow::ShowDialog()
{
return ::SendMessage(*this, COMMITMONITOR_SHOWDLGMSG, 0, 0);
}
LRESULT CHiddenWindow::HandleCustomMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == COMMITMONITOR_SHOWDLGMSG)
{
if (m_bMainDlgShown)
return TRUE;
m_bMainDlgShown = true;
CMainDlg dlg;
dlg.DoModal(hInst, IDD_MAINDLG, NULL);
wstring urlfile = CAppUtils::GetAppDataDir() + _T("\\urls");
if (PathFileExists(urlfile.c_str()))
m_UrlInfos.Load(urlfile.c_str());
m_bMainDlgShown = false;
return TRUE;
}
else if (uMsg == COMMITMONITOR_CHANGEDINFO)
{
wstring urlfile = CAppUtils::GetAppDataDir() + _T("\\urls");
if (PathFileExists(urlfile.c_str()))
m_UrlInfos.Save(urlfile.c_str());
return TRUE;
}
else if (uMsg == COMMITMONITOR_TASKBARCALLBACK)
{
switch (lParam)
{
case WM_MOUSEMOVE:
{
// update the tool tip data
}
break;
case WM_LBUTTONDBLCLK:
{
// show the main dialog
}
break;
case NIN_KEYSELECT:
case NIN_SELECT:
case WM_RBUTTONUP:
case WM_CONTEXTMENU:
{
POINT pt;
GetCursorPos( &pt );
HMENU hMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDC_COMMITMONITOR));
hMenu = ::GetSubMenu(hMenu, 0);
// set the default entry
MENUITEMINFO iinfo = {0};
iinfo.cbSize = sizeof(MENUITEMINFO);
iinfo.fMask = MIIM_STATE;
GetMenuItemInfo(hMenu, 0, MF_BYPOSITION, &iinfo);
iinfo.fState |= MFS_DEFAULT;
SetMenuItemInfo(hMenu, 0, MF_BYPOSITION, &iinfo);
// show the menu
::SetForegroundWindow(*this);
int cmd = ::TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY , pt.x, pt.y, NULL, *this, NULL);
::PostMessage(*this, WM_NULL, 0, 0);
switch( cmd )
{
case IDM_EXIT:
::PostQuitMessage(0);
break;
case ID_POPUP_OPENCOMMITMONITOR:
ShowDialog();
break;
}
}
break;
}
return TRUE;
}
return 0L;
}
LRESULT CALLBACK CHiddenWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// the custom messages are not constant, therefore we can't handle them in the
// switch-case below
HandleCustomMessages(hwnd, uMsg, wParam, lParam);
switch (uMsg)
{
case WM_CREATE:
{
m_hwnd = hwnd;
// set the timers we use to start the monitoring threads
::SetTimer(*this, IDT_MONITOR, 10, NULL);
}
break;
case WM_TIMER:
{
if (wParam == IDT_MONITOR)
{
DoTimer();
}
}
break;
case WM_COMMAND:
{
return DoCommand(LOWORD(wParam));
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
::DestroyWindow(m_hwnd);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
};
LRESULT CHiddenWindow::DoCommand(int id)
{
switch (id)
{
default:
break;
};
return 1;
}
void CHiddenWindow::DoTimer()
{
// Restart the timer with 60 seconds
::SetTimer(*this, IDT_MONITOR, TIMER_ELAPSE, NULL);
// go through all url infos and check if
// we need to refresh them
if (m_UrlInfos.infos.empty())
return;
bool bStartThread = false;
__time64_t currenttime = NULL;
_time64(&currenttime);
for (map<wstring,CUrlInfo>::const_iterator it = m_UrlInfos.infos.begin(); it != m_UrlInfos.infos.end(); ++it)
{
if ((it->second.lastchecked + (it->second.minutesinterval*60000)) < currenttime)
{
bStartThread = true;
break;
}
}
if ((bStartThread)&&(m_ThreadRunning == 0))
{
// start the monitoring thread to update the infos
DWORD dwThreadId = 0;
HANDLE hMonitorThread = CreateThread(
NULL, // no security attribute
0, // default stack size
MonitorThread,
(LPVOID)this, // thread parameter
0, // not suspended
&dwThreadId); // returns thread ID
if (hMonitorThread == NULL)
return;
else
CloseHandle(hMonitorThread);
}
}
void CHiddenWindow::ShowTrayIcon()
{
m_SystemTray.cbSize = sizeof(NOTIFYICONDATA);
m_SystemTray.hWnd = *this;
m_SystemTray.uID = 1;
m_SystemTray.hIcon = m_hIconNormal;
m_SystemTray.uFlags = NIF_MESSAGE | NIF_ICON;
m_SystemTray.uCallbackMessage = COMMITMONITOR_TASKBARCALLBACK;
Shell_NotifyIcon(NIM_ADD, &m_SystemTray);
}
DWORD CHiddenWindow::RunThread()
{
m_ThreadRunning = TRUE;
__time64_t currenttime = NULL;
_time64(&currenttime);
bool bNewEntries = false;
for (map<wstring,CUrlInfo>::iterator it = m_UrlInfos.infos.begin(); it != m_UrlInfos.infos.end(); ++it)
{
if ((it->second.lastchecked + (it->second.minutesinterval*60000)) < currenttime)
{
// get the highest revision of the repository
SVN svn;
svn.SetAuthInfo(it->second.username, it->second.password);
svn_revnum_t headrev = svn.GetHEADRevision(it->first);
if (headrev > it->second.lastcheckedrev)
{
if (svn.GetLog(it->first, headrev, it->second.lastcheckedrev))
{
it->second.lastcheckedrev = headrev;
it->second.lastchecked = currenttime;
bNewEntries = true;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator logit = svn.m_logs.begin(); logit != svn.m_logs.end(); ++logit)
{
it->second.logentries[logit->first] = logit->second;
}
}
}
}
}
if (bNewEntries)
{
// save the changed entries
::PostMessage(*this, COMMITMONITOR_CHANGEDINFO, 0, 0);
}
m_ThreadRunning = FALSE;
return 0L;
}
DWORD WINAPI MonitorThread(LPVOID lpParam)
{
CHiddenWindow * pThis = (CHiddenWindow*)lpParam;
if (pThis)
return pThis->RunThread();
return 0L;
}
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.