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.

787 lines
22 KiB

  1. /*++
  2. * File name:
  3. *
  4. * Contents:
  5. * Clipboard functions
  6. *
  7. * Copyright (C) 1998-1999 Microsoft Corp.
  8. --*/
  9. #include <windows.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <io.h>
  13. #include <fcntl.h>
  14. #include <sys/stat.h>
  15. #ifdef _CLPUTIL
  16. enum {ERROR_MESSAGE = 0, WARNING_MESSAGE, INFO_MESSAGE, ALIVE_MESSAGE};
  17. #define TRACE(_x_) LocalPrintMessage _x_
  18. #else // !_CLPUTIL
  19. #include "protocol.h"
  20. /*
  21. * Externals
  22. */
  23. extern void (__cdecl *g_pfnPrintMessage) (INT, LPCSTR, ...);
  24. #define TRACE(_x_) if (g_pfnPrintMessage) {\
  25. g_pfnPrintMessage(INFO_MESSAGE, "Worker:%d ", GetCurrentThreadId());\
  26. g_pfnPrintMessage _x_; }
  27. #endif // !_CLPUTIL
  28. typedef struct _CLIPBOARDFORMATS {
  29. UINT uiFormat;
  30. LPCSTR szFormat;
  31. } CLIPBOARDFORMATS, *PCLIPBOARDFORMATS;
  32. const CLIPBOARDFORMATS KnownFormats[] =
  33. {
  34. {CF_TEXT, "Text"},
  35. {CF_BITMAP, "Bitmap"},
  36. {CF_METAFILEPICT, "MetaFile"},
  37. {CF_SYLK, "Sylk"},
  38. {CF_DIF, "DIF"},
  39. {CF_TIFF, "TIFF"},
  40. {CF_OEMTEXT, "OEMText"},
  41. {CF_DIB, "DIB"},
  42. {CF_PALETTE, "Palette"},
  43. {CF_PENDATA, "PenData"},
  44. {CF_RIFF, "Riff"},
  45. {CF_WAVE, "Wave"},
  46. {CF_UNICODETEXT,"Unicode"},
  47. {CF_ENHMETAFILE,"ENHMetafile"},
  48. {CF_HDROP, "HDROP"},
  49. {CF_LOCALE, "Locale"},
  50. {CF_DIBV5, "DIBV5"}
  51. };
  52. typedef struct {
  53. UINT32 mm;
  54. UINT32 xExt;
  55. UINT32 yExt;
  56. } CLIPBOARD_MFPICT, *PCLIPBOARD_MFPICT;
  57. /*
  58. * Clipboard functions definitions
  59. */
  60. VOID
  61. Clp_ListAllFormats(VOID);
  62. //VOID
  63. //Clp_ListAllAvailableFormats(VOID);
  64. UINT
  65. Clp_GetClipboardFormat(CHAR *szFormatLookup);
  66. VOID
  67. Clp_PutIntoClipboard(CHAR *g_szFileName);
  68. VOID
  69. Clp_GetClipboardData(
  70. UINT format,
  71. HGLOBAL hClipData,
  72. INT *pnClipDataSize,
  73. HGLOBAL *phNewData);
  74. BOOL
  75. Clp_SetClipboardData(
  76. UINT formatID,
  77. HGLOBAL hClipData,
  78. INT nClipDataSize,
  79. BOOL *pbFreeHandle);
  80. HGLOBAL
  81. Clp_GetMFData(HANDLE hData,
  82. PUINT pDataLen);
  83. HGLOBAL
  84. Clp_SetMFData(UINT dataLen,
  85. PVOID pData);
  86. VOID
  87. _cdecl LocalPrintMessage(INT errlevel, CHAR *format, ...);
  88. VOID
  89. Clp_ListAllFormats(VOID)
  90. {
  91. UINT format = 0;
  92. CHAR szFormatName[_MAX_PATH];
  93. while ((format = EnumClipboardFormats(format)))
  94. {
  95. *szFormatName = 0;
  96. GetClipboardFormatName(format, szFormatName, _MAX_PATH);
  97. if (!(*szFormatName))
  98. // No format, check for known format
  99. {
  100. INT fmti, fmtnum;
  101. fmtnum = sizeof(KnownFormats)/sizeof(KnownFormats[0]);
  102. for (fmti = 0;
  103. KnownFormats[fmti].uiFormat != format
  104. &&
  105. fmti < fmtnum;
  106. fmti ++);
  107. if (fmti < fmtnum)
  108. strcpy(szFormatName, KnownFormats[fmti].szFormat);
  109. }
  110. if (*szFormatName)
  111. {
  112. TRACE((INFO_MESSAGE, "%s[%d(0x%X)]\n", szFormatName, format, format));
  113. } else {
  114. TRACE((ERROR_MESSAGE, "Can't find format name for: 0x%x\n", format));
  115. }
  116. }
  117. }
  118. /*
  119. VOID
  120. Clp_ListAllAvailableFormats(VOID)
  121. {
  122. UINT format = 0;
  123. CHAR szFormatName[_MAX_PATH];
  124. while ((format = EnumClipboardFormats(format)))
  125. {
  126. if (!IsClipboardFormatAvailable(format))
  127. // Skip the unavalable formats
  128. continue;
  129. *szFormatName = 0;
  130. GetClipboardFormatName(format, szFormatName, _MAX_PATH);
  131. if (!(*szFormatName))
  132. // No format, check for known format
  133. {
  134. INT fmti, fmtnum;
  135. fmtnum = sizeof(KnownFormats)/sizeof(KnownFormats[0]);
  136. for (fmti = 0;
  137. KnownFormats[fmti].uiFormat != format
  138. &&
  139. fmti < fmtnum;
  140. fmti ++);
  141. if (fmti < fmtnum)
  142. strcpy(szFormatName, KnownFormats[fmti].szFormat);
  143. }
  144. if (*szFormatName)
  145. TRACE((INFO_MESSAGE, "%s\n", szFormatName));
  146. else
  147. TRACE((ERROR_MESSAGE, "Can't find format name for: 0x%x\n", format));
  148. }
  149. }
  150. */
  151. UINT
  152. Clp_GetClipboardFormat(CHAR *szFormatLookup)
  153. // Returns the clipboard ID
  154. {
  155. UINT format = 0;
  156. CHAR szFormatName[_MAX_PATH];
  157. BOOL bFound = FALSE;
  158. *szFormatName = 0;
  159. while (!bFound && (format = EnumClipboardFormats(format)))
  160. {
  161. if (!IsClipboardFormatAvailable(format))
  162. // Skip the unavalable formats
  163. continue;
  164. *szFormatName = 0;
  165. GetClipboardFormatName(format, szFormatName, _MAX_PATH);
  166. if (!(*szFormatName))
  167. // No format, check for known format
  168. {
  169. INT fmti, fmtnum;
  170. fmtnum = sizeof(KnownFormats)/sizeof(KnownFormats[0]);
  171. for (fmti = 0;
  172. KnownFormats[fmti].uiFormat != format
  173. &&
  174. fmti < fmtnum;
  175. fmti ++);
  176. if (fmti < fmtnum)
  177. strcpy(szFormatName, KnownFormats[fmti].szFormat);
  178. }
  179. bFound = (_stricmp(szFormatName, szFormatLookup) == 0);
  180. }
  181. return format;
  182. }
  183. VOID
  184. Clp_PutIntoClipboard(CHAR *szFileName)
  185. {
  186. INT hFile = -1;
  187. LONG clplength = 0;
  188. UINT uiFormat = 0;
  189. HGLOBAL ghClipData = NULL;
  190. PBYTE pClipData = NULL;
  191. BOOL bClipboardOpen = FALSE;
  192. BOOL bFreeClipHandle = TRUE;
  193. hFile = _open(szFileName, _O_RDONLY|_O_BINARY);
  194. if (hFile == -1)
  195. {
  196. TRACE((ERROR_MESSAGE, "Error opening file: %s. errno=%d\n", szFileName, errno));
  197. goto exitpt;
  198. }
  199. clplength = _filelength(hFile) - sizeof(uiFormat);
  200. if (_read(hFile, &uiFormat, sizeof(uiFormat)) != sizeof(uiFormat))
  201. {
  202. TRACE((ERROR_MESSAGE, "Error reading from file. errno=%d\n", errno));
  203. goto exitpt;
  204. }
  205. ghClipData = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, clplength);
  206. if (!ghClipData)
  207. {
  208. TRACE((ERROR_MESSAGE, "Can't allocate %d bytes\n", clplength));
  209. goto exitpt;
  210. }
  211. pClipData = GlobalLock(ghClipData);
  212. if (!pClipData)
  213. {
  214. TRACE((ERROR_MESSAGE, "Can't lock handle 0x%x\n", ghClipData));
  215. goto exitpt;
  216. }
  217. if (_read(hFile, pClipData, clplength) != clplength)
  218. {
  219. TRACE((ERROR_MESSAGE, "Error reading from file. errno=%d\n", errno));
  220. goto exitpt;
  221. }
  222. GlobalUnlock(ghClipData);
  223. if (!OpenClipboard(NULL))
  224. {
  225. TRACE((ERROR_MESSAGE, "Can't open the clipboard. GetLastError=%d\n",
  226. GetLastError()));
  227. goto exitpt;
  228. }
  229. bClipboardOpen = TRUE;
  230. // Empty the clipboard, so we'll have only one entry
  231. EmptyClipboard();
  232. if (!Clp_SetClipboardData(uiFormat, ghClipData, clplength, &bFreeClipHandle))
  233. {
  234. TRACE((ERROR_MESSAGE, "SetClipboardData failed.\n"));
  235. } else {
  236. TRACE((INFO_MESSAGE, "Clipboard is loaded successfuly. File: %s, %d bytes\n",
  237. szFileName,
  238. clplength));
  239. }
  240. exitpt:
  241. // Do the cleanup
  242. // Close the clipboard
  243. if (bClipboardOpen)
  244. CloseClipboard();
  245. // Release the clipboard handle
  246. if (pClipData)
  247. GlobalUnlock(ghClipData);
  248. if (ghClipData && bFreeClipHandle)
  249. GlobalFree(ghClipData);
  250. // Close the file
  251. if (hFile != -1)
  252. _close(hFile);
  253. }
  254. VOID
  255. Clp_GetClipboardData(
  256. UINT format,
  257. HGLOBAL hClipData,
  258. INT *pnClipDataSize,
  259. HGLOBAL *phNewData)
  260. {
  261. HGLOBAL hData = hClipData;
  262. DWORD dataLen = 0;
  263. WORD numEntries;
  264. DWORD dwEntries;
  265. PVOID pData;
  266. *phNewData = NULL;
  267. *pnClipDataSize = 0;
  268. if (format == CF_PALETTE)
  269. {
  270. /****************************************************************/
  271. /* Find out how many entries there are in the palette and */
  272. /* allocate enough memory to hold them all. */
  273. /****************************************************************/
  274. if (GetObject(hData, sizeof(numEntries), (LPSTR)&numEntries) == 0)
  275. {
  276. numEntries = 256;
  277. }
  278. dataLen = sizeof(LOGPALETTE) +
  279. ((numEntries - 1) * sizeof(PALETTEENTRY));
  280. *phNewData = GlobalAlloc(GHND, dataLen);
  281. if (*phNewData == 0)
  282. {
  283. TRACE((ERROR_MESSAGE, "Failed to get %d bytes for palette", dataLen));
  284. goto exitpt;
  285. }
  286. else
  287. {
  288. /************************************************************/
  289. /* now get the palette entries into the new buffer */
  290. /************************************************************/
  291. pData = GlobalLock(*phNewData);
  292. dwEntries = (WORD)GetPaletteEntries((HPALETTE)hData,
  293. 0,
  294. numEntries,
  295. (PALETTEENTRY*)pData);
  296. GlobalUnlock(*phNewData);
  297. if (dwEntries == 0)
  298. {
  299. TRACE((ERROR_MESSAGE, "Failed to get any palette entries"));
  300. goto exitpt;
  301. }
  302. dataLen = dwEntries * sizeof(PALETTEENTRY);
  303. }
  304. } else if (format == CF_METAFILEPICT)
  305. {
  306. *phNewData = Clp_GetMFData(hData, &dataLen);
  307. if (!*phNewData)
  308. {
  309. TRACE((ERROR_MESSAGE, "Failed to set MF data"));
  310. goto exitpt;
  311. }
  312. } else {
  313. if (format == CF_DIB)
  314. {
  315. // Get the exact DIB size
  316. BITMAPINFOHEADER *pBMI = GlobalLock(hData);
  317. if (pBMI)
  318. {
  319. if (pBMI->biSizeImage)
  320. dataLen = pBMI->biSize + pBMI->biSizeImage;
  321. GlobalUnlock(hData);
  322. }
  323. }
  324. /****************************************************************/
  325. /* just get the length of the block */
  326. /****************************************************************/
  327. if (!dataLen)
  328. dataLen = (DWORD)GlobalSize(hData);
  329. }
  330. *pnClipDataSize = dataLen;
  331. exitpt:
  332. ;
  333. }
  334. BOOL
  335. Clp_SetClipboardData(
  336. UINT formatID,
  337. HGLOBAL hClipData,
  338. INT nClipDataSize,
  339. BOOL *pbFreeHandle)
  340. {
  341. BOOL rv = FALSE;
  342. PVOID pData = NULL;
  343. HGLOBAL hData = NULL;
  344. LOGPALETTE *pLogPalette = NULL;
  345. UINT numEntries, memLen;
  346. if (!pbFreeHandle)
  347. goto exitpt;
  348. *pbFreeHandle = TRUE;
  349. if (formatID == CF_METAFILEPICT)
  350. {
  351. /********************************************************************/
  352. /* We have to put a handle to the metafile on the clipboard - which */
  353. /* means creating a metafile from the received data first */
  354. /********************************************************************/
  355. pData = GlobalLock(hClipData);
  356. if (!pData)
  357. {
  358. TRACE((ERROR_MESSAGE, "Failed to lock buffer\n"));
  359. goto exitpt;
  360. }
  361. hData = Clp_SetMFData(nClipDataSize, pData);
  362. if (!hData)
  363. {
  364. TRACE((ERROR_MESSAGE, "Failed to set MF data\n"));
  365. }
  366. else if (SetClipboardData(formatID, hData) != hData)
  367. {
  368. TRACE((ERROR_MESSAGE, "SetClipboardData. GetLastError=%d\n", GetLastError()));
  369. }
  370. GlobalUnlock(hClipData);
  371. } else if (formatID == CF_PALETTE)
  372. {
  373. /********************************************************************/
  374. /* We have to put a handle to the palette on the clipboard - again */
  375. /* this means creating one from the received data first */
  376. /* */
  377. /* Allocate memory for a LOGPALETTE structure large enough to hold */
  378. /* all the PALETTE ENTRY structures, and fill it in. */
  379. /********************************************************************/
  380. numEntries = (nClipDataSize / sizeof(PALETTEENTRY));
  381. memLen = (sizeof(LOGPALETTE) +
  382. ((numEntries - 1) * sizeof(PALETTEENTRY)));
  383. pLogPalette = malloc(memLen);
  384. if (!pLogPalette)
  385. {
  386. TRACE((ERROR_MESSAGE, "Failed to get %d bytes", memLen));
  387. goto exitpt;
  388. }
  389. pLogPalette->palVersion = 0x300;
  390. pLogPalette->palNumEntries = (WORD)numEntries;
  391. /********************************************************************/
  392. /* get a pointer to the data and copy it to the palette */
  393. /********************************************************************/
  394. pData = GlobalLock(hClipData);
  395. if (pData == NULL)
  396. {
  397. TRACE((ERROR_MESSAGE, "Failed to lock buffer"));
  398. goto exitpt;
  399. }
  400. memcpy(pLogPalette->palPalEntry, pData, nClipDataSize);
  401. /********************************************************************/
  402. /* unlock the buffer */
  403. /********************************************************************/
  404. GlobalUnlock(hClipData);
  405. /********************************************************************/
  406. /* now create a palette */
  407. /********************************************************************/
  408. hData = CreatePalette(pLogPalette);
  409. if (!hData)
  410. {
  411. TRACE((ERROR_MESSAGE, "CreatePalette failed\n"));
  412. goto exitpt;
  413. }
  414. /********************************************************************/
  415. /* and set the palette handle to the Clipboard */
  416. /********************************************************************/
  417. if (SetClipboardData(formatID, hData) != hData)
  418. {
  419. TRACE((ERROR_MESSAGE, "SetClipboardData. GetLastError=%d\n", GetLastError()));
  420. }
  421. } else {
  422. /****************************************************************/
  423. /* Just set it onto the clipboard */
  424. /****************************************************************/
  425. if (SetClipboardData(formatID, hClipData) != hClipData)
  426. {
  427. TRACE((ERROR_MESSAGE, "SetClipboardData. GetLastError=%d, hClipData=0x%x\n", GetLastError(), hClipData));
  428. goto exitpt;
  429. }
  430. // Only in this case we don't need to free the handle
  431. *pbFreeHandle = FALSE;
  432. }
  433. rv = TRUE;
  434. exitpt:
  435. if (!pLogPalette)
  436. {
  437. free(pLogPalette);
  438. }
  439. return rv;
  440. }
  441. HGLOBAL Clp_GetMFData(HANDLE hData,
  442. PUINT pDataLen)
  443. {
  444. UINT lenMFBits = 0;
  445. BOOL rc = FALSE;
  446. LPMETAFILEPICT pMFP = NULL;
  447. HDC hMFDC = NULL;
  448. HMETAFILE hMF = NULL;
  449. HGLOBAL hMFBits = NULL;
  450. HANDLE hNewData = NULL;
  451. CHAR *pNewData = NULL;
  452. PVOID pBits = NULL;
  453. /************************************************************************/
  454. /* Lock the memory to get a pointer to a METAFILEPICT header structure */
  455. /* and create a METAFILEPICT DC. */
  456. /************************************************************************/
  457. pMFP = (LPMETAFILEPICT)GlobalLock(hData);
  458. if (pMFP == NULL)
  459. goto exitpt;
  460. hMFDC = CreateMetaFile(NULL);
  461. if (hMFDC == NULL)
  462. goto exitpt;
  463. /************************************************************************/
  464. /* Copy the MFP by playing it into the DC and closing it. */
  465. /************************************************************************/
  466. if (!PlayMetaFile(hMFDC, pMFP->hMF))
  467. {
  468. CloseMetaFile(hMFDC);
  469. goto exitpt;
  470. }
  471. hMF = CloseMetaFile(hMFDC);
  472. if (hMF == NULL)
  473. goto exitpt;
  474. /************************************************************************/
  475. /* Get the MF bits and determine how long they are. */
  476. /************************************************************************/
  477. #ifdef OS_WIN16
  478. hMFBits = GetMetaFileBits(hMF);
  479. lenMFBits = GlobalSize(hMFBits);
  480. #else
  481. lenMFBits = GetMetaFileBitsEx(hMF, 0, NULL);
  482. #endif
  483. if (lenMFBits == 0)
  484. goto exitpt;
  485. /************************************************************************/
  486. /* Work out how much memory we need and get a buffer */
  487. /************************************************************************/
  488. *pDataLen = sizeof(CLIPBOARD_MFPICT) + lenMFBits;
  489. hNewData = GlobalAlloc(GHND, *pDataLen);
  490. if (hNewData == NULL)
  491. goto exitpt;
  492. pNewData = GlobalLock(hNewData);
  493. /************************************************************************/
  494. /* Copy the MF header and bits into the buffer. */
  495. /************************************************************************/
  496. ((PCLIPBOARD_MFPICT)pNewData)->mm = pMFP->mm;
  497. ((PCLIPBOARD_MFPICT)pNewData)->xExt = pMFP->xExt;
  498. ((PCLIPBOARD_MFPICT)pNewData)->yExt = pMFP->yExt;
  499. #ifdef OS_WIN16
  500. pBits = GlobalLock(hMFBits);
  501. memcpy((pNewData + sizeof(CLIPBOARD_MFPICT)),
  502. pBits,
  503. lenMFBits);
  504. GlobalUnlock(hMFBits);
  505. #else
  506. lenMFBits = GetMetaFileBitsEx(hMF, lenMFBits,
  507. (pNewData + sizeof(CLIPBOARD_MFPICT)));
  508. if (lenMFBits == 0)
  509. goto exitpt;
  510. #endif
  511. /************************************************************************/
  512. /* all OK */
  513. /************************************************************************/
  514. rc = TRUE;
  515. exitpt:
  516. /************************************************************************/
  517. /* Unlock any global mem. */
  518. /************************************************************************/
  519. if (pMFP)
  520. {
  521. GlobalUnlock(hData);
  522. }
  523. if (pNewData)
  524. {
  525. GlobalUnlock(hNewData);
  526. }
  527. /************************************************************************/
  528. /* if things went wrong, then free the new data */
  529. /************************************************************************/
  530. if ((rc == FALSE) && (hNewData != NULL))
  531. {
  532. GlobalFree(hNewData);
  533. hNewData = NULL;
  534. }
  535. return(hNewData);
  536. }
  537. HGLOBAL Clp_SetMFData(UINT dataLen,
  538. PVOID pData)
  539. {
  540. BOOL rc = FALSE;
  541. HGLOBAL hMFBits = NULL;
  542. PVOID pMFMem = NULL;
  543. HMETAFILE hMF = NULL;
  544. HGLOBAL hMFPict = NULL;
  545. LPMETAFILEPICT pMFPict = NULL;
  546. /************************************************************************/
  547. /* Allocate memory to hold the MF bits (we need the handle to pass to */
  548. /* SetMetaFileBits). */
  549. /************************************************************************/
  550. hMFBits = GlobalAlloc(GHND, dataLen - sizeof(CLIPBOARD_MFPICT));
  551. if (hMFBits == NULL)
  552. goto exitpt;
  553. /************************************************************************/
  554. /* Lock the handle and copy in the MF header. */
  555. /************************************************************************/
  556. pMFMem = GlobalLock(hMFBits);
  557. if (pMFMem == NULL)
  558. goto exitpt;
  559. memcpy(pMFMem,
  560. (PVOID)((CHAR *)pData + sizeof(CLIPBOARD_MFPICT)),
  561. dataLen - sizeof(CLIPBOARD_MFPICT) );
  562. GlobalUnlock(hMFBits);
  563. /************************************************************************/
  564. /* Now use the copied MF bits to create the actual MF bits and get a */
  565. /* handle to the MF. */
  566. /************************************************************************/
  567. #ifdef OS_WIN16
  568. hMF = SetMetaFileBits(hMFBits);
  569. #else
  570. hMF = SetMetaFileBitsEx(dataLen - sizeof(CLIPBOARD_MFPICT), pMFMem);
  571. #endif
  572. if (hMF == NULL)
  573. goto exitpt;
  574. /************************************************************************/
  575. /* Allocate a new METAFILEPICT structure, and use the data from the */
  576. /* header. */
  577. /************************************************************************/
  578. hMFPict = GlobalAlloc(GHND, sizeof(METAFILEPICT));
  579. pMFPict = (LPMETAFILEPICT)GlobalLock(hMFPict);
  580. if (!pMFPict)
  581. goto exitpt;
  582. pMFPict->mm = (long)((PCLIPBOARD_MFPICT)pData)->mm;
  583. pMFPict->xExt = (long)((PCLIPBOARD_MFPICT)pData)->xExt;
  584. pMFPict->yExt = (long)((PCLIPBOARD_MFPICT)pData)->yExt;
  585. pMFPict->hMF = hMF;
  586. GlobalUnlock(hMFPict);
  587. rc = TRUE;
  588. exitpt:
  589. /************************************************************************/
  590. /* tidy up */
  591. /************************************************************************/
  592. if (!rc)
  593. {
  594. if (hMFPict)
  595. {
  596. GlobalFree(hMFPict);
  597. }
  598. if (hMFBits)
  599. {
  600. GlobalFree(hMFBits);
  601. }
  602. }
  603. return(hMFPict);
  604. }
  605. BOOL
  606. Clp_EmptyClipboard(VOID)
  607. {
  608. BOOL rv = FALSE;
  609. if (OpenClipboard(NULL))
  610. {
  611. EmptyClipboard();
  612. rv = TRUE;
  613. CloseClipboard();
  614. }
  615. return rv;
  616. }
  617. BOOL
  618. Clp_CheckEmptyClipboard(VOID)
  619. {
  620. BOOL rv = TRUE;
  621. if (OpenClipboard(NULL))
  622. {
  623. if (EnumClipboardFormats(0))
  624. // format is available, not empty
  625. rv = FALSE;
  626. CloseClipboard();
  627. }
  628. return rv;
  629. }
  630. // Checks for known format names and returns it's ID
  631. UINT
  632. _GetKnownClipboardFormatIDByName(LPCSTR szFormatName)
  633. {
  634. INT fmti, fmtnum;
  635. UINT rv = 0;
  636. fmtnum = sizeof(KnownFormats)/sizeof(KnownFormats[0]);
  637. for (fmti = 0;
  638. fmti < fmtnum
  639. &&
  640. _stricmp(szFormatName, KnownFormats[fmti].szFormat);
  641. fmti ++)
  642. ;
  643. if (fmti < fmtnum)
  644. rv = KnownFormats[fmti].uiFormat;
  645. return rv;
  646. }
  647. VOID
  648. _cdecl LocalPrintMessage(INT errlevel, CHAR *format, ...)
  649. {
  650. CHAR szBuffer[256];
  651. CHAR *type;
  652. va_list arglist;
  653. INT nchr;
  654. va_start (arglist, format);
  655. nchr = _vsnprintf (szBuffer, sizeof(szBuffer), format, arglist);
  656. va_end (arglist);
  657. switch(errlevel)
  658. {
  659. case INFO_MESSAGE: type = "INF"; break;
  660. case ALIVE_MESSAGE: type = "ALV"; break;
  661. case WARNING_MESSAGE: type = "WRN"; break;
  662. case ERROR_MESSAGE: type = "ERR"; break;
  663. default: type = "UNKNOWN";
  664. }
  665. printf("%s:%s", type, szBuffer);
  666. }