Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: notify.c
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "HotPlug.h"
  11. void
  12. OnTimerDeviceChange(
  13. PDEVICETREE DeviceTree
  14. )
  15. {
  16. //
  17. // if a refresh event is pending, rebuild the entire tree.
  18. //
  19. if (DeviceTree->RefreshEvent) {
  20. if (RefreshTree(DeviceTree)) {
  21. DeviceTree->RefreshEvent = FALSE;
  22. }
  23. }
  24. }
  25. BOOL
  26. RefreshTree(
  27. PDEVICETREE DeviceTree
  28. )
  29. {
  30. CONFIGRET ConfigRet;
  31. DEVINST DeviceInstance;
  32. DEVINST SelectedDevInst;
  33. PDEVTREENODE DevTreeNode;
  34. HTREEITEM hTreeItem;
  35. HCURSOR hCursor;
  36. if (DeviceTree->RedrawWait) {
  37. DeviceTree->RefreshEvent = TRUE;
  38. SetTimer(DeviceTree->hDlg, TIMERID_DEVICECHANGE,1000,NULL);
  39. return FALSE;
  40. }
  41. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  42. DeviceTree->RedrawWait = TRUE;
  43. SendMessage(DeviceTree->hwndTree, WM_SETREDRAW, FALSE, 0L);
  44. SelectedDevInst = DeviceTree->SelectedTreeNode
  45. ? DeviceTree->SelectedTreeNode->DevInst
  46. : 0;
  47. ClearRemovalList(DeviceTree);
  48. TreeView_DeleteAllItems(DeviceTree->hwndTree);
  49. RemoveChildSiblings(DeviceTree, &DeviceTree->ChildSiblingList);
  50. ConfigRet = CM_Get_Child_Ex(&DeviceInstance,
  51. DeviceTree->DevInst,
  52. 0,
  53. DeviceTree->hMachine
  54. );
  55. if (ConfigRet == CR_SUCCESS) {
  56. AddChildSiblings(DeviceTree,
  57. NULL,
  58. DeviceInstance,
  59. 0,
  60. TRUE
  61. );
  62. }
  63. DisplayChildSiblings(DeviceTree,
  64. &DeviceTree->ChildSiblingList,
  65. NULL,
  66. FALSE
  67. );
  68. //
  69. // restore treeview redraw state, and reset the selected item
  70. //
  71. DevTreeNode = DevTreeNodeByDevInst(SelectedDevInst,
  72. &DeviceTree->ChildSiblingList
  73. );
  74. if (DevTreeNode) {
  75. hTreeItem = DevTreeNode->hTreeItem;
  76. }
  77. else {
  78. hTreeItem = NULL;
  79. }
  80. if (!hTreeItem) {
  81. hTreeItem = TreeView_GetRoot(DeviceTree->hwndTree);
  82. }
  83. SendMessage(DeviceTree->hwndTree, WM_SETREDRAW, TRUE, 0L);
  84. DeviceTree->RedrawWait = FALSE;
  85. TreeView_SelectItem(DeviceTree->hwndTree, NULL);
  86. if (hTreeItem) {
  87. TreeView_SelectItem(DeviceTree->hwndTree, hTreeItem);
  88. } else {
  89. //
  90. // No device is selected
  91. //
  92. EnableWindow(GetDlgItem(DeviceTree->hDlg, IDC_STOPDEVICE), FALSE);
  93. EnableWindow(GetDlgItem(DeviceTree->hDlg, IDC_PROPERTIES), FALSE);
  94. SetDlgItemText(DeviceTree->hDlg, IDC_DEVICEDESC, TEXT(""));
  95. }
  96. SetCursor(hCursor);
  97. return TRUE;
  98. }