ReactOS  0.4.13-dev-551-gf37fb1f
hotplug.cpp File Reference
#include "precomp.h"
#include <atlsimpcoll.h>
#include <dbt.h>
#include <cfgmgr32.h>
#include <shlwapi.h>
Include dependency graph for hotplug.cpp:

Go to the source code of this file.

Macros

#define DISPLAY_NAME_LEN   40
 

Functions

HRESULT EnumHotpluggedDevices (CSimpleArray< DEVINST > &devList)
 
HRESULT NotifyBalloon (CSysTray *pSysTray, LPCWSTR szTitle=NULL, LPCWSTR szInfo=NULL, UINT uId=ID_ICON_HOTPLUG)
 
HRESULT STDMETHODCALLTYPE Hotplug_Init (_In_ CSysTray *pSysTray)
 
HRESULT STDMETHODCALLTYPE Hotplug_Update (_In_ CSysTray *pSysTray)
 
HRESULT STDMETHODCALLTYPE Hotplug_Shutdown (_In_ CSysTray *pSysTray)
 
static void _RunHotplug (CSysTray *pSysTray)
 
static void _ShowContextMenu (CSysTray *pSysTray)
 
static void _ShowContextMenuR (CSysTray *pSysTray)
 
HRESULT STDMETHODCALLTYPE Hotplug_Message (_In_ CSysTray *pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult)
 

Variables

CSimpleArray< DEVINSTg_devList
 
static HICON g_hIconHotplug = NULL
 
static LPCWSTR g_strTooltip = L"Safely Remove Hardware and Eject Media"
 
static WCHAR g_strMenuSel [DISPLAY_NAME_LEN]
 
static BOOL g_IsRemoving = FALSE
 

Macro Definition Documentation

◆ DISPLAY_NAME_LEN

#define DISPLAY_NAME_LEN   40

Definition at line 16 of file hotplug.cpp.

Function Documentation

◆ _RunHotplug()

static void _RunHotplug ( CSysTray pSysTray)
static

Definition at line 156 of file hotplug.cpp.

157 {
158  ShellExecuteW(pSysTray->GetHWnd(), L"open", L"rundll32.exe shell32.dll,Control_RunDLL hotplug.dll", NULL, NULL, SW_SHOWNORMAL);
159 }
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250
#define SW_SHOWNORMAL
Definition: winuser.h:764
HWND GetHWnd()
Definition: csystray.h:53
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2236

Referenced by _ShowContextMenuR(), and Hotplug_Message().

◆ _ShowContextMenu()

static void _ShowContextMenu ( CSysTray pSysTray)
static

Definition at line 161 of file hotplug.cpp.

162 {
163  HMENU hPopup = CreatePopupMenu();
164  ULONG ulLength = DISPLAY_NAME_LEN * sizeof(WCHAR);
165 
166  for (INT index = 0; index < g_devList.GetSize(); index++)
167  {
168  WCHAR dispName[DISPLAY_NAME_LEN], menuName[DISPLAY_NAME_LEN + 10];
170  if (cr != CR_SUCCESS)
171  StrCpyW(dispName, L"Unknown Device");
172 
173  swprintf(menuName, L"Eject %wS", dispName);
174  AppendMenuW(hPopup, MF_STRING, index+1, menuName);
175  }
176 
177  SetForegroundWindow(pSysTray->GetHWnd());
179  POINT pt;
180  GetCursorPos(&pt);
181 
182  DWORD id = TrackPopupMenuEx(hPopup, flags,
183  pt.x, pt.y,
184  pSysTray->GetHWnd(), NULL);
185 
186  if (id > 0)
187  {
188  id--; // since array indices starts from zero.
190  if (cr != CR_SUCCESS)
191  StrCpyW(g_strMenuSel, L"Unknown Device");
192 
193  cr = CM_Request_Device_Eject_Ex(g_devList[id], 0, 0, 0, 0, 0);
194  if (cr != CR_SUCCESS)
195  {
196  WCHAR strInfo[128];
197  swprintf(strInfo, L"Problem Ejecting %wS", g_strMenuSel);
198  MessageBox(0, L"The device cannot be stopped right now! Try stopping it again later!", strInfo, MB_OKCANCEL | MB_ICONEXCLAMATION);
199  }
200  else
201  {
202  //MessageBox(0, L"Device ejected successfully!! You can safely remove the device now!", L"Safely Remove Hardware", MB_OKCANCEL | MB_ICONINFORMATION);
203  g_IsRemoving = TRUE;
204  g_devList.RemoveAt(id); /* thing is.. even after removing id at this point, the devnode_change occurs after some seconds of sucessful removal
205  and since pendrive is still plugged in it gets enumerated, if problem number is not filtered.
206  */
207  }
208  }
209 
210  DestroyMenu(hPopup);
211 }
#define TRUE
Definition: types.h:120
#define CM_Get_DevNode_Registry_Property
Definition: cfgmgr32.h:1733
#define pt(x, y)
Definition: drawing.c:79
#define TPM_RETURNCMD
Definition: winuser.h:2341
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
#define MF_STRING
Definition: winuser.h:138
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define CR_SUCCESS
Definition: cfgmgr32.h:842
#define TPM_BOTTOMALIGN
Definition: winuser.h:2339
smooth NULL
Definition: ftsmooth.c:416
#define MB_OKCANCEL
Definition: winuser.h:798
GLuint index
Definition: glext.h:6031
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TPM_NONOTIFY
Definition: winuser.h:2340
GLbitfield flags
Definition: glext.h:7161
static const WCHAR L[]
Definition: oid.c:1250
#define CM_DRP_DEVICEDESC
Definition: cfgmgr32.h:676
#define MessageBox
Definition: winuser.h:5688
LPWSTR WINAPI StrCpyW(LPWSTR lpszStr, LPCWSTR lpszSrc)
Definition: string.c:514
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define CM_Request_Device_Eject_Ex
Definition: cfgmgr32.h:2878
static BOOL g_IsRemoving
Definition: hotplug.cpp:25
CSimpleArray< DEVINST > g_devList
Definition: hotplug.cpp:20
static WCHAR g_strMenuSel[DISPLAY_NAME_LEN]
Definition: hotplug.cpp:24
HWND GetHWnd()
Definition: csystray.h:53
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:846
unsigned int ULONG
Definition: retypes.h:1
BOOL WINAPI SetForegroundWindow(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define TPM_RIGHTALIGN
Definition: winuser.h:2332
#define DISPLAY_NAME_LEN
Definition: hotplug.cpp:16

Referenced by Hotplug_Message().

◆ _ShowContextMenuR()

static void _ShowContextMenuR ( CSysTray pSysTray)
static

Definition at line 213 of file hotplug.cpp.

214 {
216  HMENU hPopup = CreatePopupMenu();
217  AppendMenuW(hPopup, MF_STRING, IDS_HOTPLUG_REMOVE_2, strMenu);
219 
220  SetForegroundWindow(pSysTray->GetHWnd());
222  POINT pt;
223  GetCursorPos(&pt);
224 
225  DWORD id = TrackPopupMenuEx(hPopup, flags,
226  pt.x, pt.y,
227  pSysTray->GetHWnd(), NULL);
228 
229  if (id == IDS_HOTPLUG_REMOVE_2)
230  {
231  _RunHotplug(pSysTray);
232  }
233 
234  DestroyMenu(hPopup);
235 }
static void _RunHotplug(CSysTray *pSysTray)
Definition: hotplug.cpp:156
#define pt(x, y)
Definition: drawing.c:79
#define IDS_HOTPLUG_REMOVE_2
Definition: resource.h:19
#define TPM_RETURNCMD
Definition: winuser.h:2341
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
#define MF_STRING
Definition: winuser.h:138
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
#define TPM_BOTTOMALIGN
Definition: winuser.h:2339
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TPM_NONOTIFY
Definition: winuser.h:2340
GLbitfield flags
Definition: glext.h:7161
BOOL WINAPI DestroyMenu(_In_ HMENU)
HWND GetHWnd()
Definition: csystray.h:53
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:846
BOOL WINAPI SetForegroundWindow(_In_ HWND)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define TPM_RIGHTALIGN
Definition: winuser.h:2332

Referenced by Hotplug_Message().

◆ EnumHotpluggedDevices()

HRESULT EnumHotpluggedDevices ( CSimpleArray< DEVINST > &  devList)

Definition at line 38 of file hotplug.cpp.

39 {
40  devList.RemoveAll(); // Clear current devList
43  return E_HANDLE;
44  SP_DEVINFO_DATA did = { 0 };
45  did.cbSize = sizeof(did);
46 
47  // Enumerate all the attached devices.
48  for (int idev = 0; SetupDiEnumDeviceInfo(hdev, idev, &did); idev++)
49  {
50  DWORD dwCapabilities = 0, dwSize = sizeof(dwCapabilities);
51  WCHAR dispName[DISPLAY_NAME_LEN];
52  ULONG ulStatus = 0, ulPnum = 0, ulLength = DISPLAY_NAME_LEN * sizeof(WCHAR);
53  CONFIGRET cr = CM_Get_DevNode_Status(&ulStatus, &ulPnum, did.DevInst, 0);
54  if (cr != CR_SUCCESS)
55  continue;
56  cr = CM_Get_DevNode_Registry_Property(did.DevInst, CM_DRP_DEVICEDESC, NULL, dispName, &ulLength, 0);
57  if (cr != CR_SUCCESS)
58  continue;
60  if (cr != CR_SUCCESS)
61  continue;
62 
63  // Filter and make list of only the appropriate safely removable devices.
64  if ( (dwCapabilities & CM_DEVCAP_REMOVABLE) &&
65  !(dwCapabilities & CM_DEVCAP_DOCKDEVICE) &&
66  !(dwCapabilities & CM_DEVCAP_SURPRISEREMOVALOK) &&
67  ((dwCapabilities & CM_DEVCAP_EJECTSUPPORTED) || (ulStatus & DN_DISABLEABLE)) &&
68  !ulPnum)
69  {
70  devList.Add(did.DevInst);
71  }
72  }
74 
76  {
77  return E_UNEXPECTED;
78  }
79 
80  return S_OK;
81 }
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1792
#define CM_Get_DevNode_Registry_Property
Definition: cfgmgr32.h:1733
#define CM_DEVCAP_REMOVABLE
Definition: cfgmgr32.h:737
#define E_HANDLE
Definition: winerror.h:2850
BOOL Add(const T &t)
Definition: atlsimpcoll.h:58
#define CM_DEVCAP_EJECTSUPPORTED
Definition: cfgmgr32.h:736
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
#define DN_DISABLEABLE
Definition: cfg.h:131
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define NO_ERROR
Definition: dderror.h:5
#define CR_SUCCESS
Definition: cfgmgr32.h:842
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DIGCF_ALLCLASSES
Definition: setupapi.h:172
#define CM_DRP_DEVICEDESC
Definition: cfgmgr32.h:676
#define SetupDiGetClassDevs
Definition: setupapi.h:2588
#define S_OK
Definition: intsafe.h:59
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define E_UNEXPECTED
Definition: winerror.h:2456
CONFIGRET WINAPI CM_Get_DevNode_Status(_Out_ PULONG pulStatus, _Out_ PULONG pulProblemNumber, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:3426
unsigned int ULONG
Definition: retypes.h:1
#define CM_DEVCAP_SURPRISEREMOVALOK
Definition: cfgmgr32.h:742
#define CM_DEVCAP_DOCKDEVICE
Definition: cfgmgr32.h:738
_In_ HDEV hdev
Definition: winddi.h:3449
#define CM_DRP_CAPABILITIES
Definition: cfgmgr32.h:691
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define DIGCF_PRESENT
Definition: setupapi.h:171
#define DISPLAY_NAME_LEN
Definition: hotplug.cpp:16

Referenced by Hotplug_Init(), and Hotplug_Message().

◆ Hotplug_Init()

HRESULT STDMETHODCALLTYPE Hotplug_Init ( _In_ CSysTray pSysTray)

Definition at line 130 of file hotplug.cpp.

131 {
132  TRACE("Hotplug_Init\n");
135 
136  return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip, NIS_HIDDEN);
137 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON g_hIconHotplug
Definition: hotplug.cpp:22
#define ID_ICON_HOTPLUG
Definition: precomp.h:34
static LPCWSTR g_strTooltip
Definition: hotplug.cpp:23
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT EnumHotpluggedDevices(CSimpleArray< DEVINST > &devList)
Definition: hotplug.cpp:38
CSimpleArray< DEVINST > g_devList
Definition: hotplug.cpp:20
#define NIM_ADD
Definition: shellapi.h:91
#define LoadIcon
Definition: winuser.h:5679
HINSTANCE g_hInstance
Definition: MainWindow.cpp:18
#define IDI_HOTPLUG_OK
Definition: resource.h:57

Referenced by Hotplug_Message().

◆ Hotplug_Message()

HRESULT STDMETHODCALLTYPE Hotplug_Message ( _In_ CSysTray pSysTray,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
LRESULT lResult 
)

Definition at line 237 of file hotplug.cpp.

238 {
239  HRESULT hr = E_FAIL;
240  TRACE("Hotplug_Message uMsg=%d, wParam=%x, lParam=%x\n", uMsg, wParam, lParam);
241 
242  switch (uMsg)
243  {
244  /*case WM_CREATE:
245  TRACE("Hotplug_Message: WM_CREATE\n");
246  DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
247 
248  ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
249  NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
250  NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
251 
252  g_hDevNotify = RegisterDeviceNotification(pSysTray->GetHWnd(), &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
253  if (g_hDevNotify != NULL)
254  {
255  lResult = true;
256  return S_OK;
257  }
258  return S_FALSE;*/
259 
260  case WM_USER + 220:
261  TRACE("Hotplug_Message: WM_USER+220\n");
263  {
264  if (lParam)
265  {
266  pSysTray->EnableService(HOTPLUG_SERVICE_FLAG, TRUE);
267  return Hotplug_Init(pSysTray);
268  }
269  else
270  {
271  pSysTray->EnableService(HOTPLUG_SERVICE_FLAG, FALSE);
272  return Hotplug_Shutdown(pSysTray);
273  }
274  }
275  return S_FALSE;
276 
277  case WM_USER + 221:
278  TRACE("Hotplug_Message: WM_USER+221\n");
280  {
281  lResult = (LRESULT)pSysTray->IsServiceEnabled(HOTPLUG_SERVICE_FLAG);
282  return S_OK;
283  }
284  return S_FALSE;
285 
286  case WM_TIMER:
287  if (wParam == HOTPLUG_TIMER_ID)
288  {
289  KillTimer(pSysTray->GetHWnd(), HOTPLUG_TIMER_ID);
290  _ShowContextMenu(pSysTray);
291  }
292  break;
293 
294  case ID_ICON_HOTPLUG:
295  Hotplug_Update(pSysTray);
296 
297  switch (lParam)
298  {
299  case WM_LBUTTONDOWN:
300  SetTimer(pSysTray->GetHWnd(), HOTPLUG_TIMER_ID, GetDoubleClickTime(), NULL);
301  break;
302 
303  case WM_LBUTTONUP:
304  break;
305 
306  case WM_LBUTTONDBLCLK:
307  KillTimer(pSysTray->GetHWnd(), HOTPLUG_TIMER_ID);
308  _RunHotplug(pSysTray);
309  break;
310 
311  case WM_RBUTTONDOWN:
312  break;
313 
314  case WM_RBUTTONUP:
315  _ShowContextMenuR(pSysTray);
316  break;
317 
318  case WM_RBUTTONDBLCLK:
319  break;
320 
321  case WM_MOUSEMOVE:
322  break;
323  }
324  return S_OK;
325 
326  case WM_DEVICECHANGE:
327  switch (wParam)
328  {
331  if (FAILED(hr))
332  return hr;
333 
334  lResult = true;
335  break;
336  case DBT_DEVICEARRIVAL:
337  break;
339  break;
341  break;
343  WCHAR strInfo[128];
344  swprintf(strInfo, L"The %wS can now be safely removed from the system.", g_strMenuSel);
345  NotifyBalloon(pSysTray, L"Safe to Remove Hardware", strInfo);
346 
347  lResult = true;
348  break;
350  break;
351  }
352  return S_OK;
353 
354  /*case WM_CLOSE:
355  if (!UnregisterDeviceNotification(hDeviceNotify))
356  {
357  return S_FALSE;
358  }
359  return S_OK;*/
360 
361  default:
362  TRACE("Hotplug_Message received for unknown ID %d, ignoring.\n");
363  return S_FALSE;
364  }
365 
366  return S_FALSE;
367 }
#define HOTPLUG_SERVICE_FLAG
Definition: precomp.h:38
static void _RunHotplug(CSysTray *pSysTray)
Definition: hotplug.cpp:156
static void _ShowContextMenu(CSysTray *pSysTray)
Definition: hotplug.cpp:161
#define TRUE
Definition: types.h:120
#define WM_LBUTTONDOWN
Definition: winuser.h:1752
#define DBT_DEVNODES_CHANGED
Definition: dbt.h:28
HRESULT hr
Definition: shlfolder.c:183
#define ID_ICON_HOTPLUG
Definition: precomp.h:34
#define E_FAIL
Definition: ddrawi.h:102
WPARAM wParam
Definition: combotst.c:138
#define DBT_DEVICEREMOVECOMPLETE
Definition: dbt.h:16
HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray *pSysTray)
Definition: hotplug.cpp:130
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_RBUTTONDOWN
Definition: winuser.h:1755
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT STDMETHODCALLTYPE Hotplug_Shutdown(_In_ CSysTray *pSysTray)
Definition: hotplug.cpp:149
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define WM_TIMER
Definition: winuser.h:1718
#define DBT_DEVICEQUERYREMOVE
Definition: dbt.h:13
HRESULT EnumHotpluggedDevices(CSimpleArray< DEVINST > &devList)
Definition: hotplug.cpp:38
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WM_RBUTTONUP
Definition: winuser.h:1756
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define DBT_DEVICEQUERYREMOVEFAILED
Definition: dbt.h:14
static const WCHAR L[]
Definition: oid.c:1250
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1754
#define LRESULT
Definition: ole.h:14
#define WM_USER
Definition: winuser.h:1856
#define S_OK
Definition: intsafe.h:59
CSimpleArray< DEVINST > g_devList
Definition: hotplug.cpp:20
static WCHAR g_strMenuSel[DISPLAY_NAME_LEN]
Definition: hotplug.cpp:24
HRESULT STDMETHODCALLTYPE Hotplug_Update(_In_ CSysTray *pSysTray)
Definition: hotplug.cpp:139
#define WM_LBUTTONUP
Definition: winuser.h:1753
#define DBT_DEVICEARRIVAL
Definition: dbt.h:12
#define WM_MOUSEMOVE
Definition: winuser.h:1751
#define WM_DEVICECHANGE
Definition: winuser.h:1787
UINT WINAPI GetDoubleClickTime(void)
Definition: ntwrapper.h:314
#define DBT_DEVICEREMOVEPENDING
Definition: dbt.h:15
#define WM_RBUTTONDBLCLK
Definition: winuser.h:1757
#define HOTPLUG_TIMER_ID
Definition: precomp.h:79
HRESULT NotifyBalloon(CSysTray *pSysTray, LPCWSTR szTitle=NULL, LPCWSTR szInfo=NULL, UINT uId=ID_ICON_HOTPLUG)
Definition: hotplug.cpp:100
LPARAM lParam
Definition: combotst.c:139
static void _ShowContextMenuR(CSysTray *pSysTray)
Definition: hotplug.cpp:213

◆ Hotplug_Shutdown()

HRESULT STDMETHODCALLTYPE Hotplug_Shutdown ( _In_ CSysTray pSysTray)

Definition at line 149 of file hotplug.cpp.

150 {
151  TRACE("Hotplug_Shutdown\n");
152 
153  return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_HOTPLUG, NULL, NULL);
154 }
#define ID_ICON_HOTPLUG
Definition: precomp.h:34
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define NIM_DELETE
Definition: shellapi.h:93

Referenced by Hotplug_Message().

◆ Hotplug_Update()

HRESULT STDMETHODCALLTYPE Hotplug_Update ( _In_ CSysTray pSysTray)

Definition at line 139 of file hotplug.cpp.

140 {
141  TRACE("Hotplug_Update\n");
142 
143  if(g_devList.GetSize() || g_IsRemoving)
144  return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip);
145  else
146  return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip, NIS_HIDDEN);
147 }
static HICON g_hIconHotplug
Definition: hotplug.cpp:22
#define ID_ICON_HOTPLUG
Definition: precomp.h:34
static LPCWSTR g_strTooltip
Definition: hotplug.cpp:23
#define TRACE(s)
Definition: solgame.cpp:4
static BOOL g_IsRemoving
Definition: hotplug.cpp:25
CSimpleArray< DEVINST > g_devList
Definition: hotplug.cpp:20
#define NIM_MODIFY
Definition: shellapi.h:92

Referenced by Hotplug_Message().

◆ NotifyBalloon()

HRESULT NotifyBalloon ( CSysTray pSysTray,
LPCWSTR  szTitle = NULL,
LPCWSTR  szInfo = NULL,
UINT  uId = ID_ICON_HOTPLUG 
)

Definition at line 100 of file hotplug.cpp.

101 {
102  NOTIFYICONDATA nim = { 0 };
103 
104  nim.cbSize = sizeof(nim);
105  nim.uID = uId;
106  nim.hWnd = pSysTray->GetHWnd();
107 
108  nim.uFlags = NIF_INFO;
109  nim.uTimeout = 10;
110  nim.dwInfoFlags = NIIF_INFO;
111 
113  StringCchCopy(nim.szInfo, _countof(nim.szInfo), szInfo);
115 
116  Sleep(10000); /* As per windows, the balloon notification remains visible for atleast 10 sec.
117  This timer maintains the same condition.
118  Also it is required so that the icon doesn't hide instantly after last device is removed,
119  as that will prevent popping of notification.
120  */
122  StringCchCopy(nim.szInfo, _countof(nim.szInfo), L"");
124  g_IsRemoving = FALSE; /* This flag is used to prevent instant icon hiding after last device is removed.
125  The above timer maintains the required state for the same.
126  */
127  return ret ? S_OK : E_FAIL;
128 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define _countof(array)
Definition: fontsub.cpp:30
DWORD dwInfoFlags
Definition: shellapi.h:244
#define E_FAIL
Definition: ddrawi.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define StringCchCopy
Definition: strsafe.h:139
#define S_OK
Definition: intsafe.h:59
static BOOL g_IsRemoving
Definition: hotplug.cpp:25
HWND GetHWnd()
Definition: csystray.h:53
CHAR szInfo[256]
Definition: shellapi.h:238
#define Shell_NotifyIcon
Definition: shellapi.h:687
CHAR szInfoTitle[64]
Definition: shellapi.h:243
#define NIM_MODIFY
Definition: shellapi.h:92

Referenced by Hotplug_Message().

Variable Documentation

◆ g_devList

CSimpleArray<DEVINST> g_devList

Definition at line 20 of file hotplug.cpp.

Referenced by _ShowContextMenu(), Hotplug_Init(), Hotplug_Message(), and Hotplug_Update().

◆ g_hIconHotplug

HICON g_hIconHotplug = NULL
static

Definition at line 22 of file hotplug.cpp.

Referenced by Hotplug_Init(), and Hotplug_Update().

◆ g_IsRemoving

BOOL g_IsRemoving = FALSE
static

Definition at line 25 of file hotplug.cpp.

Referenced by _ShowContextMenu(), Hotplug_Update(), and NotifyBalloon().

◆ g_strMenuSel

WCHAR g_strMenuSel[DISPLAY_NAME_LEN]
static

Definition at line 24 of file hotplug.cpp.

Referenced by _ShowContextMenu(), and Hotplug_Message().

◆ g_strTooltip

LPCWSTR g_strTooltip = L"Safely Remove Hardware and Eject Media"
static

Definition at line 23 of file hotplug.cpp.

Referenced by Hotplug_Init(), and Hotplug_Update().