ReactOS  0.4.15-dev-1197-g8081ba9
CIconWatcher Class Reference
Inheritance diagram for CIconWatcher:
Collaboration diagram for CIconWatcher:

Public Member Functions

 CIconWatcher ()
 
virtual ~CIconWatcher ()
 
bool Initialize (_In_ HWND hWndParent)
 
void Uninitialize ()
 
bool AddIconToWatcher (_In_ CONST NOTIFYICONDATA *iconData)
 
bool RemoveIconFromWatcher (_In_ CONST NOTIFYICONDATA *iconData)
 
IconWatcherDataGetListEntry (_In_opt_ CONST NOTIFYICONDATA *iconData, _In_opt_ HANDLE hProcess, _In_ bool Remove)
 

Static Private Member Functions

static UINT WINAPI WatcherThread (_In_opt_ LPVOID lpParam)
 

Private Attributes

CAtlList< IconWatcherData * > m_WatcherList
 
CRITICAL_SECTION m_ListLock
 
HANDLE m_hWatcherThread
 
HANDLE m_WakeUpEvent
 
HWND m_hwndSysTray
 
bool m_Loop
 

Detailed Description

Definition at line 54 of file syspager.cpp.

Constructor & Destructor Documentation

◆ CIconWatcher()

CIconWatcher::CIconWatcher ( )

Definition at line 266 of file syspager.cpp.

266  :
270  m_Loop(false)
271 {
272 }
HANDLE m_hWatcherThread
Definition: syspager.cpp:58
HWND m_hwndSysTray
Definition: syspager.cpp:60
smooth NULL
Definition: ftsmooth.c:416
HANDLE m_WakeUpEvent
Definition: syspager.cpp:59

◆ ~CIconWatcher()

CIconWatcher::~CIconWatcher ( )
virtual

Definition at line 274 of file syspager.cpp.

275 {
276  Uninitialize();
278 
279  if (m_WakeUpEvent)
281  if (m_hWatcherThread)
283 }
#define CloseHandle
Definition: compat.h:487
HANDLE m_hWatcherThread
Definition: syspager.cpp:58
void Uninitialize()
Definition: syspager.cpp:306
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
CRITICAL_SECTION m_ListLock
Definition: syspager.cpp:57
HANDLE m_WakeUpEvent
Definition: syspager.cpp:59

Member Function Documentation

◆ AddIconToWatcher()

bool CIconWatcher::AddIconToWatcher ( _In_ CONST NOTIFYICONDATA iconData)

Definition at line 330 of file syspager.cpp.

331 {
333  (void)GetWindowThreadProcessId(iconData->hWnd, &ProcessId);
334 
337  if (hProcess == NULL)
338  {
339  return false;
340  }
341 
342  IconWatcherData *Icon = new IconWatcherData(iconData);
343  Icon->hProcess = hProcess;
344  Icon->ProcessId = ProcessId;
345 
346  bool Added = false;
348 
349  // The likelyhood of someone having more than 64 icons in their tray is
350  // pretty slim. We could spin up a new thread for each multiple of 64, but
351  // it's not worth the effort, so we just won't bother watching those icons
353  {
356  Added = true;
357  }
358 
360 
361  if (!Added)
362  {
363  delete Icon;
364  }
365 
366  return Added;
367 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2706
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
CAtlList< IconWatcherData * > m_WatcherList
Definition: syspager.cpp:56
#define MAXIMUM_WAIT_OBJECTS
Definition: winbase.h:385
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define FALSE
Definition: types.h:117
DWORD WINAPI GetWindowThreadProcessId(HWND, PDWORD)
smooth NULL
Definition: ftsmooth.c:416
size_t GetCount() const
Definition: atlcoll.h:537
unsigned long DWORD
Definition: ntddk_ex.h:95
CRITICAL_SECTION m_ListLock
Definition: syspager.cpp:57
#define SYNCHRONIZE
Definition: nt_native.h:61
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:624
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
HANDLE m_WakeUpEvent
Definition: syspager.cpp:59
Definition: globals.h:96
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by CSysPagerWnd::NotifyIcon().

◆ GetListEntry()

IconWatcherData * CIconWatcher::GetListEntry ( _In_opt_ CONST NOTIFYICONDATA iconData,
_In_opt_ HANDLE  hProcess,
_In_ bool  Remove 
)

Definition at line 383 of file syspager.cpp.

384 {
386  POSITION NextPosition = m_WatcherList.GetHeadPosition();
388  do
389  {
390  Position = NextPosition;
391 
392  Entry = m_WatcherList.GetNext(NextPosition);
393  if (Entry)
394  {
395  if ((iconData && ((Entry->IconData.hWnd == iconData->hWnd) && (Entry->IconData.uID == iconData->uID))) ||
396  (hProcess && (Entry->hProcess == hProcess)))
397  {
398  if (Remove)
400  break;
401  }
402  }
403  Entry = NULL;
404 
405  } while (NextPosition != NULL);
406 
407  return Entry;
408 }
POSITION GetHeadPosition() const
Definition: atlcoll.h:549
CAtlList< IconWatcherData * > m_WatcherList
Definition: syspager.cpp:56
struct _Entry Entry
Definition: kefuncs.h:627
static COORD Position
Definition: mouse.c:34
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
_In_ BOOLEAN Remove
Definition: psfuncs.h:110
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:561
void RemoveAt(_In_ POSITION pos)
Definition: atlcoll.h:746
base of all file and directory entries
Definition: entries.h:82

◆ Initialize()

bool CIconWatcher::Initialize ( _In_ HWND  hWndParent)

Definition at line 285 of file syspager.cpp.

286 {
288 
291  if (m_WakeUpEvent == NULL)
292  return false;
293 
295  0,
297  (LPVOID)this,
298  0,
299  NULL);
300  if (m_hWatcherThread == NULL)
301  return false;
302 
303  return true;
304 }
HANDLE m_hWatcherThread
Definition: syspager.cpp:58
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
#define FALSE
Definition: types.h:117
HWND m_hwndSysTray
Definition: syspager.cpp:60
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
static UINT WINAPI WatcherThread(_In_opt_ LPVOID lpParam)
Definition: syspager.cpp:410
PVOID HANDLE
Definition: typedefs.h:73
CRITICAL_SECTION m_ListLock
Definition: syspager.cpp:57
HANDLE m_WakeUpEvent
Definition: syspager.cpp:59

Referenced by CSysPagerWnd::OnCreate().

◆ RemoveIconFromWatcher()

bool CIconWatcher::RemoveIconFromWatcher ( _In_ CONST NOTIFYICONDATA iconData)

Definition at line 369 of file syspager.cpp.

370 {
372 
374  Icon = GetListEntry(iconData, NULL, true);
375 
378 
379  delete Icon;
380  return true;
381 }
IconWatcherData * GetListEntry(_In_opt_ CONST NOTIFYICONDATA *iconData, _In_opt_ HANDLE hProcess, _In_ bool Remove)
Definition: syspager.cpp:383
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
smooth NULL
Definition: ftsmooth.c:416
CRITICAL_SECTION m_ListLock
Definition: syspager.cpp:57
HANDLE m_WakeUpEvent
Definition: syspager.cpp:59
Definition: globals.h:96
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by CSysPagerWnd::NotifyIcon().

◆ Uninitialize()

void CIconWatcher::Uninitialize ( void  )

Definition at line 306 of file syspager.cpp.

307 {
308  m_Loop = false;
309  if (m_WakeUpEvent)
311 
313 
314  POSITION Pos;
315  for (size_t i = 0; i < m_WatcherList.GetCount(); i++)
316  {
318  if (Pos)
319  {
322  delete Icon;
323  }
324  }
326 
328 }
CAtlList< IconWatcherData * > m_WatcherList
Definition: syspager.cpp:56
POSITION FindIndex(_In_ size_t iElement) const
Definition: atlcoll.h:795
ush Pos
Definition: deflate.h:92
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
size_t GetCount() const
Definition: atlcoll.h:537
void RemoveAll()
Definition: atlcoll.h:725
E & GetAt(_In_ POSITION pos)
Definition: atlcoll.h:593
CRITICAL_SECTION m_ListLock
Definition: syspager.cpp:57
HANDLE m_WakeUpEvent
Definition: syspager.cpp:59
Definition: globals.h:96
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by CSysPagerWnd::OnDestroy().

◆ WatcherThread()

UINT WINAPI CIconWatcher::WatcherThread ( _In_opt_ LPVOID  lpParam)
staticprivate

Definition at line 410 of file syspager.cpp.

411 {
412  CIconWatcher* This = reinterpret_cast<CIconWatcher *>(lpParam);
413  HANDLE *WatchList = NULL;
414 
415  This->m_Loop = true;
416  while (This->m_Loop)
417  {
418  EnterCriticalSection(&This->m_ListLock);
419 
420  DWORD Size;
421  Size = This->m_WatcherList.GetCount() + 1;
423 
424  if (WatchList)
425  delete[] WatchList;
426  WatchList = new HANDLE[Size];
427  WatchList[0] = This->m_WakeUpEvent;
428 
429  POSITION Pos;
430  for (size_t i = 0; i < This->m_WatcherList.GetCount(); i++)
431  {
432  Pos = This->m_WatcherList.FindIndex(i);
433  if (Pos)
434  {
436  Icon = This->m_WatcherList.GetAt(Pos);
437  WatchList[i + 1] = Icon->hProcess;
438  }
439  }
440 
441  LeaveCriticalSection(&This->m_ListLock);
442 
443  DWORD Status;
445  WatchList,
446  FALSE,
447  INFINITE);
448  if (Status == WAIT_OBJECT_0)
449  {
450  // We've been kicked, we have updates to our list (or we're exiting the thread)
451  if (This->m_Loop)
452  TRACE("Updating watched icon list\n");
453  }
454  else if ((Status >= WAIT_OBJECT_0 + 1) && (Status < Size))
455  {
457  Icon = This->GetListEntry(NULL, WatchList[Status], false);
458 
459  TRACE("Pid %lu owns a notification icon and has stopped without deleting it. We'll cleanup on its behalf\n", Icon->ProcessId);
460 
461  TRAYNOTIFYDATAW tnid = {0};
462  tnid.dwSignature = NI_NOTIFY_SIG;
463  tnid.dwMessage = NIM_DELETE;
464  CopyMemory(&tnid.nid, &Icon->IconData, Icon->IconData.cbSize);
465 
467  data.dwData = 1;
468  data.cbData = sizeof(tnid);
469  data.lpData = &tnid;
470 
471  BOOL Success = ::SendMessage(This->m_hwndSysTray, WM_COPYDATA,
472  (WPARAM)&Icon->IconData, (LPARAM)&data);
473  if (!Success)
474  {
475  // If we failed to handle the delete message, forcibly remove it
476  This->RemoveIconFromWatcher(&Icon->IconData);
477  }
478  }
479  else
480  {
481  if (Status == WAIT_FAILED)
482  {
483  Status = GetLastError();
484  }
485  ERR("Failed to wait on process handles : %lu\n", Status);
486  This->Uninitialize();
487  }
488  }
489 
490  if (WatchList)
491  delete[] WatchList;
492 
493  return 0;
494 }
#define MAXIMUM_WAIT_OBJECTS
Definition: winbase.h:385
ush Pos
Definition: deflate.h:92
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
UINT_PTR WPARAM
Definition: windef.h:207
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define WM_COPYDATA
Definition: winuser.h:1646
#define TRACE(s)
Definition: solgame.cpp:4
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define CopyMemory
Definition: winbase.h:1646
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_FAILED
Definition: winbase.h:394
#define NIM_DELETE
Definition: shellapi.h:93
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define ERR(fmt,...)
Definition: debug.h:110
Definition: globals.h:96
#define SendMessage
Definition: winuser.h:5818
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define INFINITE
Definition: serial.h:102

Member Data Documentation

◆ m_hWatcherThread

HANDLE CIconWatcher::m_hWatcherThread
private

Definition at line 58 of file syspager.cpp.

◆ m_hwndSysTray

HWND CIconWatcher::m_hwndSysTray
private

Definition at line 60 of file syspager.cpp.

◆ m_ListLock

CRITICAL_SECTION CIconWatcher::m_ListLock
private

Definition at line 57 of file syspager.cpp.

◆ m_Loop

bool CIconWatcher::m_Loop
private

Definition at line 61 of file syspager.cpp.

◆ m_WakeUpEvent

HANDLE CIconWatcher::m_WakeUpEvent
private

Definition at line 59 of file syspager.cpp.

◆ m_WatcherList

CAtlList<IconWatcherData *> CIconWatcher::m_WatcherList
private

Definition at line 56 of file syspager.cpp.


The documentation for this class was generated from the following file: