Source code of Windows XP (NT5)
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.

431 lines
11 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * FASTRES.C
  8. * WOW16 user resource services
  9. *
  10. * History:
  11. *
  12. * Created 12-Jan-1993 by Chandan Chuahan (ChandanC)
  13. *
  14. * This file provides the Win 3.1 routines for loading BITMAP, MENU, ICON,
  15. * CURSOR, and DIALOG resources. These routines load the resources from the
  16. * App EXE and then pass the pointers to the corresponding 32 bit WOW
  17. * thunks. Thus saving the call backs from USER client to find, load, lock,
  18. * size, unlock, and free the resources.
  19. *
  20. --*/
  21. #include "user.h"
  22. HBITMAP FAR PASCAL WOWLoadBitmap (HINSTANCE hInst, LPCSTR lpszBitmap, LPBYTE lpByte, DWORD ResSize);
  23. HMENU FAR PASCAL WOWLoadMenu (HINSTANCE hInst, LPCSTR lpszMenuName, LPBYTE lpByte, DWORD ResSize, WORD WinVer);
  24. HCURSOR FAR PASCAL WOWLoadCursorIcon (HINSTANCE hInst, LPCSTR lpszCursor, LPBYTE lpByte, DWORD ResSize, HGLOBAL hGbl, WORD WinVer, WORD wRttype);
  25. //
  26. // fDialogApi is TRUE for DialogBox* apis
  27. // fDialogApi is FALSE for CreateDialog* apis
  28. //
  29. HWND FAR PASCAL WOWDialogBoxParam (HINSTANCE hInst, LPBYTE lpByte,
  30. HWND hwndOwner, DLGPROC dlgprc, LPARAM lParamInit,
  31. DWORD ResSize, WORD fDialogApi);
  32. DWORD FAR PASCAL NotifyWOW (WORD Id, LPBYTE pData);
  33. #define LR_DEFAULTSIZE 0x0040 // from \nt\public\sdk\inc\winuser.h
  34. int FAR PASCAL LookupIconIdFromDirectoryEx(LPBYTE lpByte, BOOL fIcon,
  35. int cxDesired, int cyDesired,
  36. WORD wFlags);
  37. HANDLE FAR PASCAL WOWSetClipboardData (UINT, HANDLE);
  38. typedef struct _ICONCUR16 { /* iconcur */
  39. WORD hInst;
  40. DWORD lpStr;
  41. } ICONCUR16;
  42. /* These must match counterparts in mvdm\inc\wowusr.h */
  43. #define NW_LOADICON 1 // Internal
  44. #define NW_LOADCURSOR 2 // Internal
  45. HINSTANCE CheckDispHandle (HINSTANCE hInst)
  46. {
  47. HMODULE hIns;
  48. if (hInst) {
  49. hIns = GetModuleHandle ("DISPLAY");
  50. return ((hInst == (HINSTANCE) hIns) ? 0:hInst);
  51. }
  52. else {
  53. return (0);
  54. }
  55. }
  56. HBITMAP API ILoadBitmap (HINSTANCE hInst, LPCSTR lpszBitmap)
  57. {
  58. HRSRC hRsrc = 0;
  59. HGLOBAL hGbl = 0;
  60. DWORD ResSize = 0;
  61. LPBYTE lpByte = (LPBYTE) NULL;
  62. HBITMAP ul = (HBITMAP)0;
  63. if (hInst = CheckDispHandle (hInst)) {
  64. hRsrc = FindResource (hInst, lpszBitmap, RT_BITMAP);
  65. if (!hRsrc) {
  66. goto lbm_exit;
  67. }
  68. ResSize = SizeofResource (hInst, hRsrc);
  69. if (!ResSize) {
  70. goto lbm_exit;
  71. }
  72. hGbl = LoadResource (hInst, hRsrc);
  73. if (!hGbl) {
  74. goto lbm_exit;
  75. }
  76. lpByte = LockResource (hGbl);
  77. if (!lpByte) {
  78. goto lbm_exit;
  79. }
  80. }
  81. ul = (HBITMAP) WOWLoadBitmap (hInst, lpszBitmap, lpByte, ResSize);
  82. lbm_exit:
  83. if (lpByte) {
  84. GlobalUnlock (hGbl);
  85. }
  86. if (hGbl) {
  87. FreeResource(hGbl);
  88. }
  89. return (ul);
  90. }
  91. HMENU API ILoadMenu (HINSTANCE hInst, LPCSTR lpszMenuName)
  92. {
  93. HRSRC hRsrc;
  94. HGLOBAL hGbl;
  95. DWORD ResSize = 0;
  96. LPBYTE lpByte = (LPBYTE) NULL;
  97. HMENU ul;
  98. WORD WinVer;
  99. if (hRsrc = FindResource (hInst, lpszMenuName, RT_MENU)) {
  100. if (ResSize = SizeofResource (hInst, hRsrc))
  101. if (hGbl = LoadResource (hInst, hRsrc))
  102. if (lpByte = LockResource (hGbl))
  103. WinVer = GetExpWinVer (hInst);
  104. }
  105. if (!lpByte) {
  106. return (NULL);
  107. }
  108. ul = (HMENU) WOWLoadMenu (hInst, lpszMenuName, lpByte, ResSize, WinVer);
  109. if (hInst) {
  110. GlobalUnlock (hGbl);
  111. }
  112. return (ul);
  113. }
  114. HICON API ILoadIcon (HINSTANCE hInst, LPCSTR lpszIcon)
  115. {
  116. HRSRC hRsrc;
  117. HGLOBAL hGbl;
  118. DWORD ResSize = 0;
  119. LPBYTE lpByte = (LPBYTE) NULL;
  120. HICON ul;
  121. DWORD IconId;
  122. WORD WinVer;
  123. ICONCUR16 IconCur;
  124. WinVer = GetExpWinVer (hInst);
  125. if (!(hInst = CheckDispHandle (hInst))) {
  126. ul = WOWLoadCursorIcon (hInst, lpszIcon, lpByte, ResSize, NULL, WinVer, (WORD)RT_ICON);
  127. }
  128. else {
  129. IconCur.hInst = (WORD) hInst;
  130. IconCur.lpStr = (DWORD) lpszIcon;
  131. if (!(ul = (HICON) NotifyWOW (NW_LOADICON, (LPBYTE) &IconCur))) {
  132. if (WinVer >= VER30) {
  133. if (hRsrc = FindResource (hInst, lpszIcon, RT_GROUP_ICON)) {
  134. if (ResSize = SizeofResource (hInst, hRsrc))
  135. if (hGbl = LoadResource (hInst, hRsrc))
  136. lpByte = LockResource (hGbl);
  137. }
  138. if (!lpByte) {
  139. return (NULL);
  140. }
  141. IconId = LookupIconIdFromDirectoryEx(lpByte, TRUE, 0, 0, LR_DEFAULTSIZE);
  142. GlobalUnlock (hGbl);
  143. }
  144. else {
  145. IconId = (DWORD)lpszIcon;
  146. }
  147. if (hRsrc = FindResource (hInst, (LPCSTR) IconId, RT_ICON)) {
  148. if (ResSize = SizeofResource (hInst, hRsrc))
  149. if (hGbl = LoadResource (hInst, hRsrc))
  150. lpByte = LockResource (hGbl);
  151. }
  152. if (!lpByte) {
  153. return (NULL);
  154. }
  155. ul = WOWLoadCursorIcon (hInst, lpszIcon, lpByte, ResSize, hGbl, WinVer, (WORD)RT_ICON);
  156. GlobalUnlock (hGbl);
  157. }
  158. }
  159. return (ul);
  160. }
  161. HCURSOR API ILoadCursor (HINSTANCE hInst, LPCSTR lpszCursor)
  162. {
  163. HRSRC hRsrc;
  164. HGLOBAL hGbl;
  165. DWORD ResSize = 0;
  166. LPBYTE lpByte = (LPBYTE) NULL;
  167. HCURSOR ul;
  168. DWORD CursorId;
  169. WORD WinVer;
  170. ICONCUR16 IconCur;
  171. WinVer = GetExpWinVer (hInst);
  172. if (!(hInst = CheckDispHandle (hInst))) {
  173. ul = WOWLoadCursorIcon (hInst, lpszCursor, lpByte, ResSize, NULL, WinVer, (WORD)RT_CURSOR);
  174. }
  175. else {
  176. IconCur.hInst = (WORD) hInst;
  177. IconCur.lpStr = (DWORD) lpszCursor;
  178. if (!(ul = (HICON) NotifyWOW (NW_LOADCURSOR, (LPBYTE) &IconCur))) {
  179. if (WinVer >= VER30) {
  180. if (hRsrc = FindResource (hInst, lpszCursor, RT_GROUP_CURSOR)) {
  181. if (ResSize = SizeofResource (hInst, hRsrc))
  182. if (hGbl = LoadResource (hInst, hRsrc))
  183. lpByte = LockResource (hGbl);
  184. }
  185. if (!lpByte) {
  186. return (NULL);
  187. }
  188. CursorId = LookupIconIdFromDirectoryEx((LPBYTE)lpByte, FALSE, 0, 0, LR_DEFAULTSIZE);
  189. GlobalUnlock (hGbl);
  190. }
  191. else {
  192. CursorId = (DWORD)lpszCursor;
  193. }
  194. if (hRsrc = FindResource (hInst, (LPCSTR) CursorId, RT_CURSOR)) {
  195. if (ResSize = SizeofResource (hInst, hRsrc))
  196. if (hGbl = LoadResource (hInst, hRsrc))
  197. if (lpByte = LockResource (hGbl))
  198. WinVer = GetExpWinVer (hInst);
  199. }
  200. if (!lpByte) {
  201. return (NULL);
  202. }
  203. ul = WOWLoadCursorIcon (hInst, lpszCursor, lpByte, ResSize, hGbl, WinVer, (WORD)RT_CURSOR);
  204. GlobalUnlock (hGbl);
  205. }
  206. }
  207. return (ul);
  208. }
  209. HWND API ICreateDialogParam (HINSTANCE hInst, LPCSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgprc, LPARAM lParamInit)
  210. {
  211. HRSRC hRsrc;
  212. HGLOBAL hGbl;
  213. DWORD ResSize = 0;
  214. LPBYTE lpByte = (LPBYTE) NULL;
  215. HWND ul;
  216. if (hRsrc = FindResource (hInst, lpszDlgTemp, RT_DIALOG)) {
  217. if (ResSize = SizeofResource (hInst, hRsrc))
  218. if (hGbl = LoadResource (hInst, hRsrc))
  219. lpByte = LockResource (hGbl);
  220. }
  221. if (!lpByte) {
  222. return (NULL);
  223. }
  224. ul = (HWND) WOWDialogBoxParam (hInst, lpByte, hwndOwner,
  225. dlgprc, lParamInit, ResSize, FALSE);
  226. if (hInst) {
  227. GlobalUnlock (hGbl);
  228. }
  229. return (ul);
  230. }
  231. HWND API ICreateDialog (HINSTANCE hInst, LPCSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgprc)
  232. {
  233. return (ICreateDialogParam (hInst, lpszDlgTemp, hwndOwner, dlgprc, 0L));
  234. }
  235. HWND API ICreateDialogIndirectParam (HINSTANCE hInst, LPCSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgprc, LPARAM lParamInit)
  236. {
  237. return WOWDialogBoxParam (hInst, (LPBYTE)lpszDlgTemp, hwndOwner,
  238. dlgprc, lParamInit, 0, FALSE);
  239. }
  240. HWND API ICreateDialogIndirect (HINSTANCE hInst, LPCSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgprc)
  241. {
  242. return WOWDialogBoxParam (hInst, (LPBYTE)lpszDlgTemp, hwndOwner,
  243. dlgprc, 0, 0, FALSE);
  244. }
  245. int API IDialogBoxParam (HINSTANCE hInst, LPCSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgprc, LPARAM lParamInit)
  246. {
  247. HRSRC hRsrc;
  248. HGLOBAL hGbl;
  249. DWORD ResSize = 0;
  250. LPBYTE lpByte = (LPBYTE) NULL;
  251. int ul;
  252. if (hRsrc = FindResource (hInst, lpszDlgTemp, RT_DIALOG)) {
  253. if (ResSize = SizeofResource (hInst, hRsrc))
  254. if (hGbl = LoadResource (hInst, hRsrc))
  255. lpByte = LockResource (hGbl);
  256. }
  257. if (!lpByte) {
  258. return (-1);
  259. }
  260. ul = (int)WOWDialogBoxParam (hInst, lpByte, hwndOwner, dlgprc,
  261. lParamInit, ResSize, TRUE);
  262. if (hInst) {
  263. GlobalUnlock (hGbl);
  264. }
  265. return (ul);
  266. }
  267. int API IDialogBox (HINSTANCE hInst, LPCSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgprc)
  268. {
  269. return (IDialogBoxParam (hInst, lpszDlgTemp, hwndOwner, dlgprc, 0L));
  270. }
  271. int API IDialogBoxIndirectParam (HINSTANCE hInst, HGLOBAL hGbl, HWND hwndOwner, DLGPROC dlgprc, LPARAM lParamInit)
  272. {
  273. DWORD ResSize;
  274. LPBYTE lpByte;
  275. int ul;
  276. if (lpByte = LockResource (hGbl)) {
  277. ResSize = GlobalSize(hGbl);
  278. ul = (int)WOWDialogBoxParam (hInst, lpByte, hwndOwner, dlgprc,
  279. lParamInit, ResSize, TRUE);
  280. GlobalUnlock (hGbl);
  281. }
  282. else {
  283. ul = -1;
  284. }
  285. return (ul);
  286. }
  287. int API IDialogBoxIndirect(HINSTANCE hInst, HGLOBAL hGbl, HWND hwndOwner, DLGPROC dlgprc)
  288. {
  289. return IDialogBoxIndirectParam (hInst, hGbl, hwndOwner, dlgprc, 0);
  290. }
  291. HANDLE API SetClipboardData (UINT cbformat, HANDLE hMem)
  292. {
  293. HANDLE ul;
  294. LPMETAFILEPICT lpMf;
  295. switch (cbformat) {
  296. case CF_DSPMETAFILEPICT:
  297. case CF_METAFILEPICT:
  298. if (hMem) {
  299. lpMf = (LPMETAFILEPICT) GlobalLock(hMem);
  300. if (lpMf) {
  301. /* If the handle is bad make hMF = NULL. This is needed
  302. * for Micrograpfx. They don't check for failure when rendering
  303. * data
  304. */
  305. if (!(GlobalReAlloc (lpMf->hMF, 0L, GMEM_MODIFY | GMEM_SHARE))) {
  306. lpMf->hMF = NULL;
  307. }
  308. }
  309. GlobalUnlock(hMem);
  310. }
  311. // It is intentional to let it thru to the "case statements".
  312. // ChandanC 5/11/92.
  313. /*
  314. * These are the defaults.
  315. *
  316. * case CF_DIB:
  317. * case CF_TEXT:
  318. * case CF_DSPTEXT:
  319. * case CF_SYLK:
  320. * case CF_DIF:
  321. * case CF_TIFF:
  322. * case CF_OEMTEXT:
  323. * case CF_PENDATA:
  324. * case CF_RIFF:
  325. * case CF_WAVE:
  326. * case CF_OWNERDISPLAY:
  327. */
  328. default:
  329. if (hMem) {
  330. hMem = GlobalReAlloc (hMem, 0L, GMEM_MODIFY | GMEM_DDESHARE);
  331. }
  332. break;
  333. case CF_DSPBITMAP:
  334. case CF_BITMAP:
  335. case CF_PALETTE:
  336. break;
  337. }
  338. ul = WOWSetClipboardData (cbformat, hMem);
  339. return (ul);
  340. }