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.

206 lines
6.2 KiB

  1. /****************************************************************************
  2. USEREX.CPP
  3. Owner: cslim
  4. Copyright (c) 1997-2000 Microsoft Corporation
  5. Windows User API extension functions
  6. History:
  7. 01-JUN-2000 cslim Ported from IME code
  8. 19-JUL-1999 cslim Created
  9. *****************************************************************************/
  10. #include "private.h"
  11. #include <windowsx.h>
  12. #include "userex.h"
  13. #include "osver.h"
  14. inline Min(INT a, INT b)
  15. {
  16. return ((a)<(b)?(a):(b)) ;
  17. }
  18. /*---------------------------------------------------------------------------
  19. LoadStringExW
  20. Wrapper of LoadStringW() API.
  21. Load Unicode string with specified Language in any platform.
  22. ---------------------------------------------------------------------------*/
  23. INT WINAPI LoadStringExW(HINSTANCE hInst, UINT uID, LPWSTR lpBuffer, INT nBufferMax)
  24. {
  25. INT cchwstr = 0;
  26. UINT block, num;
  27. HRSRC hres;
  28. HGLOBAL hgbl;
  29. LPWSTR lpwstr;
  30. if (!hInst || !lpBuffer)
  31. return 0;
  32. block = (uID >>4)+1;
  33. num = uID & 0xf;
  34. hres = FindResourceEx(hInst,
  35. RT_STRING,
  36. MAKEINTRESOURCE(block),
  37. GetSystemDefaultLangID());
  38. if (hres == NULL)
  39. hres = FindResourceEx(hInst,
  40. RT_STRING,
  41. MAKEINTRESOURCE(block),
  42. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
  43. if (!hres)
  44. goto Error;
  45. if ((hgbl = LoadResource(hInst, hres)) == NULL)
  46. goto Error;
  47. if ((lpwstr = (LPWSTR)LockResource(hgbl)) == NULL)
  48. goto Error;
  49. for(UINT i = 0; i < num; i++)
  50. lpwstr += *lpwstr + 1;
  51. cchwstr = *lpwstr;
  52. CopyMemory(lpBuffer, lpwstr+1, Min(cchwstr, nBufferMax-1) * sizeof(WCHAR));
  53. Error:
  54. lpBuffer[Min(cchwstr, nBufferMax-1)]= (WCHAR)0x0000;
  55. return cchwstr;
  56. }
  57. /*---------------------------------------------------------------------------
  58. LoadStringExA
  59. Wrapper of LoadStringA() API.
  60. ---------------------------------------------------------------------------*/
  61. INT WINAPI LoadStringExA(HINSTANCE hInst, INT uID, LPSTR lpBuffer, INT nBufferMax)
  62. {
  63. INT cchstr;
  64. LPWSTR lpwstr;
  65. if (!hInst || !lpBuffer)
  66. return 0;
  67. if ((lpwstr = (LPWSTR)GlobalAllocPtr(GHND, nBufferMax*sizeof(WCHAR))) == NULL)
  68. return 0;
  69. // Call wide version
  70. LoadStringExW(hInst, uID, lpwstr, nBufferMax/2);
  71. // W to A
  72. cchstr = WideCharToMultiByte(CP_ACP,
  73. 0,
  74. lpwstr, -1,
  75. lpBuffer, nBufferMax,
  76. NULL, NULL);
  77. if (cchstr)
  78. cchstr--; // remove NULL char
  79. GlobalFreePtr(lpwstr);
  80. return cchstr;
  81. }
  82. /*---------------------------------------------------------------------------
  83. LoadMenuTemplateEx
  84. ---------------------------------------------------------------------------*/
  85. static MENUTEMPLATE* LoadMenuTemplateEx(LANGID lgid, HINSTANCE hInstance, LPCSTR pchTemplate)
  86. {
  87. HRSRC hResMenu;
  88. HANDLE hMenuTmpl;
  89. hResMenu = FindResourceEx(hInstance, RT_MENU, pchTemplate, lgid);
  90. if((hResMenu == NULL) && (lgid != MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  91. hResMenu = FindResourceEx(hInstance,
  92. RT_MENU,
  93. pchTemplate,
  94. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  95. if (hResMenu == NULL)
  96. return NULL;
  97. hMenuTmpl = LoadResource( hInstance, hResMenu );
  98. if(hMenuTmpl == NULL)
  99. return NULL;
  100. return (MENUTEMPLATE *)LockResource( hMenuTmpl );
  101. }
  102. /*---------------------------------------------------------------------------
  103. LoadMenuEx
  104. ---------------------------------------------------------------------------*/
  105. HMENU WINAPI LoadMenuEx(HINSTANCE hInstance, LPCSTR lpMenuName)
  106. {
  107. MENUTEMPLATE* pMenuTmpl;
  108. pMenuTmpl = LoadMenuTemplateEx(GetSystemDefaultLangID(), hInstance, lpMenuName);
  109. if (pMenuTmpl != NULL)
  110. return LoadMenuIndirect(pMenuTmpl);
  111. else
  112. return HMENU(0);
  113. }
  114. /*---------------------------------------------------------------------------
  115. LoadDialogTemplateEx
  116. ---------------------------------------------------------------------------*/
  117. DLGTEMPLATE* WINAPI LoadDialogTemplateEx(LANGID lgid, HINSTANCE hInstance, LPCSTR pchTemplate)
  118. {
  119. HRSRC hResDlg;
  120. HANDLE hDlgTmpl;
  121. hResDlg = FindResourceExA(hInstance, RT_DIALOG, pchTemplate, lgid);
  122. if ((hResDlg == NULL) && (lgid != MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  123. hResDlg = FindResourceExA(hInstance,
  124. RT_DIALOG,
  125. pchTemplate,
  126. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  127. if (hResDlg == NULL)
  128. return NULL;
  129. hDlgTmpl = LoadResource(hInstance, hResDlg);
  130. if(hDlgTmpl == NULL)
  131. return NULL;
  132. return (DLGTEMPLATE *)LockResource(hDlgTmpl);
  133. }
  134. /*---------------------------------------------------------------------------
  135. OurGetMessage
  136. ---------------------------------------------------------------------------*/
  137. BOOL WINAPI OurGetMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax)
  138. {
  139. if (IsOnNT())
  140. return ::GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
  141. else
  142. return ::GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
  143. }
  144. /*---------------------------------------------------------------------------
  145. IsWin64
  146. ---------------------------------------------------------------------------*/
  147. #if !defined(_WIN64)
  148. BOOL WINAPI IsWin64()
  149. {
  150. static BOOL fFristCallIsWin64 = fTrue;
  151. static BOOL fIsWin64 = fFalse;
  152. SYSTEM_INFO sys;
  153. if (fFristCallIsWin64 == fFalse)
  154. return fIsWin64;
  155. GetNativeSystemInfo(&sys);
  156. fIsWin64 = (sys.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
  157. ||(sys.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64);
  158. fFristCallIsWin64 = fFalse;
  159. return fIsWin64;
  160. }
  161. #endif