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.

103 lines
1.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. LazyReleaseDC.cpp
  5. Abstract:
  6. Delay releasing a DC by one call. A DC is not released until the next call to ReleaseDC
  7. Notes:
  8. This is a general purpose shim.
  9. History:
  10. 10/10/1999 linstev Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(LazyReleaseDC)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(ReleaseDC)
  17. APIHOOK_ENUM_END
  18. HWND g_hWndPrev;
  19. HDC g_hDcPrev;
  20. CRITICAL_SECTION g_MakeThreadSafe;
  21. /*++
  22. Save this hWnd and hdc for releasing later. If there is already a DC to be
  23. released, release it now.
  24. --*/
  25. int
  26. APIHOOK(ReleaseDC)(
  27. HWND hWnd,
  28. HDC hdc
  29. )
  30. {
  31. UINT uRet = 1; // All's well
  32. EnterCriticalSection(&g_MakeThreadSafe);
  33. // If there is a previous DC, release it now
  34. if (g_hDcPrev) {
  35. uRet = ORIGINAL_API(ReleaseDC)(g_hWndPrev, g_hDcPrev);
  36. }
  37. g_hWndPrev = hWnd;
  38. g_hDcPrev = hdc;
  39. LeaveCriticalSection(&g_MakeThreadSafe);
  40. return uRet;
  41. }
  42. /*++
  43. Register hooked functions
  44. --*/
  45. BOOL
  46. NOTIFY_FUNCTION(
  47. DWORD fdwReason
  48. )
  49. {
  50. if (fdwReason == DLL_PROCESS_ATTACH) {
  51. g_hWndPrev = 0;
  52. g_hDcPrev = 0;
  53. InitializeCriticalSection(&g_MakeThreadSafe);
  54. }
  55. // Ignore Detach code
  56. /*
  57. else if (fdwReason == DLL_PROCESS_DETACH) {
  58. DeleteCriticalSection(&g_MakeThreadSafe);
  59. }
  60. */
  61. return TRUE;
  62. }
  63. HOOK_BEGIN
  64. CALL_NOTIFY_FUNCTION
  65. APIHOOK_ENTRY(USER32.DLL, ReleaseDC)
  66. HOOK_END
  67. IMPLEMENT_SHIM_END