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.

175 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. DinosaurActivityCenter.cpp
  5. Abstract:
  6. The app doesn't handle the WM_PAINT messages so when you drag the "Save As"
  7. dialog box, the main window doesn't redraw.
  8. We fix this by capturing the static image of the main window into a
  9. memory DC and blit from it when the WM_PAINT messages arrive (the
  10. image under the dialog doesn't change).
  11. Notes:
  12. This is an app specific shim.
  13. History:
  14. 09/21/2000 maonis Created
  15. 11/29/2000 andyseti Converted into AppSpecific shim.
  16. --*/
  17. #include "precomp.h"
  18. static HWND g_hwndOwner;
  19. static HDC g_hdcMemory;
  20. static RECT g_rect;
  21. IMPLEMENT_SHIM_BEGIN(DinosaurActivityCenter)
  22. #include "ShimHookMacro.h"
  23. APIHOOK_ENUM_BEGIN
  24. APIHOOK_ENUM_ENTRY(RegisterClassExA)
  25. APIHOOK_ENUM_ENTRY(GetSaveFileNameA)
  26. APIHOOK_ENUM_END
  27. BOOL
  28. APIHOOK(GetSaveFileNameA)(
  29. LPOPENFILENAMEA lpofn
  30. )
  31. {
  32. BOOL fRet;
  33. HDC hdcWindow = NULL;
  34. HBITMAP hbmMemory = NULL;
  35. HBITMAP hbmOld = NULL;
  36. HWND hwndOwner = lpofn->hwndOwner;
  37. DPFN( eDbgLevelInfo, "GetSaveFileNameA called with hwnd = 0x%x.", hwndOwner);
  38. if (hdcWindow = GetDC(hwndOwner))
  39. {
  40. if ((g_hdcMemory = CreateCompatibleDC(hdcWindow)) &&
  41. GetWindowRect(hwndOwner, &g_rect) &&
  42. (hbmMemory = CreateCompatibleBitmap(hdcWindow, g_rect.right, g_rect.bottom)) &&
  43. (hbmOld = (HBITMAP)SelectObject(g_hdcMemory, hbmMemory)) &&
  44. BitBlt(g_hdcMemory, 0, 0, g_rect.right, g_rect.bottom, hdcWindow, 0, 0, SRCCOPY))
  45. {
  46. g_hwndOwner = hwndOwner;
  47. }
  48. else
  49. {
  50. DPFN( eDbgLevelError, "GetSaveFileName(hwnd = 0x%x): Error creating bitmap", hwndOwner);
  51. }
  52. ReleaseDC(hwndOwner, hdcWindow);
  53. }
  54. fRet = ORIGINAL_API(GetSaveFileNameA)(lpofn);
  55. g_hwndOwner = NULL;
  56. if (g_hdcMemory)
  57. {
  58. if (hbmMemory)
  59. {
  60. if (hbmOld)
  61. {
  62. SelectObject(g_hdcMemory, hbmOld);
  63. }
  64. DeleteObject(hbmMemory);
  65. }
  66. DeleteDC(g_hdcMemory);
  67. }
  68. return fRet;
  69. }
  70. /*++
  71. Validate after paint and filter syskey messages.
  72. --*/
  73. LRESULT
  74. CALLBACK
  75. DinosaurActivityCenter_WindowProcHook(
  76. WNDPROC pfnOld,
  77. HWND hwnd,
  78. UINT uMsg,
  79. WPARAM wParam,
  80. LPARAM lParam
  81. )
  82. {
  83. if (hwnd == g_hwndOwner)
  84. {
  85. if (uMsg == WM_PAINT)
  86. {
  87. PAINTSTRUCT ps;
  88. HDC hdcWindow;
  89. if (hdcWindow = BeginPaint(hwnd, &ps))
  90. {
  91. BitBlt(hdcWindow, 0, 0, g_rect.right, g_rect.bottom, g_hdcMemory, 0, 0, SRCCOPY);
  92. EndPaint(hwnd, &ps);
  93. }
  94. LOGN( eDbgLevelError, "hwnd = 0x%x: Paint to the screen", hwnd);
  95. }
  96. }
  97. return (*pfnOld)(hwnd, uMsg, wParam, lParam);
  98. }
  99. /*++
  100. Hook the wndproc
  101. --*/
  102. ATOM
  103. APIHOOK(RegisterClassExA)(
  104. CONST WNDCLASSEXA *lpwcx
  105. )
  106. {
  107. CSTRING_TRY
  108. {
  109. CString csClassName(lpwcx->lpszClassName);
  110. if (csClassName.CompareNoCase(L"GAMEAPP") == 0)
  111. {
  112. WNDCLASSEXA wcNewWndClass = *lpwcx;
  113. wcNewWndClass.lpfnWndProc =
  114. (WNDPROC) HookCallback(lpwcx->lpfnWndProc, DinosaurActivityCenter_WindowProcHook);
  115. return ORIGINAL_API(RegisterClassExA)(&wcNewWndClass);
  116. }
  117. }
  118. CSTRING_CATCH
  119. {
  120. // Do Nothing
  121. }
  122. return ORIGINAL_API(RegisterClassExA)(lpwcx);
  123. }
  124. /*++
  125. Register hooked functions
  126. --*/
  127. HOOK_BEGIN
  128. APIHOOK_ENTRY(USER32.DLL, RegisterClassExA)
  129. APIHOOK_ENTRY(COMDLG32.DLL, GetSaveFileNameA)
  130. HOOK_END
  131. IMPLEMENT_SHIM_END