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.

166 lines
5.0 KiB

  1. /*
  2. * GETICON.CPP
  3. *
  4. * Functions to create DVASPECT_ICON metafile from filename or classname.
  5. *
  6. * OleMetafilePictFromIconAndLabel
  7. *
  8. * (c) Copyright Microsoft Corp. 1992-1993 All Rights Reserved
  9. */
  10. /*******
  11. *
  12. * ICON (DVASPECT_ICON) METAFILE FORMAT:
  13. *
  14. * The metafile generated with OleMetafilePictFromIconAndLabel contains
  15. * the following records which are used by the functions in DRAWICON.CPP
  16. * to draw the icon with and without the label and to extract the icon,
  17. * label, and icon source/index.
  18. *
  19. * SetWindowOrg
  20. * SetWindowExt
  21. * DrawIcon:
  22. * Inserts records of DIBBITBLT or DIBSTRETCHBLT, once for the
  23. * AND mask, one for the image bits.
  24. * Escape with the comment "IconOnly"
  25. * This indicates where to stop record enumeration to draw only
  26. * the icon.
  27. * SetTextColor
  28. * SetTextAlign
  29. * SetBkColor
  30. * CreateFont
  31. * SelectObject on the font.
  32. * ExtTextOut
  33. * One or more ExtTextOuts occur if the label is wrapped. The
  34. * text in these records is used to extract the label.
  35. * SelectObject on the old font.
  36. * DeleteObject on the font.
  37. * Escape with a comment that contains the path to the icon source.
  38. * Escape with a comment that is the ASCII of the icon index.
  39. *
  40. *******/
  41. #include "precomp.h"
  42. #include "common.h"
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include <ctype.h>
  46. #include <commdlg.h>
  47. #include <memory.h>
  48. #include <cderr.h>
  49. #include "utility.h"
  50. OLEDBGDATA
  51. static const TCHAR szSeparators[] = TEXT(" \t\\/!:");
  52. #define IS_SEPARATOR(c) ( (c) == ' ' || (c) == '\\' \
  53. || (c) == '/' || (c) == '\t' \
  54. || (c) == '!' || (c) == ':')
  55. #define IS_FILENAME_DELIM(c) ( (c) == '\\' || (c) == '/' || (c) == ':' )
  56. #define IS_SPACE(c) ( (c) == ' ' || (c) == '\t' || (c) == '\n' )
  57. /*
  58. * GetAssociatedExecutable
  59. *
  60. * Purpose: Finds the executable associated with the provided extension
  61. *
  62. * Parameters:
  63. * lpszExtension LPSTR points to the extension we're trying to find
  64. * an exe for. Does **NO** validation.
  65. *
  66. * lpszExecutable LPSTR points to where the exe name will be returned.
  67. * No validation here either - pass in 128 char buffer.
  68. *
  69. * Return:
  70. * BOOL TRUE if we found an exe, FALSE if we didn't.
  71. *
  72. */
  73. BOOL FAR PASCAL GetAssociatedExecutable(LPTSTR lpszExtension, LPTSTR lpszExecutable)
  74. {
  75. HKEY hKey;
  76. LRESULT lRet = RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hKey);
  77. if (ERROR_SUCCESS != lRet)
  78. return FALSE;
  79. LONG dw = MAX_PATH_SIZE;
  80. TCHAR szValue[OLEUI_CCHKEYMAX];
  81. lRet = RegQueryValue(hKey, lpszExtension, szValue, &dw); //ProgId
  82. if (ERROR_SUCCESS != lRet)
  83. {
  84. RegCloseKey(hKey);
  85. return FALSE;
  86. }
  87. // szValue now has ProgID
  88. TCHAR szKey[OLEUI_CCHKEYMAX];
  89. lstrcpy(szKey, szValue);
  90. lstrcat(szKey, TEXT("\\Shell\\Open\\Command"));
  91. dw = MAX_PATH_SIZE;
  92. lRet = RegQueryValue(hKey, szKey, szValue, &dw);
  93. if (ERROR_SUCCESS != lRet)
  94. {
  95. RegCloseKey(hKey);
  96. return FALSE;
  97. }
  98. // szValue now has an executable name in it. Let's null-terminate
  99. // at the first post-executable space (so we don't have cmd line
  100. // args.
  101. LPTSTR lpszTemp = szValue;
  102. while ('\0' != *lpszTemp && IS_SPACE(*lpszTemp))
  103. lpszTemp = CharNext(lpszTemp); // Strip off leading spaces
  104. LPTSTR lpszExe = lpszTemp;
  105. while ('\0' != *lpszTemp && !IS_SPACE(*lpszTemp))
  106. lpszTemp = CharNext(lpszTemp); // Step through exe name
  107. *lpszTemp = '\0'; // null terminate at first space (or at end).
  108. lstrcpy(lpszExecutable, lpszExe);
  109. return TRUE;
  110. }
  111. /*
  112. * PointerToNthField
  113. *
  114. * Purpose:
  115. * Returns a pointer to the beginning of the nth field.
  116. * Assumes null-terminated string.
  117. *
  118. * Parameters:
  119. * lpszString string to parse
  120. * nField field to return starting index of.
  121. * chDelimiter char that delimits fields
  122. *
  123. * Return Value:
  124. * LPSTR pointer to beginning of nField field.
  125. * NOTE: If the null terminator is found
  126. * Before we find the Nth field, then
  127. * we return a pointer to the null terminator -
  128. * calling app should be sure to check for
  129. * this case.
  130. *
  131. */
  132. LPTSTR FAR PASCAL PointerToNthField(LPTSTR lpszString, int nField, TCHAR chDelimiter)
  133. {
  134. if (1 == nField)
  135. return lpszString;
  136. int cFieldFound = 1;
  137. LPTSTR lpField = lpszString;
  138. while (*lpField != '\0')
  139. {
  140. if (*lpField++ == chDelimiter)
  141. {
  142. cFieldFound++;
  143. if (nField == cFieldFound)
  144. return lpField;
  145. }
  146. }
  147. return lpField;
  148. }