Leaked source code of windows server 2003
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.

196 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. RestoreSystemCursors.cpp
  5. Abstract:
  6. Due to a bug in NT, cursors are not correctly restored with the following
  7. code sequence:
  8. 1. hNewCursor = LoadCursor(0, "cursor.cur");
  9. 2. SetSystemCursor(hNewCursor, OCR_NORMAL)
  10. 3. hOldCursor = LoadCursor(0,MAKEINTRESOURCE(OCR_NORMAL));
  11. 4. SetSystemCursor(hOldCursor, OCR_NORMAL)
  12. The last call (4) does nothing on NT, but works correctly on Win9x.
  13. To fix this we use the known USER workaround, namely CopyCursor. Note that
  14. this will probably be fixed in Whistler by the time it ships.
  15. Notes:
  16. This is a general purpose shim.
  17. History:
  18. 02/13/2000 linstev Created
  19. --*/
  20. #include "precomp.h"
  21. IMPLEMENT_SHIM_BEGIN(RestoreSystemCursors)
  22. #include "ShimHookMacro.h"
  23. APIHOOK_ENUM_BEGIN
  24. APIHOOK_ENUM_ENTRY(GetCommandLineA)
  25. APIHOOK_ENUM_ENTRY(GetCommandLineW)
  26. APIHOOK_ENUM_END
  27. #define OCR_NORMAL 32512UL
  28. #define OCR_IBEAM 32513UL
  29. #define OCR_WAIT 32514UL
  30. #define OCR_CROSS 32515UL
  31. #define OCR_UP 32516UL
  32. #define OCR_SIZE 32640UL
  33. #define OCR_ICON 32641UL
  34. #define OCR_SIZENWSE 32642UL
  35. #define OCR_SIZENESW 32643UL
  36. #define OCR_SIZEWE 32644UL
  37. #define OCR_SIZENS 32645UL
  38. #define OCR_SIZEALL 32646UL
  39. #define OCR_ICOCUR 32647UL
  40. #define OCR_NO 32648UL
  41. #define OCR_HAND 32649UL
  42. #define OCR_APPSTARTING 32650UL
  43. struct CURSOR
  44. {
  45. DWORD id;
  46. HCURSOR hCursor;
  47. };
  48. CURSOR g_arrCursors[] =
  49. {
  50. {OCR_NORMAL, 0},
  51. {OCR_IBEAM, 0},
  52. {OCR_WAIT, 0},
  53. {OCR_CROSS, 0},
  54. {OCR_UP, 0},
  55. {OCR_SIZE, 0},
  56. {OCR_ICON, 0},
  57. {OCR_SIZENWSE, 0},
  58. {OCR_SIZENESW, 0},
  59. {OCR_SIZEWE, 0},
  60. {OCR_SIZENS, 0},
  61. {OCR_SIZEALL, 0},
  62. {OCR_ICOCUR, 0},
  63. {OCR_NO, 0},
  64. {OCR_HAND, 0},
  65. {OCR_APPSTARTING, 0}
  66. };
  67. BOOL g_bInit = FALSE;
  68. /*++
  69. Backup cursors.
  70. --*/
  71. VOID
  72. BackupCursors()
  73. {
  74. if (!g_bInit)
  75. {
  76. g_bInit = TRUE;
  77. // Backup all the cursors
  78. for (int i=0; i<sizeof(g_arrCursors)/sizeof(CURSOR);i++)
  79. {
  80. HCURSOR hCursorT = LoadCursor(0,MAKEINTRESOURCE(g_arrCursors[i].id));
  81. if (hCursorT)
  82. {
  83. g_arrCursors[i].hCursor = CopyCursor(hCursorT);
  84. DestroyCursor(hCursorT);
  85. }
  86. else
  87. {
  88. g_arrCursors[i].hCursor = 0;
  89. }
  90. }
  91. }
  92. }
  93. /*++
  94. Restore cursors.
  95. --*/
  96. VOID
  97. RestoreCursors()
  98. {
  99. if (g_bInit)
  100. {
  101. // Restore all the cursors
  102. for (int i=0; i<sizeof(g_arrCursors)/sizeof(CURSOR);i++)
  103. {
  104. if (g_arrCursors[i].hCursor)
  105. {
  106. SetSystemCursor(g_arrCursors[i].hCursor, g_arrCursors[i].id);
  107. DestroyCursor(g_arrCursors[i].hCursor);
  108. }
  109. }
  110. }
  111. }
  112. /*++
  113. Backup cursors.
  114. --*/
  115. LPSTR
  116. APIHOOK(GetCommandLineA)()
  117. {
  118. BackupCursors();
  119. return ORIGINAL_API(GetCommandLineA)();
  120. }
  121. /*++
  122. Backup cursors.
  123. --*/
  124. LPWSTR
  125. APIHOOK(GetCommandLineW)()
  126. {
  127. BackupCursors();
  128. return ORIGINAL_API(GetCommandLineW)();
  129. }
  130. /*++
  131. Register hooked functions
  132. --*/
  133. BOOL
  134. NOTIFY_FUNCTION(
  135. DWORD fdwReason
  136. )
  137. {
  138. if (fdwReason == DLL_PROCESS_DETACH) {
  139. RestoreCursors();
  140. }
  141. return TRUE;
  142. }
  143. HOOK_BEGIN
  144. CALL_NOTIFY_FUNCTION
  145. APIHOOK_ENTRY(KERNEL32.DLL, GetCommandLineA)
  146. APIHOOK_ENTRY(KERNEL32.DLL, GetCommandLineW)
  147. HOOK_END
  148. IMPLEMENT_SHIM_END