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.

221 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. WPS2000.cpp
  5. Abstract:
  6. This in in fact NT user bug, see whistler bug 359407's attached mail for
  7. detail. The problem is NT user's MSGFILTER hook is not dbcs-enabled, the dbcs
  8. char code sent to ANSI edit control actually got reverted, 2nd byte first
  9. followed by first byte. The code path seems only hit when edit control is
  10. ANSI window and used in OLE server.
  11. Notes:
  12. This is an app specific shim.
  13. History:
  14. 06/02/2001 xiaoz Created
  15. --*/
  16. #include "precomp.h"
  17. IMPLEMENT_SHIM_BEGIN(WPS2000)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(CreateDialogIndirectParamA)
  21. APIHOOK_ENUM_END
  22. //
  23. // Global windowproc for subclassed Edit Control
  24. //
  25. WNDPROC g_lpWndProc = NULL;
  26. //
  27. // CONSTANT for how we were being launched
  28. //
  29. #define EMBEDDIND_STATUS_UNKOWN 0 // We have not checked whether how we were launched
  30. #define EMBEDDIND_STATUS_YES 1 // We were launched as an OLE object
  31. #define EMBEDDIND_STATUS_NO 2 // We were launched as stand-alone exe file
  32. //
  33. // Global variable to keep our status
  34. //
  35. UINT g_nEmbeddingObject =EMBEDDIND_STATUS_UNKOWN;
  36. /*++
  37. The subclassed edit windowproc that we use to exchange the 1st byte and 2nd byte
  38. of a DBCS char
  39. --*/
  40. LRESULT
  41. CALLBACK
  42. WindowProcA(
  43. HWND hWnd,
  44. UINT uMsg,
  45. WPARAM wParam,
  46. LPARAM lParam
  47. )
  48. {
  49. BYTE bHi,bLo;
  50. //
  51. // If it' not a WM_IME_CHAR message, ignore it
  52. //
  53. if (uMsg == WM_IME_CHAR)
  54. {
  55. //
  56. // Exchange the 1st byte with 2nd byte
  57. //
  58. bHi = HIBYTE(wParam);
  59. bLo = LOBYTE(wParam);
  60. wParam = bLo*256 + bHi;
  61. }
  62. return CallWindowProcA(g_lpWndProc, hWnd, uMsg, wParam, lParam);
  63. }
  64. /*++
  65. Enumerate the control on the dlg and if is editbox, subclass it.
  66. --*/
  67. BOOL
  68. CALLBACK
  69. EnumChildProc(
  70. HWND hwnd,
  71. LPARAM lParam
  72. )
  73. {
  74. CString cstrEdit(L"Edit");
  75. WCHAR szClassName[MAX_PATH];
  76. WNDPROC lpWndProc;
  77. GetClassName(hwnd, szClassName, MAX_PATH);
  78. //
  79. // Only care Edit Control
  80. //
  81. if (!cstrEdit.CompareNoCase(szClassName))
  82. {
  83. //
  84. // There are 3 Edit Control on thsi speficic dlg,all standard one
  85. // having same WinProc Address
  86. //
  87. lpWndProc = (WNDPROC) GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
  88. if (lpWndProc)
  89. {
  90. g_lpWndProc = lpWndProc;
  91. SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)WindowProcA);
  92. LOGN(eDbgLevelWarning, "Edit Control Sub-Classed");
  93. }
  94. }
  95. return TRUE;
  96. }
  97. /*++
  98. Check commandline for a sub-string "-Embedding".
  99. --*/
  100. UINT GetAppLaunchMethod()
  101. {
  102. WCHAR *pwstrCmdLine;
  103. //
  104. // If we have not check this, then do it
  105. //
  106. if (g_nEmbeddingObject == EMBEDDIND_STATUS_UNKOWN)
  107. {
  108. CString cStrCmdLineRightPart;
  109. CString cStrCmdLine = GetCommandLine();
  110. CString cstrEmbeded(L"-Embedding");
  111. cStrCmdLineRightPart = cStrCmdLine.Right(cstrEmbeded.GetLength());
  112. if (cStrCmdLineRightPart.CompareNoCase(cstrEmbeded))
  113. {
  114. g_nEmbeddingObject = EMBEDDIND_STATUS_NO;
  115. }
  116. else
  117. {
  118. g_nEmbeddingObject = EMBEDDIND_STATUS_YES;
  119. }
  120. }
  121. return (g_nEmbeddingObject);
  122. }
  123. /*++
  124. Hook CreateDialogIndirectParamA to find this specific dlg and subclass
  125. edit control on it
  126. --*/
  127. HWND
  128. APIHOOK(CreateDialogIndirectParamA)(
  129. HINSTANCE hInstance,
  130. LPCDLGTEMPLATE lpTemplate,
  131. HWND hWndParent,
  132. DLGPROC lpDialogFunc,
  133. LPARAM lParamInit
  134. )
  135. {
  136. HWND hDlg;
  137. WCHAR wszCaption[MAX_PATH];
  138. WCHAR wszTitle[] = { (WCHAR)0x6587, (WCHAR)0x672c, (WCHAR)0x8f93, (WCHAR)0x5165, (WCHAR)0x0000 };
  139. CString cstrCaption;
  140. hDlg = ORIGINAL_API(CreateDialogIndirectParamA)(hInstance, lpTemplate,
  141. hWndParent, lpDialogFunc, lParamInit);
  142. //
  143. // If dlg can not be created or not launched as OLE server, ignore it
  144. //
  145. if (!hDlg || (EMBEDDIND_STATUS_YES != GetAppLaunchMethod()))
  146. {
  147. goto End;
  148. }
  149. //
  150. // Try to get caption and see if that's the dlg we are interested
  151. //
  152. if (!GetWindowText(hDlg, wszCaption, MAX_PATH))
  153. {
  154. goto End;
  155. }
  156. cstrCaption = wszCaption;
  157. if (!cstrCaption.CompareNoCase(wszTitle))
  158. {
  159. EnumChildWindows(hDlg, EnumChildProc, NULL);
  160. }
  161. End:
  162. return hDlg;
  163. }
  164. /*++
  165. Register hooked functions
  166. --*/
  167. HOOK_BEGIN
  168. APIHOOK_ENTRY(USER32.DLL, CreateDialogIndirectParamA)
  169. HOOK_END
  170. IMPLEMENT_SHIM_END