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.

996 lines
28 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // res.c - resource functions
  24. ////
  25. #include "winlocal.h"
  26. #include <stdlib.h>
  27. #include "res.h"
  28. #include "list.h"
  29. #include "mem.h"
  30. #include "str.h"
  31. #include "strbuf.h"
  32. #include "trace.h"
  33. ////
  34. // private definitions
  35. ////
  36. // res control struct
  37. //
  38. typedef struct RES
  39. {
  40. DWORD dwVersion;
  41. HINSTANCE hInst;
  42. HTASK hTask;
  43. HLIST hListModules;
  44. HSTRBUF hStrBuf;
  45. int cBuf;
  46. int sizBuf;
  47. } RES, FAR *LPRES;
  48. // helper functions
  49. //
  50. static LPRES ResGetPtr(HRES hRes);
  51. static HRES ResGetHandle(LPRES lpRes);
  52. ////
  53. // public functions
  54. ////
  55. // ResInit - initialize resource engine
  56. // <dwVersion> (i) must be RES_VERSION
  57. // <hInst> (i) instance handle of calling module
  58. // return handle (NULL if error)
  59. //
  60. HRES DLLEXPORT WINAPI ResInit(DWORD dwVersion, HINSTANCE hInst)
  61. {
  62. BOOL fSuccess = TRUE;
  63. LPRES lpRes = NULL;
  64. if (dwVersion != RES_VERSION)
  65. fSuccess = TraceFALSE(NULL);
  66. else if (hInst == NULL)
  67. fSuccess = TraceFALSE(NULL);
  68. else if ((lpRes = (LPRES) MemAlloc(NULL, sizeof(RES), 0)) == NULL)
  69. fSuccess = TraceFALSE(NULL);
  70. else
  71. {
  72. lpRes->dwVersion = dwVersion;
  73. lpRes->hInst = hInst;
  74. lpRes->hTask = GetCurrentTask();
  75. lpRes->hListModules = NULL;
  76. lpRes->hStrBuf = NULL;
  77. lpRes->cBuf = 8;
  78. lpRes->sizBuf = 512;
  79. // create linked list to hold instance handles of resource modules
  80. //
  81. if ((lpRes->hListModules = ListCreate(LIST_VERSION, hInst)) == NULL)
  82. fSuccess = TraceFALSE(NULL);
  83. // calling module is always the first resource module in list
  84. //
  85. else if (ResAddModule(ResGetHandle(lpRes), hInst) != 0)
  86. fSuccess = TraceFALSE(NULL);
  87. // create string buffer array to be used by ResString
  88. //
  89. else if ((lpRes->hStrBuf = StrBufInit(STRBUF_VERSION, hInst,
  90. lpRes->cBuf, lpRes->sizBuf)) == NULL)
  91. fSuccess = TraceFALSE(NULL);
  92. }
  93. if (!fSuccess)
  94. {
  95. ResTerm(ResGetHandle(lpRes));
  96. lpRes = NULL;
  97. }
  98. return fSuccess ? ResGetHandle(lpRes) : NULL;
  99. }
  100. // ResTerm - shut down resource engine
  101. // <hRes> (i) handle returned from ResInit
  102. // return 0 if success
  103. //
  104. int DLLEXPORT WINAPI ResTerm(HRES hRes)
  105. {
  106. BOOL fSuccess = TRUE;
  107. LPRES lpRes;
  108. if ((lpRes = ResGetPtr(hRes)) == NULL)
  109. fSuccess = TraceFALSE(NULL);
  110. else
  111. {
  112. if (lpRes->hListModules != NULL)
  113. {
  114. if (ListDestroy(lpRes->hListModules) != 0)
  115. fSuccess = TraceFALSE(NULL);
  116. else
  117. lpRes->hStrBuf = NULL;
  118. }
  119. if (lpRes->hStrBuf != NULL)
  120. {
  121. if (StrBufTerm(lpRes->hStrBuf) != 0)
  122. fSuccess = TraceFALSE(NULL);
  123. else
  124. lpRes->hStrBuf = NULL;
  125. }
  126. if ((lpRes = MemFree(NULL, lpRes)) != NULL)
  127. fSuccess = TraceFALSE(NULL);
  128. }
  129. return fSuccess ? 0 : -1;
  130. }
  131. // ResAddModule - add module resources to res engine
  132. // <hRes> (i) handle returned from ResInit
  133. // <hInst> (i) instance handle of resource module
  134. // return 0 if success
  135. //
  136. int DLLEXPORT WINAPI ResAddModule(HRES hRes, HINSTANCE hInst)
  137. {
  138. BOOL fSuccess = TRUE;
  139. LPRES lpRes;
  140. if ((lpRes = ResGetPtr(hRes)) == NULL)
  141. fSuccess = TraceFALSE(NULL);
  142. else if (hInst == NULL)
  143. fSuccess = TraceFALSE(NULL);
  144. else if (ListAddHead(lpRes->hListModules, (LISTELEM) hInst) == NULL)
  145. fSuccess = TraceFALSE(NULL);
  146. return fSuccess ? 0 : -1;
  147. }
  148. // ResRemoveModule - remove module resources from res engine
  149. // <hRes> (i) handle returned from ResInit
  150. // <hInst> (i) instance handle of resource module
  151. // return 0 if success
  152. //
  153. int DLLEXPORT WINAPI ResRemoveModule(HRES hRes, HINSTANCE hInst)
  154. {
  155. BOOL fSuccess = TRUE;
  156. LPRES lpRes;
  157. HLISTNODE hNode;
  158. if ((lpRes = ResGetPtr(hRes)) == NULL)
  159. fSuccess = TraceFALSE(NULL);
  160. else if (hInst == NULL)
  161. fSuccess = TraceFALSE(NULL);
  162. else if ((hNode = ListFind(lpRes->hListModules, (LISTELEM) hInst, NULL)) == NULL)
  163. fSuccess = TraceFALSE(NULL);
  164. else if (ListRemoveAt(lpRes->hListModules, hNode) == NULL)
  165. fSuccess = TraceFALSE(NULL);
  166. return fSuccess ? 0 : -1;
  167. }
  168. // ResLoadAccelerators - load specified accelerator table
  169. // <hRes> (i) handle returned from ResInit
  170. // <lpszTableName> (i) name of accelerator table
  171. // or MAKEINTRESOURCE(idAccel)
  172. // return accel handle if success, otherwise NULL
  173. // NOTE: see documentation for LoadAccelerators function
  174. //
  175. HACCEL DLLEXPORT WINAPI ResLoadAccelerators(HRES hRes, LPCTSTR lpszTableName)
  176. {
  177. BOOL fSuccess = TRUE;
  178. LPRES lpRes;
  179. HLISTNODE hNode;
  180. HACCEL hAccel = NULL;
  181. if ((lpRes = ResGetPtr(hRes)) == NULL)
  182. fSuccess = TraceFALSE(NULL);
  183. // search each module for the specified resource
  184. //
  185. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  186. fSuccess && hNode != NULL;
  187. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  188. {
  189. HINSTANCE hInst;
  190. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  191. fSuccess = TraceFALSE(NULL);
  192. else if ((hAccel = LoadAccelerators(hInst, lpszTableName)) != NULL)
  193. break; // resource found
  194. }
  195. return fSuccess ? hAccel : NULL;
  196. }
  197. // ResLoadBitmap - load specified bitmap resource
  198. // <hRes> (i) handle returned from ResInit
  199. // NULL load pre-defined Windows bitmap
  200. // <lpszBitmap> (i) name of bitmap resource
  201. // or MAKEINTRESOURCE(idBitmap)
  202. // or <OBM_xxx> if hRes is NULL
  203. // return bitmap handle if success, otherwise NULL
  204. // NOTE: see documentation for LoadBitmap function
  205. //
  206. HBITMAP DLLEXPORT WINAPI ResLoadBitmap(HRES hRes, LPCTSTR lpszBitmap)
  207. {
  208. BOOL fSuccess = TRUE;
  209. LPRES lpRes;
  210. HLISTNODE hNode;
  211. HBITMAP hBitmap = NULL;
  212. if (hRes == NULL)
  213. {
  214. // special case to handle pre-defined Windows resources
  215. //
  216. if ((hBitmap = LoadBitmap(NULL, lpszBitmap)) == NULL)
  217. fSuccess = TraceFALSE(NULL);
  218. }
  219. else if ((lpRes = ResGetPtr(hRes)) == NULL)
  220. fSuccess = TraceFALSE(NULL);
  221. // search each module for the specified resource
  222. //
  223. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  224. fSuccess && hNode != NULL;
  225. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  226. {
  227. HINSTANCE hInst;
  228. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  229. fSuccess = TraceFALSE(NULL);
  230. else if ((hBitmap = LoadBitmap(hInst, lpszBitmap)) != NULL)
  231. break; // resource found
  232. }
  233. return fSuccess ? hBitmap : NULL;
  234. }
  235. // ResLoadCursor - load specified cursor resource
  236. // <hRes> (i) handle returned from ResInit
  237. // NULL load pre-defined Windows cursor
  238. // <lpszCursor> (i) name of cursor resource
  239. // or MAKEINTRESOURCE(idCursor)
  240. // or <IDC_xxx> if hRes is NULL
  241. // return cursor handle if success, otherwise NULL
  242. // NOTE: see documentation for LoadCursor function
  243. //
  244. HCURSOR DLLEXPORT WINAPI ResLoadCursor(HRES hRes, LPCTSTR lpszCursor)
  245. {
  246. BOOL fSuccess = TRUE;
  247. LPRES lpRes;
  248. HLISTNODE hNode;
  249. HCURSOR hCursor = NULL;
  250. if (hRes == NULL)
  251. {
  252. // special case to handle pre-defined Windows resources
  253. //
  254. if ((hCursor = LoadCursor(NULL, lpszCursor)) == NULL)
  255. fSuccess = TraceFALSE(NULL);
  256. }
  257. else if ((lpRes = ResGetPtr(hRes)) == NULL)
  258. fSuccess = TraceFALSE(NULL);
  259. // search each module for the specified resource
  260. //
  261. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  262. fSuccess && hNode != NULL;
  263. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  264. {
  265. HINSTANCE hInst;
  266. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  267. fSuccess = TraceFALSE(NULL);
  268. else if ((hCursor = LoadCursor(hInst, lpszCursor)) != NULL)
  269. break; // resource found
  270. }
  271. return fSuccess ? hCursor : NULL;
  272. }
  273. // ResLoadIcon - load specified icon resource
  274. // <hRes> (i) handle returned from ResInit
  275. // NULL load pre-defined Windows icon
  276. // <lpszIcon> (i) name of icon resource
  277. // or MAKEINTRESOURCE(idIcon)
  278. // or <IDI_xxx> if hRes is NULL
  279. // return icon handle if success, otherwise NULL
  280. // NOTE: see documentation for LoadIcon function
  281. //
  282. HICON DLLEXPORT WINAPI ResLoadIcon(HRES hRes, LPCTSTR lpszIcon)
  283. {
  284. BOOL fSuccess = TRUE;
  285. LPRES lpRes;
  286. HLISTNODE hNode;
  287. HICON hIcon = NULL;
  288. if (hRes == NULL)
  289. {
  290. // special case to handle pre-defined Windows resources
  291. //
  292. if ((hIcon = LoadIcon(NULL, lpszIcon)) == NULL)
  293. fSuccess = TraceFALSE(NULL);
  294. }
  295. else if ((lpRes = ResGetPtr(hRes)) == NULL)
  296. fSuccess = TraceFALSE(NULL);
  297. // search each module for the specified resource
  298. //
  299. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  300. fSuccess && hNode != NULL;
  301. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  302. {
  303. HINSTANCE hInst;
  304. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  305. fSuccess = TraceFALSE(NULL);
  306. else if ((hIcon = LoadIcon(hInst, lpszIcon)) != NULL)
  307. break; // resource found
  308. }
  309. return fSuccess ? hIcon : NULL;
  310. }
  311. // ResLoadMenu - load specified menu resource
  312. // <hRes> (i) handle returned from ResInit
  313. // <lpszMenu> (i) name of menu resource
  314. // or MAKEINTRESOURCE(idMenu)
  315. // return menu handle if success, otherwise NULL
  316. // NOTE: see documentation for LoadMenu function
  317. //
  318. HMENU DLLEXPORT WINAPI ResLoadMenu(HRES hRes, LPCTSTR lpszMenu)
  319. {
  320. BOOL fSuccess = TRUE;
  321. LPRES lpRes;
  322. HLISTNODE hNode;
  323. HMENU hMenu = NULL;
  324. if ((lpRes = ResGetPtr(hRes)) == NULL)
  325. fSuccess = TraceFALSE(NULL);
  326. // search each module for the specified resource
  327. //
  328. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  329. fSuccess && hNode != NULL;
  330. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  331. {
  332. HINSTANCE hInst;
  333. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  334. fSuccess = TraceFALSE(NULL);
  335. else if ((hMenu = LoadMenu(hInst, lpszMenu)) != NULL)
  336. break; // resource found
  337. }
  338. return fSuccess ? hMenu : NULL;
  339. }
  340. // ResFindResource - find specified resource
  341. // <hRes> (i) handle returned from ResInit
  342. // <lpszName> (i) resource name
  343. // or MAKEINTRESOURCE(idResource)
  344. // <lpszType> (i) resource type (RT_xxx)
  345. // return resource handle if success, otherwise NULL
  346. // NOTE: see documentation for FindResource function
  347. //
  348. HRSRC DLLEXPORT WINAPI ResFindResource(HRES hRes, LPCTSTR lpszName, LPCTSTR lpszType)
  349. {
  350. BOOL fSuccess = TRUE;
  351. LPRES lpRes;
  352. HLISTNODE hNode;
  353. HRSRC hrsrc = NULL;
  354. if ((lpRes = ResGetPtr(hRes)) == NULL)
  355. fSuccess = TraceFALSE(NULL);
  356. // search each module for the specified resource
  357. //
  358. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  359. fSuccess && hNode != NULL;
  360. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  361. {
  362. HINSTANCE hInst;
  363. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  364. fSuccess = TraceFALSE(NULL);
  365. else if ((hrsrc = FindResource(hInst, lpszName, lpszType)) != NULL)
  366. break; // resource found
  367. }
  368. return fSuccess ? hrsrc : NULL;
  369. }
  370. // ResLoadResource - load specified resource
  371. // <hRes> (i) handle returned from ResInit
  372. // <hrsrc> (i) handle returned from ResFindResource
  373. // return resource handle if success, otherwise NULL
  374. // NOTE: see documentation for LoadResource function
  375. //
  376. HGLOBAL DLLEXPORT WINAPI ResLoadResource(HRES hRes, HRSRC hrsrc)
  377. {
  378. BOOL fSuccess = TRUE;
  379. LPRES lpRes;
  380. HLISTNODE hNode;
  381. HGLOBAL hGlobal = NULL;
  382. if ((lpRes = ResGetPtr(hRes)) == NULL)
  383. fSuccess = TraceFALSE(NULL);
  384. // search each module for the specified resource
  385. //
  386. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  387. fSuccess && hNode != NULL;
  388. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  389. {
  390. HINSTANCE hInst;
  391. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  392. fSuccess = TraceFALSE(NULL);
  393. else if ((hGlobal = LoadResource(hInst, hrsrc)) != NULL)
  394. break; // resource found
  395. }
  396. return fSuccess ? hGlobal : NULL;
  397. }
  398. // ResLoadString - load specified string resource
  399. // <hRes> (i) handle returned from ResInit
  400. // <idResource> (i) string id
  401. // <lpszBuffer> (o) buffer to receive the string
  402. // <cbBuffer> (i) buffer size in bytes
  403. // return number of bytes copied to <lpszBuffer>, -1 if error, 0 if not found
  404. // NOTE: see documentation for LoadString function
  405. //
  406. int DLLEXPORT WINAPI ResLoadString(HRES hRes, UINT idResource, LPTSTR lpszBuffer, int cbBuffer)
  407. {
  408. BOOL fSuccess = TRUE;
  409. LPRES lpRes;
  410. HLISTNODE hNode;
  411. int nBytesCopied = 0;
  412. if ((lpRes = ResGetPtr(hRes)) == NULL)
  413. fSuccess = TraceFALSE(NULL);
  414. else if (lpszBuffer == NULL)
  415. fSuccess = TraceFALSE(NULL);
  416. else if (cbBuffer < 0)
  417. fSuccess = TraceFALSE(NULL);
  418. // search each module for the specified resource
  419. //
  420. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  421. fSuccess && hNode != NULL;
  422. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  423. {
  424. HINSTANCE hInst;
  425. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  426. fSuccess = TraceFALSE(NULL);
  427. else if ((nBytesCopied = LoadString(hInst, idResource, lpszBuffer, cbBuffer)) > 0)
  428. break; // resource found
  429. }
  430. return fSuccess ? nBytesCopied : -1;
  431. }
  432. // ResString - return specified string resource
  433. // <hRes> (i) handle returned from ResInit
  434. // <idResource> (i) string id
  435. // return ptr to string in next available string buffer (NULL if error)
  436. // NOTE: If the the specified id in <idResource> is not found,
  437. // a string in the form "String #<idResource>" is returned.
  438. //
  439. LPTSTR DLLEXPORT WINAPI ResString(HRES hRes, UINT idResource)
  440. {
  441. BOOL fSuccess = TRUE;
  442. LPRES lpRes;
  443. LPTSTR lpszBuf;
  444. if ((lpRes = ResGetPtr(hRes)) == NULL)
  445. fSuccess = TraceFALSE(NULL);
  446. else if ((lpszBuf = StrBufGetNext(lpRes->hStrBuf)) == NULL)
  447. fSuccess = TraceFALSE(NULL);
  448. else if (ResLoadString(hRes, idResource, lpszBuf, lpRes->sizBuf) <= 0)
  449. {
  450. // resource not found; construct a dummy string instead
  451. //
  452. wsprintf(lpszBuf, TEXT("String #%u"), idResource);
  453. }
  454. return fSuccess ? lpszBuf : NULL;
  455. }
  456. // ResCreateDialog - create modeless dialog box from template resource
  457. // <hRes> (i) handle returned from ResInit
  458. // <lpszDlgTemp> (i) dialog box template name
  459. // or MAKEINTRESOURCE(idDlg)
  460. // <hwndOwner> (i) handle of owner window
  461. // <dlgproc> (i) instance address of dialog box procedure
  462. // return dialog box window handle (NULL if error)
  463. // NOTE: see documentation for CreateDialog function
  464. //
  465. HWND DLLEXPORT WINAPI ResCreateDialog(HRES hRes,
  466. LPCTSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgproc)
  467. {
  468. BOOL fSuccess = TRUE;
  469. LPRES lpRes;
  470. HLISTNODE hNode;
  471. HWND hwndDlg = NULL;
  472. if ((lpRes = ResGetPtr(hRes)) == NULL)
  473. fSuccess = TraceFALSE(NULL);
  474. // search each module for the specified resource
  475. //
  476. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  477. fSuccess && hNode != NULL;
  478. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  479. {
  480. HINSTANCE hInst;
  481. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  482. fSuccess = TraceFALSE(NULL);
  483. else if ((hwndDlg = CreateDialog(hInst,
  484. lpszDlgTemp, hwndOwner, dlgproc)) != NULL)
  485. break; // resource found
  486. }
  487. return fSuccess ? hwndDlg : NULL;
  488. }
  489. // ResCreateDialogIndirect - create modeless dialog box from template resource
  490. // <hRes> (i) handle returned from ResInit
  491. // <lpvDlgTemp> (i) dialog box header structure
  492. // <hwndOwner> (i) handle of owner window
  493. // <dlgproc> (i) instance address of dialog box procedure
  494. // return dialog box window handle (NULL if error)
  495. // NOTE: see documentation for CreateDialogIndirect function
  496. //
  497. HWND DLLEXPORT WINAPI ResCreateDialogIndirect(HRES hRes,
  498. const void FAR* lpvDlgTemp, HWND hwndOwner, DLGPROC dlgproc)
  499. {
  500. BOOL fSuccess = TRUE;
  501. LPRES lpRes;
  502. HLISTNODE hNode;
  503. HWND hwndDlg = NULL;
  504. if ((lpRes = ResGetPtr(hRes)) == NULL)
  505. fSuccess = TraceFALSE(NULL);
  506. // search each module for the specified resource
  507. //
  508. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  509. fSuccess && hNode != NULL;
  510. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  511. {
  512. HINSTANCE hInst;
  513. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  514. fSuccess = TraceFALSE(NULL);
  515. else if ((hwndDlg = CreateDialogIndirect(hInst,
  516. lpvDlgTemp, hwndOwner, dlgproc)) != NULL)
  517. break; // resource found
  518. }
  519. return fSuccess ? hwndDlg : NULL;
  520. }
  521. // ResCreateDialogParam - create modeless dialog box from template resource
  522. // <hRes> (i) handle returned from ResInit
  523. // <lpszDlgTemp> (i) dialog box template name
  524. // or MAKEINTRESOURCE(idDlg)
  525. // <hwndOwner> (i) handle of owner window
  526. // <dlgproc> (i) instance address of dialog box procedure
  527. // <lParamInit> (i) initialization value
  528. // return dialog box window handle (NULL if error)
  529. // NOTE: see documentation for CreateDialogParam function
  530. //
  531. HWND DLLEXPORT WINAPI ResCreateDialogParam(HRES hRes,
  532. LPCTSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgproc, LPARAM lParamInit)
  533. {
  534. BOOL fSuccess = TRUE;
  535. LPRES lpRes;
  536. HLISTNODE hNode;
  537. HWND hwndDlg = NULL;
  538. if ((lpRes = ResGetPtr(hRes)) == NULL)
  539. fSuccess = TraceFALSE(NULL);
  540. // search each module for the specified resource
  541. //
  542. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  543. fSuccess && hNode != NULL;
  544. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  545. {
  546. HINSTANCE hInst;
  547. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  548. fSuccess = TraceFALSE(NULL);
  549. else if ((hwndDlg = CreateDialogParam(hInst,
  550. lpszDlgTemp, hwndOwner, dlgproc, lParamInit)) != NULL)
  551. break; // resource found
  552. }
  553. return fSuccess ? hwndDlg : NULL;
  554. }
  555. // ResCreateDialogIndirectParam - create modeless dialog box from template resource
  556. // <hRes> (i) handle returned from ResInit
  557. // <lpvDlgTemp> (i) dialog box header structure
  558. // <hwndOwner> (i) handle of owner window
  559. // <dlgproc> (i) instance address of dialog box procedure
  560. // <lParamInit> (i) initialization value
  561. // return dialog box window handle (NULL if error)
  562. // NOTE: see documentation for CreateDialogIndirectParam function
  563. //
  564. HWND DLLEXPORT WINAPI ResCreateDialogIndirectParam(HRES hRes,
  565. const void FAR* lpvDlgTemp, HWND hwndOwner, DLGPROC dlgproc, LPARAM lParamInit)
  566. {
  567. BOOL fSuccess = TRUE;
  568. LPRES lpRes;
  569. HLISTNODE hNode;
  570. HWND hwndDlg = NULL;
  571. if ((lpRes = ResGetPtr(hRes)) == NULL)
  572. fSuccess = TraceFALSE(NULL);
  573. // search each module for the specified resource
  574. //
  575. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  576. fSuccess && hNode != NULL;
  577. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  578. {
  579. HINSTANCE hInst;
  580. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  581. fSuccess = TraceFALSE(NULL);
  582. else if ((hwndDlg = CreateDialogIndirectParam(hInst,
  583. lpvDlgTemp, hwndOwner, dlgproc, lParamInit)) != NULL)
  584. break; // resource found
  585. }
  586. return fSuccess ? hwndDlg : NULL;
  587. }
  588. // ResDialogBox - create modal dialog box from template resource
  589. // <hRes> (i) handle returned from ResInit
  590. // <lpszDlgTemp> (i) dialog box template name
  591. // or MAKEINTRESOURCE(idDlg)
  592. // <hwndOwner> (i) handle of owner window
  593. // <dlgproc> (i) instance address of dialog box procedure
  594. // return dialog box return code (-1 if error)
  595. // NOTE: see documentation for DialogBox function
  596. //
  597. INT_PTR DLLEXPORT WINAPI ResDialogBox(HRES hRes,
  598. LPCTSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgproc)
  599. {
  600. BOOL fSuccess = TRUE;
  601. LPRES lpRes;
  602. HLISTNODE hNode;
  603. INT_PTR iRet = -1;
  604. if ((lpRes = ResGetPtr(hRes)) == NULL)
  605. fSuccess = TraceFALSE(NULL);
  606. // search each module for the specified resource
  607. //
  608. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  609. fSuccess && hNode != NULL;
  610. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  611. {
  612. HINSTANCE hInst;
  613. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  614. fSuccess = TraceFALSE(NULL);
  615. else if ((iRet = DialogBox(hInst,
  616. lpszDlgTemp, hwndOwner, dlgproc)) != -1)
  617. break; // resource found
  618. }
  619. return fSuccess ? iRet : -1;
  620. }
  621. // ResDialogBoxIndirect - create modal dialog box from template resource
  622. // <hRes> (i) handle returned from ResInit
  623. // <hglbDlgTemp> (i) dialog box header structure
  624. // <hwndOwner> (i) handle of owner window
  625. // <dlgproc> (i) instance address of dialog box procedure
  626. // return dialog box return code (-1 if error)
  627. // NOTE: see documentation for DialogBoxIndirect function
  628. //
  629. INT_PTR DLLEXPORT WINAPI ResDialogBoxIndirect(HRES hRes,
  630. HGLOBAL hglbDlgTemp, HWND hwndOwner, DLGPROC dlgproc)
  631. {
  632. BOOL fSuccess = TRUE;
  633. LPRES lpRes;
  634. HLISTNODE hNode;
  635. INT_PTR iRet = -1;
  636. if ((lpRes = ResGetPtr(hRes)) == NULL)
  637. fSuccess = TraceFALSE(NULL);
  638. // search each module for the specified resource
  639. //
  640. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  641. fSuccess && hNode != NULL;
  642. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  643. {
  644. HINSTANCE hInst;
  645. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  646. fSuccess = TraceFALSE(NULL);
  647. else if ((iRet = DialogBoxIndirect(hInst,
  648. hglbDlgTemp, hwndOwner, dlgproc)) != -1)
  649. break; // resource found
  650. }
  651. return fSuccess ? iRet : -1;
  652. }
  653. // ResDialogBoxParam - create modal dialog box from template resource
  654. // <hRes> (i) handle returned from ResInit
  655. // <lpszDlgTemp> (i) dialog box template name
  656. // or MAKEINTRESOURCE(idDlg)
  657. // <hwndOwner> (i) handle of owner window
  658. // <dlgproc> (i) instance address of dialog box procedure
  659. // <lParamInit> (i) initialization value
  660. // return dialog box return code (-1 if error)
  661. // NOTE: see documentation for DialogBoxParam function
  662. //
  663. INT_PTR DLLEXPORT WINAPI ResDialogBoxParam(HRES hRes,
  664. LPCTSTR lpszDlgTemp, HWND hwndOwner, DLGPROC dlgproc, LPARAM lParamInit)
  665. {
  666. BOOL fSuccess = TRUE;
  667. LPRES lpRes;
  668. HLISTNODE hNode;
  669. INT_PTR iRet = -1;
  670. if ((lpRes = ResGetPtr(hRes)) == NULL)
  671. fSuccess = TraceFALSE(NULL);
  672. // search each module for the specified resource
  673. //
  674. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  675. fSuccess && hNode != NULL;
  676. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  677. {
  678. HINSTANCE hInst;
  679. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  680. fSuccess = TraceFALSE(NULL);
  681. else if ((iRet = DialogBoxParam(hInst,
  682. lpszDlgTemp, hwndOwner, dlgproc, lParamInit)) != -1)
  683. break; // resource found
  684. }
  685. return fSuccess ? iRet : -1;
  686. }
  687. // ResDialogBoxIndirectParam - create modal dialog box from template resource
  688. // <hRes> (i) handle returned from ResInit
  689. // <hglbDlgTemp> (i) dialog box header structure
  690. // <hwndOwner> (i) handle of owner window
  691. // <dlgproc> (i) instance address of dialog box procedure
  692. // <lParamInit> (i) initialization value
  693. // return dialog box return code (-1 if error)
  694. // NOTE: see documentation for DialogBoxIndirectParam function
  695. //
  696. INT_PTR DLLEXPORT WINAPI ResDialogBoxIndirectParam(HRES hRes,
  697. HGLOBAL hglbDlgTemp, HWND hwndOwner, DLGPROC dlgproc, LPARAM lParamInit)
  698. {
  699. BOOL fSuccess = TRUE;
  700. LPRES lpRes;
  701. HLISTNODE hNode;
  702. INT_PTR iRet = -1;
  703. if ((lpRes = ResGetPtr(hRes)) == NULL)
  704. fSuccess = TraceFALSE(NULL);
  705. // search each module for the specified resource
  706. //
  707. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  708. fSuccess && hNode != NULL;
  709. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  710. {
  711. HINSTANCE hInst;
  712. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  713. fSuccess = TraceFALSE(NULL);
  714. else if ((iRet = DialogBoxIndirectParam(hInst,
  715. hglbDlgTemp, hwndOwner, dlgproc, lParamInit)) != -1)
  716. break; // resource found
  717. }
  718. return fSuccess ? iRet : -1;
  719. }
  720. // ResGetOpenFileName - display common dialog for selecting a file to open
  721. // <hRes> (i) handle returned from ResInit
  722. // <lpofn> (i/o) address of struct with initialization data
  723. // return non-zero if file chosen, 0 if error or no file chosen
  724. // NOTE: see documentation for GetOpenFileName function
  725. //
  726. BOOL DLLEXPORT WINAPI ResGetOpenFileName(HRES hRes, LPOPENFILENAME lpofn)
  727. {
  728. BOOL fSuccess = TRUE;
  729. BOOL fFound = FALSE;
  730. LPRES lpRes;
  731. HLISTNODE hNode;
  732. if ((lpRes = ResGetPtr(hRes)) == NULL)
  733. fSuccess = TraceFALSE(NULL);
  734. // search each module for the specified resource
  735. //
  736. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  737. fSuccess && hNode != NULL;
  738. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  739. {
  740. HINSTANCE hInst;
  741. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  742. fSuccess = TraceFALSE(NULL);
  743. else if (FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG) != NULL)
  744. {
  745. fFound = TRUE;
  746. lpofn->hInstance = hInst;
  747. if (!GetOpenFileName(lpofn))
  748. fSuccess = TraceFALSE(NULL);
  749. break;
  750. }
  751. }
  752. if (fSuccess && !fFound)
  753. fSuccess = TraceFALSE(NULL);
  754. return fSuccess;
  755. }
  756. // ResGetSaveFileName - display common dialog for selecting a file to save
  757. // <hRes> (i) handle returned from ResInit
  758. // <lpofn> (i/o) address of struct with initialization data
  759. // return non-zero if file chosen, 0 if error or no file chosen
  760. // NOTE: see documentation for GetSaveFileName function
  761. //
  762. BOOL DLLEXPORT WINAPI ResGetSaveFileName(HRES hRes, LPOPENFILENAME lpofn)
  763. {
  764. BOOL fSuccess = TRUE;
  765. BOOL fFound = FALSE;
  766. LPRES lpRes;
  767. HLISTNODE hNode;
  768. if ((lpRes = ResGetPtr(hRes)) == NULL)
  769. fSuccess = TraceFALSE(NULL);
  770. // search each module for the specified resource
  771. //
  772. else for (hNode = ListGetHeadNode(lpRes->hListModules);
  773. fSuccess && hNode != NULL;
  774. hNode = ListGetNextNode(lpRes->hListModules, hNode))
  775. {
  776. HINSTANCE hInst;
  777. if ((hInst = (HINSTANCE) ListGetAt(lpRes->hListModules, hNode)) == NULL)
  778. fSuccess = TraceFALSE(NULL);
  779. else if (FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG) != NULL)
  780. {
  781. fFound = TRUE;
  782. lpofn->hInstance = hInst;
  783. if (!GetSaveFileName(lpofn))
  784. fSuccess = TraceFALSE(NULL);
  785. break;
  786. }
  787. }
  788. if (fSuccess && !fFound)
  789. fSuccess = TraceFALSE(NULL);
  790. return fSuccess;
  791. }
  792. ////
  793. // helper functions
  794. ////
  795. // ResGetPtr - verify that res handle is valid,
  796. // <hRes> (i) handle returned from ResInit
  797. // return corresponding res pointer (NULL if error)
  798. //
  799. static LPRES ResGetPtr(HRES hRes)
  800. {
  801. BOOL fSuccess = TRUE;
  802. LPRES lpRes;
  803. if ((lpRes = (LPRES) hRes) == NULL)
  804. fSuccess = TraceFALSE(NULL);
  805. else if (IsBadWritePtr(lpRes, sizeof(RES)))
  806. fSuccess = TraceFALSE(NULL);
  807. #ifdef CHECKTASK
  808. // make sure current task owns the res handle
  809. //
  810. else if (lpRes->hTask != GetCurrentTask())
  811. fSuccess = TraceFALSE(NULL);
  812. #endif
  813. return fSuccess ? lpRes : NULL;
  814. }
  815. // ResGetHandle - verify that res pointer is valid,
  816. // <lpRes> (i) pointer to RES struct
  817. // return corresponding res handle (NULL if error)
  818. //
  819. static HRES ResGetHandle(LPRES lpRes)
  820. {
  821. BOOL fSuccess = TRUE;
  822. HRES hRes;
  823. if ((hRes = (HRES) lpRes) == NULL)
  824. fSuccess = TraceFALSE(NULL);
  825. return fSuccess ? hRes : NULL;
  826. }