ReactOS  0.4.15-dev-5079-gf79e80c
hotplug.c File Reference
#include "hotplug.h"
#include <initguid.h>
#include <devguid.h>
#include <debug.h>
Include dependency graph for hotplug.c:

Go to the source code of this file.

Classes

struct  _HOTPLUG_DATA
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _HOTPLUG_DATA HOTPLUG_DATA
 
typedef struct _HOTPLUG_DATAPHOTPLUG_DATA
 

Functions

static DWORD GetHotPlugFlags (VOID)
 
static DWORD SetHotPlugFlags (_In_ DWORD dwFlags)
 
static HTREEITEM InsertDeviceTreeItem (_In_ HWND hwndDeviceTree, _In_ HTREEITEM hParent, _In_ DWORD DevInst, _In_ PHOTPLUG_DATA pHotplugData)
 
static VOID RecursiveInsertSubDevices (_In_ HWND hwndDeviceTree, _In_ HTREEITEM hParentItem, _In_ DWORD ParentDevInst, _In_ PHOTPLUG_DATA pHotplugData)
 
static VOID EnumHotpluggedDevices (HWND hwndDeviceTree, PHOTPLUG_DATA pHotplugData)
 
static VOID UpdateButtons (HWND hwndDlg)
 
static VOID ShowContextMenu (HWND hwndDlg, HWND hwndTreeView, PHOTPLUG_DATA pHotplugData)
 
INT_PTR CALLBACK SafeRemovalDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
LONG APIENTRY InitApplet (HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
 
LONG CALLBACK CPlApplet (HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
 
INT WINAPI DllMain (HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
 

Variables

HINSTANCE hApplet = 0
 
APPLET Applets [NUM_APPLETS]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file hotplug.c.

Typedef Documentation

◆ HOTPLUG_DATA

◆ PHOTPLUG_DATA

Function Documentation

◆ CPlApplet()

LONG CALLBACK CPlApplet ( HWND  hwndCPl,
UINT  uMsg,
LPARAM  lParam1,
LPARAM  lParam2 
)

Definition at line 534 of file hotplug.c.

539 {
540  UINT i = (UINT)lParam1;
541 
542  switch(uMsg)
543  {
544  case CPL_INIT:
545  return TRUE;
546 
547  case CPL_GETCOUNT:
548  return NUM_APPLETS;
549 
550  case CPL_INQUIRE:
551  if (i < NUM_APPLETS)
552  {
553  CPLINFO *CPlInfo = (CPLINFO*)lParam2;
554  CPlInfo->lData = 0;
555  CPlInfo->idIcon = Applets[i].idIcon;
556  CPlInfo->idName = Applets[i].idName;
557  CPlInfo->idInfo = Applets[i].idDescription;
558  }
559  else
560  {
561  return TRUE;
562  }
563  break;
564 
565  case CPL_DBLCLK:
566  if (i < NUM_APPLETS)
567  Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
568  else
569  return TRUE;
570  break;
571 
572  case CPL_STARTWPARMSW:
573  if (i < NUM_APPLETS)
574  return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
575  break;
576  }
577  return FALSE;
578 }
Definition: cpl.h:24
#define TRUE
Definition: types.h:120
int idName
Definition: hotplug.h:36
int idIcon
Definition: hotplug.h:35
int idInfo
Definition: cpl.h:27
int idIcon
Definition: cpl.h:25
int idDescription
Definition: hotplug.h:37
#define CPL_DBLCLK
Definition: cpl.h:16
APPLET Applets[NUM_APPLETS]
Definition: hotplug.c:32
#define FALSE
Definition: types.h:117
APPLET_PROC AppletProc
Definition: hotplug.h:38
#define CPL_STARTWPARMSW
Definition: cpl.h:21
#define CPL_INIT
Definition: cpl.h:12
#define CPL_INQUIRE
Definition: cpl.h:14
LONG_PTR lData
Definition: cpl.h:28
int idName
Definition: cpl.h:26
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
unsigned int UINT
Definition: ndis.h:50
#define NUM_APPLETS
Definition: access.c:14
#define CPL_GETCOUNT
Definition: cpl.h:13

◆ DllMain()

INT WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  dwReason,
LPVOID  lpvReserved 
)

Definition at line 583 of file hotplug.c.

587 {
589 
590  switch (dwReason)
591  {
592  case DLL_PROCESS_ATTACH:
593  case DLL_THREAD_ATTACH:
594  hApplet = hinstDLL;
595  break;
596  }
597  return TRUE;
598 }
HINSTANCE hApplet
Definition: hotplug.c:29
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define DLL_THREAD_ATTACH
Definition: compat.h:132
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
static IN DWORD IN LPVOID lpvReserved
DWORD dwReason
Definition: misc.cpp:154

◆ EnumHotpluggedDevices()

static VOID EnumHotpluggedDevices ( HWND  hwndDeviceTree,
PHOTPLUG_DATA  pHotplugData 
)
static

Definition at line 231 of file hotplug.c.

234 {
235  SP_DEVINFO_DATA did = { 0 };
236  HDEVINFO hdev;
237  int idev;
238  DWORD dwCapabilities, dwSize;
239  ULONG ulStatus, ulProblem;
240  HTREEITEM hTreeItem;
241  CONFIGRET cr;
242 
243  DPRINT1("EnumHotpluggedDevices()\n");
244 
245  TreeView_DeleteAllItems(hwndDeviceTree);
246 
248  if (hdev == INVALID_HANDLE_VALUE)
249  return;
250 
251  did.cbSize = sizeof(did);
252 
253  /* Enumerate all the attached devices */
254  for (idev = 0; SetupDiEnumDeviceInfo(hdev, idev, &did); idev++)
255  {
256  ulStatus = 0;
257  ulProblem = 0;
258 
259  cr = CM_Get_DevNode_Status(&ulStatus,
260  &ulProblem,
261  did.DevInst,
262  0);
263  if (cr != CR_SUCCESS)
264  continue;
265 
266  dwCapabilities = 0,
267  dwSize = sizeof(dwCapabilities);
270  NULL,
271  &dwCapabilities,
272  &dwSize,
273  0);
274  if (cr != CR_SUCCESS)
275  continue;
276 
277  /* Add devices that require safe removal to the device tree */
278  if ( (dwCapabilities & CM_DEVCAP_REMOVABLE) &&
279  !(dwCapabilities & CM_DEVCAP_DOCKDEVICE) &&
280  !(dwCapabilities & CM_DEVCAP_SURPRISEREMOVALOK) &&
281  ((dwCapabilities & CM_DEVCAP_EJECTSUPPORTED) || (ulStatus & DN_DISABLEABLE)) &&
282  ulProblem == 0)
283  {
284  hTreeItem = InsertDeviceTreeItem(hwndDeviceTree,
285  TVI_ROOT,
286  did.DevInst,
287  pHotplugData);
288 
289  if ((hTreeItem != NULL) && (pHotplugData->dwFlags & HOTPLUG_DISPLAY_DEVICE_COMPONENTS))
290  {
291  RecursiveInsertSubDevices(hwndDeviceTree,
292  hTreeItem,
293  did.DevInst,
294  pHotplugData);
295  }
296  }
297  }
298 
300 }
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1787
#define CM_Get_DevNode_Registry_Property
Definition: cfgmgr32.h:1733
#define CM_DEVCAP_REMOVABLE
Definition: cfgmgr32.h:737
#define CM_DEVCAP_EJECTSUPPORTED
Definition: cfgmgr32.h:736
#define TreeView_DeleteAllItems(hwnd)
Definition: commctrl.h:3417
DWORD dwFlags
Definition: hotplug.c:24
#define DN_DISABLEABLE
Definition: cfg.h:131
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define HOTPLUG_DISPLAY_DEVICE_COMPONENTS
Definition: hotplug.h:24
static VOID RecursiveInsertSubDevices(_In_ HWND hwndDeviceTree, _In_ HTREEITEM hParentItem, _In_ DWORD ParentDevInst, _In_ PHOTPLUG_DATA pHotplugData)
Definition: hotplug.c:174
static HTREEITEM InsertDeviceTreeItem(_In_ HWND hwndDeviceTree, _In_ HTREEITEM hParent, _In_ DWORD DevInst, _In_ PHOTPLUG_DATA pHotplugData)
Definition: hotplug.c:108
#define CR_SUCCESS
Definition: cfgmgr32.h:842
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TVI_ROOT
Definition: commctrl.h:3368
#define DIGCF_ALLCLASSES
Definition: setupapi.h:172
#define SetupDiGetClassDevs
Definition: setupapi.h:2593
#define NULL
Definition: types.h:112
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define DPRINT1
Definition: precomp.h:8
CONFIGRET WINAPI CM_Get_DevNode_Status(_Out_ PULONG pulStatus, _Out_ PULONG pulProblemNumber, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:3573
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:56
#define DIGCF_PRESENT
Definition: setupapi.h:171

Referenced by SafeRemovalDlgProc().

◆ GetHotPlugFlags()

static DWORD GetHotPlugFlags ( VOID  )
static

Definition at line 39 of file hotplug.c.

40 {
41  HKEY hKey = NULL;
42  DWORD dwFlags = 0;
43  DWORD dwSize, dwError;
44 
47  0,
48  KEY_READ,
49  &hKey);
50  if (dwError != ERROR_SUCCESS)
51  goto done;
52 
53  dwSize = sizeof(dwFlags);
54  dwError = RegQueryValueExW(hKey,
55  L"HotPlugFlags",
56  NULL,
57  NULL,
58  (LPBYTE)&dwFlags,
59  &dwSize);
60  if (dwError != ERROR_SUCCESS)
61  dwFlags = 0;
62 
63 done:
64  if (hKey != NULL)
66 
67  return dwFlags;
68 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
#define REGSTR_PATH_SYSTRAY
Definition: regstr.h:531
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4120
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
#define RegCloseKey(hKey)
Definition: registry.h:47
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by SafeRemovalDlgProc().

◆ InitApplet()

LONG APIENTRY InitApplet ( HWND  hwnd,
UINT  uMsg,
LPARAM  wParam,
LPARAM  lParam 
)

Definition at line 514 of file hotplug.c.

519 {
520  DPRINT("InitApplet()\n");
521 
524  hwnd,
526 
527  // TODO
528  return TRUE;
529 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
HINSTANCE hApplet
Definition: hotplug.c:29
#define TRUE
Definition: types.h:120
#define DialogBox
Definition: winuser.h:5751
#define IDD_SAFE_REMOVE_HARDWARE_DIALOG
Definition: resource.h:9
INT_PTR CALLBACK SafeRemovalDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: hotplug.c:349
#define DPRINT
Definition: sndvol32.h:71
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022

◆ InsertDeviceTreeItem()

static HTREEITEM InsertDeviceTreeItem ( _In_ HWND  hwndDeviceTree,
_In_ HTREEITEM  hParent,
_In_ DWORD  DevInst,
_In_ PHOTPLUG_DATA  pHotplugData 
)
static

Definition at line 108 of file hotplug.c.

113 {
114  WCHAR szDisplayName[40];
115  WCHAR szGuidString[MAX_GUID_STRING_LEN];
116  TVINSERTSTRUCTW tvItem;
117  GUID ClassGuid;
118  INT nClassImage;
119  DWORD dwSize;
120  CONFIGRET cr;
121 
122  /* Get the device description */
123  dwSize = sizeof(szDisplayName);
126  NULL,
127  szDisplayName,
128  &dwSize,
129  0);
130  if (cr != CR_SUCCESS)
131  wcscpy(szDisplayName, L"Unknown Device");
132 
133  /* Get the class GUID */
134  dwSize = sizeof(szGuidString);
137  NULL,
138  szGuidString,
139  &dwSize,
140  0);
141  if (cr == CR_SUCCESS)
142  {
143  pSetupGuidFromString(szGuidString, &ClassGuid);
144  }
145  else
146  {
147  memcpy(&ClassGuid, &GUID_DEVCLASS_UNKNOWN, sizeof(GUID));
148  }
149 
150  /* Get the image for the class this device is in */
151  SetupDiGetClassImageIndex(&pHotplugData->ImageListData,
152  &ClassGuid,
153  &nClassImage);
154 
155  /* Add it to the device tree */
156  ZeroMemory(&tvItem, sizeof(tvItem));
157  tvItem.hParent = hParent;
158  tvItem.hInsertAfter = TVI_LAST;
159 
160  tvItem.item.mask = TVIF_STATE | TVIF_TEXT /*| TVIF_PARAM*/ | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
161  tvItem.item.state = TVIS_EXPANDED;
162  tvItem.item.stateMask = TVIS_EXPANDED;
163  tvItem.item.pszText = szDisplayName;
164  tvItem.item.iImage = nClassImage;
165  tvItem.item.iSelectedImage = nClassImage;
166  tvItem.item.lParam = (LPARAM)NULL;
167 
168  return TreeView_InsertItem(hwndDeviceTree, &tvItem);
169 }
#define CM_Get_DevNode_Registry_Property
Definition: cfgmgr32.h:1733
HTREEITEM hParent
Definition: commctrl.h:3393
#define ZeroMemory
Definition: winbase.h:1667
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3271
int32_t INT
Definition: typedefs.h:58
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3412
#define L(x)
Definition: ntvdm.h:50
HTREEITEM hInsertAfter
Definition: commctrl.h:3394
#define CR_SUCCESS
Definition: cfgmgr32.h:842
#define CM_DRP_CLASSGUID
Definition: cfgmgr32.h:684
LONG_PTR LPARAM
Definition: windef.h:208
#define TVI_LAST
Definition: commctrl.h:3370
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_GUID_STRING_LEN
Definition: apphelp.c:29
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI SetupDiGetClassImageIndex(IN PSP_CLASSIMAGELIST_DATA ClassImageListData, IN CONST GUID *ClassGuid, OUT PINT ImageIndex)
Definition: devclass.c:277
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define CM_DRP_DEVICEDESC
Definition: cfgmgr32.h:676
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define TVIS_EXPANDED
Definition: commctrl.h:3284
#define TVIF_TEXT
Definition: commctrl.h:3266
#define TVIF_IMAGE
Definition: commctrl.h:3267
#define NULL
Definition: types.h:112
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define TVIF_STATE
Definition: commctrl.h:3269
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
DWORD WINAPI pSetupGuidFromString(PCWSTR pString, LPGUID lpGUID)
Definition: misc.c:1751

Referenced by EnumHotpluggedDevices(), and RecursiveInsertSubDevices().

◆ RecursiveInsertSubDevices()

static VOID RecursiveInsertSubDevices ( _In_ HWND  hwndDeviceTree,
_In_ HTREEITEM  hParentItem,
_In_ DWORD  ParentDevInst,
_In_ PHOTPLUG_DATA  pHotplugData 
)
static

Definition at line 174 of file hotplug.c.

179 {
180  HTREEITEM hTreeItem;
181  DEVINST ChildDevInst;
182  CONFIGRET cr;
183 
184  DPRINT("RecursiveInsertSubDevices()\n");
185 
186  cr = CM_Get_Child(&ChildDevInst, ParentDevInst, 0);
187  if (cr != CR_SUCCESS)
188  {
189  DPRINT("No child! %lu\n", cr);
190  return;
191  }
192 
193  hTreeItem = InsertDeviceTreeItem(hwndDeviceTree,
194  hParentItem,
195  ChildDevInst,
196  pHotplugData);
197  if (hTreeItem != NULL)
198  {
199  RecursiveInsertSubDevices(hwndDeviceTree,
200  hTreeItem,
201  ChildDevInst,
202  pHotplugData);
203  }
204 
205  for (;;)
206  {
207  cr = CM_Get_Sibling(&ChildDevInst, ChildDevInst, 0);
208  if (cr != CR_SUCCESS)
209  {
210  DPRINT("No sibling! %lu\n", cr);
211  return;
212  }
213 
214  hTreeItem = InsertDeviceTreeItem(hwndDeviceTree,
215  hParentItem,
216  ChildDevInst,
217  pHotplugData);
218  if (hTreeItem != NULL)
219  {
220  RecursiveInsertSubDevices(hwndDeviceTree,
221  hTreeItem,
222  ChildDevInst,
223  pHotplugData);
224  }
225  }
226 }
CONFIGRET WINAPI CM_Get_Sibling(_Out_ PDEVINST pdnDevInst, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:5530
static VOID RecursiveInsertSubDevices(_In_ HWND hwndDeviceTree, _In_ HTREEITEM hParentItem, _In_ DWORD ParentDevInst, _In_ PHOTPLUG_DATA pHotplugData)
Definition: hotplug.c:174
static HTREEITEM InsertDeviceTreeItem(_In_ HWND hwndDeviceTree, _In_ HTREEITEM hParent, _In_ DWORD DevInst, _In_ PHOTPLUG_DATA pHotplugData)
Definition: hotplug.c:108
CONFIGRET WINAPI CM_Get_Child(_Out_ PDEVINST pdnDevInst, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:2530
#define CR_SUCCESS
Definition: cfgmgr32.h:842
DWORD DEVINST
Definition: cfgmgr32.h:76
#define NULL
Definition: types.h:112
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define DPRINT
Definition: sndvol32.h:71

Referenced by EnumHotpluggedDevices().

◆ SafeRemovalDlgProc()

INT_PTR CALLBACK SafeRemovalDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 349 of file hotplug.c.

354 {
355  PHOTPLUG_DATA pHotplugData;
356 
357  pHotplugData = (PHOTPLUG_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
358 
359  switch (uMsg)
360  {
361  case WM_INITDIALOG:
362  pHotplugData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HOTPLUG_DATA));
363  if (pHotplugData != NULL)
364  {
365  WCHAR szWindowTitle[MAX_PATH];
366 
367  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pHotplugData);
368 
369  if (LoadStringW(hApplet,
370  IDS_CPLNAME,
371  szWindowTitle,
372  ARRAYSIZE(szWindowTitle)))
373  {
374  SetWindowTextW(hwndDlg, szWindowTitle);
375  }
376 
377  pHotplugData->hIcon = (HICON)LoadImageW(hApplet,
379  IMAGE_ICON,
383  pHotplugData->hIconSm = (HICON)LoadImageW(hApplet,
385  IMAGE_ICON,
389  SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)pHotplugData->hIcon);
390  SendMessageW(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)pHotplugData->hIconSm);
391 
392  pHotplugData->ImageListData.cbSize = sizeof(pHotplugData->ImageListData);
393  SetupDiGetClassImageList(&pHotplugData->ImageListData);
394 
396 
397  pHotplugData->dwFlags = GetHotPlugFlags();
398 
399  if (pHotplugData->dwFlags & HOTPLUG_DISPLAY_DEVICE_COMPONENTS)
401 
403  pHotplugData->ImageListData.ImageList,
404  TVSIL_NORMAL);
405 
407  pHotplugData);
408  UpdateButtons(hwndDlg);
409  }
410  return TRUE;
411 
412  case WM_COMMAND:
413  switch (LOWORD(wParam))
414  {
415  case IDCLOSE:
416  KillTimer(hwndDlg, 1);
417  EndDialog(hwndDlg, TRUE);
418  break;
419 
421  if (HIWORD(wParam) == BN_CLICKED)
422  {
423  if (pHotplugData != NULL)
424  {
427  else
428  pHotplugData->dwFlags &= ~HOTPLUG_DISPLAY_DEVICE_COMPONENTS;
429 
430  SetHotPlugFlags(pHotplugData->dwFlags);
431 
433  pHotplugData);
434  }
435  }
436  break;
437  }
438  break;
439 
440  case WM_DEVICECHANGE:
441  switch (wParam)
442  {
444  SetTimer(hwndDlg, 1, 500, NULL);
445  break;
446  }
447  break;
448 
449  case WM_TIMER:
450  if (wParam == 1)
451  {
452  KillTimer(hwndDlg, 1);
453 
454  if (pHotplugData != NULL)
455  {
457  pHotplugData);
458  UpdateButtons(hwndDlg);
459  }
460  }
461  break;
462 
463  case WM_NOTIFY:
464  if (((LPNMHDR)lParam)->idFrom == IDC_SAFE_REMOVE_DEVICE_TREE)
465  {
466  if (((LPNMHDR)lParam)->code == NM_RCLICK)
467  {
468  if (pHotplugData != NULL)
469  {
470  ShowContextMenu(hwndDlg,
471  ((LPNMHDR)lParam)->hwndFrom,
472  pHotplugData);
473  return TRUE;
474  }
475  }
476  }
477  break;
478 
479  case WM_CLOSE:
480  KillTimer(hwndDlg, 1);
481  EndDialog(hwndDlg, TRUE);
482  break;
483 
484  case WM_DESTROY:
485  if (pHotplugData != NULL)
486  {
487  if (pHotplugData->hPopupMenu != NULL)
488  DestroyMenu(pHotplugData->hPopupMenu);
489 
491 
492  if (pHotplugData->hIconSm)
493  {
494  DestroyIcon(pHotplugData->hIconSm);
495  }
496 
497  if (pHotplugData->hIcon)
498  {
499  DestroyIcon(pHotplugData->hIcon);
500  }
501 
502  HeapFree(GetProcessHeap(), 0, pHotplugData);
504  }
505  break;
506  }
507 
508  return FALSE;
509 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
#define IMAGE_ICON
Definition: winuser.h:212
#define DBT_DEVNODES_CHANGED
Definition: dbt.h:28
HINSTANCE hApplet
Definition: hotplug.c:29
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define TRUE
Definition: types.h:120
static DWORD SetHotPlugFlags(_In_ DWORD dwFlags)
Definition: hotplug.c:73
DWORD dwFlags
Definition: hotplug.c:24
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define HOTPLUG_DISPLAY_DEVICE_COMPONENTS
Definition: hotplug.h:24
#define SM_CYSMICON
Definition: winuser.h:1007
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define IDI_HOTPLUG
Definition: resource.h:4
BOOL WINAPI SetupDiGetClassImageList(OUT PSP_CLASSIMAGELIST_DATA ClassImageListData)
Definition: devclass.c:322
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define SetWindowLongPtr
Definition: treelist.c:70
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define ICON_SMALL
Definition: tnclass.cpp:48
static VOID UpdateButtons(HWND hwndDlg)
Definition: hotplug.c:305
#define IDS_CPLNAME
Definition: resource.h:8
#define FALSE
Definition: types.h:117
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
#define SM_CXICON
Definition: winuser.h:966
BOOL WINAPI SetupDiDestroyClassImageList(IN PSP_CLASSIMAGELIST_DATA ClassImageListData)
Definition: devclass.c:85
LONG_PTR LPARAM
Definition: windef.h:208
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3447
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_DESTROY
Definition: winuser.h:1599
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static VOID EnumHotpluggedDevices(HWND hwndDeviceTree, PHOTPLUG_DATA pHotplugData)
Definition: hotplug.c:231
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDM_POPUP_DEVICE_TREE
Definition: resource.h:20
#define WM_TIMER
Definition: winuser.h:1732
#define WM_CLOSE
Definition: winuser.h:1611
#define MAX_PATH
Definition: compat.h:34
#define Button_GetCheck(hwndCtl)
Definition: windowsx.h:6
int WINAPI GetSystemMetrics(_In_ int)
#define BN_CLICKED
Definition: winuser.h:1915
SP_CLASSIMAGELIST_DATA ImageListData
Definition: hotplug.c:22
#define SM_CXSMICON
Definition: winuser.h:1006
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SM_CYICON
Definition: winuser.h:967
struct _HOTPLUG_DATA * PHOTPLUG_DATA
#define DWLP_USER
Definition: winuser.h:866
#define WM_COMMAND
Definition: winuser.h:1730
Definition: inflate.c:139
BOOL WINAPI DestroyMenu(_In_ HMENU)
static DWORD GetHotPlugFlags(VOID)
Definition: hotplug.c:39
#define LoadMenu
Definition: winuser.h:5807
#define NM_RCLICK
Definition: commctrl.h:133
HICON hIconSm
Definition: hotplug.c:21
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define IDC_SAFE_REMOVE_DEVICE_TREE
Definition: resource.h:11
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define BST_CHECKED
Definition: winuser.h:197
#define WM_DEVICECHANGE
Definition: winuser.h:1801
#define Button_SetCheck(hwndCtl, check)
Definition: windowsx.h:10
#define TVSIL_NORMAL
Definition: commctrl.h:3443
#define HIWORD(l)
Definition: typedefs.h:247
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: treelist.c:73
static VOID ShowContextMenu(HWND hwndDlg, HWND hwndTreeView, PHOTPLUG_DATA pHotplugData)
Definition: hotplug.c:319
#define LR_DEFAULTCOLOR
Definition: winuser.h:1081
HMENU hPopupMenu
Definition: hotplug.c:23
#define IDC_SAFE_REMOVE_DISPLAY_COMPONENTS
Definition: resource.h:15
#define WM_INITDIALOG
Definition: winuser.h:1729
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:594
#define WM_NOTIFY
Definition: richedit.h:61
#define ICON_BIG
Definition: tnclass.cpp:51
HICON hIcon
Definition: hotplug.c:20

Referenced by InitApplet().

◆ SetHotPlugFlags()

static DWORD SetHotPlugFlags ( _In_ DWORD  dwFlags)
static

Definition at line 73 of file hotplug.c.

75 {
76  HKEY hKey = NULL;
77  DWORD dwError;
78 
81  0,
82  NULL,
84  KEY_WRITE,
85  NULL,
86  &hKey,
87  NULL);
88  if (dwError != ERROR_SUCCESS)
89  goto done;
90 
91  dwError = RegSetValueExW(hKey,
92  L"HotPlugFlags",
93  0,
94  REG_DWORD,
95  (LPBYTE)&dwFlags,
96  sizeof(dwFlags));
97 
98 done:
99  if (hKey != NULL)
100  RegCloseKey(hKey);
101 
102  return dwError;
103 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
#define REGSTR_PATH_SYSTRAY
Definition: regstr.h:531
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4899
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
#define REG_DWORD
Definition: sdbapi.c:596
#define RegCloseKey(hKey)
Definition: registry.h:47

Referenced by SafeRemovalDlgProc().

◆ ShowContextMenu()

static VOID ShowContextMenu ( HWND  hwndDlg,
HWND  hwndTreeView,
PHOTPLUG_DATA  pHotplugData 
)
static

Definition at line 319 of file hotplug.c.

323 {
324  HTREEITEM hTreeItem;
325  RECT rc;
326  POINT pt;
327 
328  hTreeItem = TreeView_GetSelection(hwndTreeView);
329  if (hTreeItem == NULL)
330  return;
331 
332  TreeView_GetItemRect(hwndTreeView, hTreeItem, &rc, TRUE);
333 
334  pt.x = (rc.left + rc.right) / 2;
335  pt.y = (rc.top + rc.bottom) / 2;
337  TrackPopupMenu(GetSubMenu(pHotplugData->hPopupMenu, 0),
339  pt.x,
340  pt.y,
341  0,
342  hwndDlg,
343  NULL);
344 }
#define TreeView_GetItemRect(hwnd, hitem, prc, code)
Definition: commctrl.h:3429
BOOL WINAPI ClientToScreen(_In_ HWND, _Inout_ LPPOINT)
#define TRUE
Definition: types.h:120
#define pt(x, y)
Definition: drawing.c:79
#define TPM_LEFTALIGN
Definition: winuser.h:2367
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
LONG right
Definition: windef.h:308
#define TPM_TOPALIGN
Definition: winuser.h:2373
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3473
HWND hwndTreeView
Definition: eventvwr.c:84
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define NULL
Definition: types.h:112
LONG bottom
Definition: windef.h:309
HMENU hPopupMenu
Definition: hotplug.c:23
BOOL WINAPI TrackPopupMenu(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _Reserved_ int, _In_ HWND, _Reserved_ LPCRECT)

Referenced by OpenDialogProc(), SafeRemovalDlgProc(), SaveDialogProc(), and VfdPageDlgProc().

◆ UpdateButtons()

static VOID UpdateButtons ( HWND  hwndDlg)
static

Definition at line 305 of file hotplug.c.

307 {
308  BOOL bEnabled;
309 
310  bEnabled = (TreeView_GetCount(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE)) != 0);
311 
313  EnableWindow(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_STOP), bEnabled);
314 }
#define IDC_SAFE_REMOVE_STOP
Definition: resource.h:14
#define TreeView_GetCount(hwnd)
Definition: commctrl.h:3432
unsigned int BOOL
Definition: ntddk_ex.h:94
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define IDC_SAFE_REMOVE_DEVICE_TREE
Definition: resource.h:11
#define IDC_SAFE_REMOVE_PROPERTIES
Definition: resource.h:13

Referenced by SafeRemovalDlgProc().

Variable Documentation

◆ Applets

APPLET Applets[NUM_APPLETS]
Initial value:
=
{
}
#define IDI_HOTPLUG
Definition: resource.h:4
#define IDS_CPLNAME
Definition: resource.h:8
#define IDS_CPLDESCRIPTION
Definition: resource.h:9
LONG APIENTRY InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
Definition: hotplug.c:514

Definition at line 32 of file hotplug.c.

Referenced by CPlApplet().

◆ hApplet

HINSTANCE hApplet = 0

Definition at line 29 of file hotplug.c.

Referenced by DllMain(), InitApplet(), and SafeRemovalDlgProc().