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.

147 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ForceMessageBoxFocus.cpp
  5. Abstract:
  6. This APIHooks MessageBox and adds the MB_SETFOREGROUND style
  7. so as to force the messagebox to foreground.
  8. Notes:
  9. History:
  10. 01/15/2000 a-leelat Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(ForceMessageBoxFocus)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(MessageBoxA)
  17. APIHOOK_ENUM_ENTRY(MessageBoxW)
  18. APIHOOK_ENUM_ENTRY(MessageBoxExA)
  19. APIHOOK_ENUM_ENTRY(MessageBoxExW)
  20. APIHOOK_ENUM_END
  21. int
  22. APIHOOK(MessageBoxA)(
  23. HWND hWnd, // handle to owner window
  24. LPCSTR lpText, // text in message box
  25. LPCSTR lpCaption, // message box title
  26. UINT uType // message box style
  27. )
  28. {
  29. int iReturnValue;
  30. //Add the foreground style
  31. uType |= MB_SETFOREGROUND;
  32. iReturnValue = ORIGINAL_API(MessageBoxA)(
  33. hWnd,
  34. lpText,
  35. lpCaption,
  36. uType);
  37. return iReturnValue;
  38. }
  39. int
  40. APIHOOK(MessageBoxW)(
  41. HWND hWnd, // handle to owner window
  42. LPCWSTR lpText, // text in message box
  43. LPCWSTR lpCaption, // message box title
  44. UINT uType // message box style
  45. )
  46. {
  47. int iReturnValue;
  48. //Add the foreground style
  49. uType |= MB_SETFOREGROUND;
  50. iReturnValue = ORIGINAL_API(MessageBoxW)(
  51. hWnd,
  52. lpText,
  53. lpCaption,
  54. uType);
  55. return iReturnValue;
  56. }
  57. int
  58. APIHOOK(MessageBoxExA)(
  59. HWND hWnd, // handle to owner window
  60. LPCSTR lpText, // text in message box
  61. LPCSTR lpCaption, // message box title
  62. UINT uType, // message box style
  63. WORD wLanguageId // language identifier
  64. )
  65. {
  66. int iReturnValue;
  67. //Add the foreground style
  68. uType |= MB_SETFOREGROUND;
  69. iReturnValue = ORIGINAL_API(MessageBoxExA)(
  70. hWnd,
  71. lpText,
  72. lpCaption,
  73. uType,
  74. wLanguageId);
  75. return iReturnValue;
  76. }
  77. int
  78. APIHOOK(MessageBoxExW)(
  79. HWND hWnd, // handle to owner window
  80. LPCWSTR lpText, // text in message box
  81. LPCWSTR lpCaption, // message box title
  82. UINT uType, // message box style
  83. WORD wLanguageId // language identifier
  84. )
  85. {
  86. int iReturnValue;
  87. //Add the foreground style
  88. uType |= MB_SETFOREGROUND;
  89. iReturnValue = ORIGINAL_API(MessageBoxExW)(
  90. hWnd,
  91. lpText,
  92. lpCaption,
  93. uType,
  94. wLanguageId);
  95. return iReturnValue;
  96. }
  97. /*++
  98. Register hooked functions
  99. --*/
  100. HOOK_BEGIN
  101. APIHOOK_ENTRY(USER32.DLL, MessageBoxA)
  102. APIHOOK_ENTRY(USER32.DLL, MessageBoxW)
  103. APIHOOK_ENTRY(USER32.DLL, MessageBoxExA)
  104. APIHOOK_ENTRY(USER32.DLL, MessageBoxExW)
  105. HOOK_END
  106. IMPLEMENT_SHIM_END