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.

126 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. CorelSiteBuilder.cpp
  5. Abstract:
  6. App repeatedly calls SetWindowTextA with the same title causing
  7. flickering. This repros on some machines and not others: we don't know why.
  8. Notes:
  9. This is an app specific shim.
  10. History:
  11. 01/31/2001 linstev Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(CorelSiteBuilder)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(SetWindowTextA)
  18. APIHOOK_ENUM_END
  19. HWND g_hLast = NULL;
  20. CString * g_csLastWindowText = NULL;
  21. CRITICAL_SECTION g_csGlobals;
  22. /*++
  23. Only send the message if the text has changed.
  24. --*/
  25. BOOL
  26. APIHOOK(SetWindowTextA)(
  27. HWND hWnd,
  28. LPCSTR lpString
  29. )
  30. {
  31. EnterCriticalSection(&g_csGlobals);
  32. if (lpString)
  33. {
  34. CSTRING_TRY
  35. {
  36. CString csString(lpString);
  37. if ((g_hLast == hWnd) && g_csLastWindowText->Compare(csString) == 0) {
  38. //
  39. // We have the same window and title, don't bother setting it again
  40. //
  41. LeaveCriticalSection(&g_csGlobals);
  42. return TRUE;
  43. }
  44. //
  45. // Store the current settings as the last known values
  46. //
  47. g_hLast = hWnd;
  48. *g_csLastWindowText = csString;
  49. }
  50. CSTRING_CATCH
  51. {
  52. // Do nothing
  53. }
  54. }
  55. LeaveCriticalSection(&g_csGlobals);
  56. return ORIGINAL_API(SetWindowTextA)(hWnd, lpString);
  57. }
  58. /*++
  59. Register hooked functions
  60. --*/
  61. BOOL
  62. NOTIFY_FUNCTION(
  63. DWORD fdwReason)
  64. {
  65. if (fdwReason == DLL_PROCESS_ATTACH) {
  66. CSTRING_TRY
  67. {
  68. if (!InitializeCriticalSectionAndSpinCount(&g_csGlobals, 0x80000000))
  69. {
  70. return FALSE;
  71. }
  72. g_csLastWindowText = new CString;
  73. if (g_csLastWindowText == NULL)
  74. {
  75. return FALSE;
  76. }
  77. }
  78. CSTRING_CATCH
  79. {
  80. return FALSE;
  81. }
  82. }
  83. return TRUE;
  84. }
  85. HOOK_BEGIN
  86. CALL_NOTIFY_FUNCTION
  87. APIHOOK_ENTRY(USER32.DLL, SetWindowTextA)
  88. HOOK_END
  89. IMPLEMENT_SHIM_END