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.

338 lines
8.6 KiB

  1. /***********************************************************************
  2. MODULE : CMNDLG.C
  3. FUNCTIONS :
  4. COMMENTS :
  5. ************************************************************************/
  6. #include "windows.h"
  7. #include "mfdcod32.h"
  8. /**************************************************************************
  9. Function: InitializeStruct(WORD, LPSTR)
  10. Purpose: To initialize a structure for the current common dialog.
  11. This routine is called just before the common dialogs
  12. API is called.
  13. Returns: void
  14. Comments:
  15. History: Date Author Reason
  16. -------- --------- -----------------------------------
  17. 10/01/91 gregk Created
  18. 11/25/91 denniscr mod for purposes of this app
  19. 7/9/93 denniscr modified for win32 and emf
  20. **************************************************************************/
  21. void InitializeStruct(wCommDlgType, lpStruct, lpszFilter)
  22. WORD wCommDlgType;
  23. LPSTR lpStruct;
  24. LPSTR lpszFilter;
  25. {
  26. LPFOCHUNK lpFOChunk;
  27. LPFSCHUNK lpFSChunk;
  28. switch (wCommDlgType)
  29. {
  30. case FILEOPENDLG:
  31. lpFOChunk = (LPFOCHUNK)lpStruct;
  32. *(lpFOChunk->szFile) = 0;
  33. *(lpFOChunk->szFileTitle) = 0;
  34. lpFOChunk->of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
  35. lpFOChunk->of.hwndOwner = (HWND)hWndMain;
  36. lpFOChunk->of.hInstance = (HANDLE)NULL;
  37. lpFOChunk->of.lpstrFilter = gszFilter;
  38. lpFOChunk->of.lpstrCustomFilter = (LPSTR)NULL;
  39. lpFOChunk->of.nMaxCustFilter = 0L;
  40. lpFOChunk->of.nFilterIndex = 1L;
  41. lpFOChunk->of.lpstrFile = lpFOChunk->szFile;
  42. lpFOChunk->of.nMaxFile = (DWORD)sizeof(lpFOChunk->szFile);
  43. lpFOChunk->of.lpstrFileTitle = lpFOChunk->szFileTitle;
  44. lpFOChunk->of.nMaxFileTitle = 256;
  45. lpFOChunk->of.lpstrInitialDir = (LPSTR)NULL;
  46. lpFOChunk->of.lpstrTitle = (LPSTR)NULL;
  47. lpFOChunk->of.Flags = OFN_HIDEREADONLY |
  48. OFN_PATHMUSTEXIST |
  49. OFN_FILEMUSTEXIST;
  50. lpFOChunk->of.nFileOffset = 0;
  51. lpFOChunk->of.nFileExtension = 0;
  52. lpFOChunk->of.lpstrDefExt = (LPSTR)NULL;
  53. lpFOChunk->of.lCustData = 0L;
  54. lpFOChunk->of.lpfnHook = (LPOFNHOOKPROC)NULL;
  55. lpFOChunk->of.lpTemplateName = (LPSTR)NULL;
  56. break;
  57. case FILESAVEDLG:
  58. lpFSChunk = (LPFSCHUNK)lpStruct;
  59. *(lpFSChunk->szFile) = 0;
  60. *(lpFSChunk->szFileTitle) = 0;
  61. lpFSChunk->of.lStructSize = 0x4C; //OPENFILENAME_SIZE_VERSION_400
  62. lpFSChunk->of.hwndOwner = (HWND)hWndMain;
  63. lpFSChunk->of.hInstance = (HANDLE)NULL;
  64. lpFSChunk->of.lpstrFilter = lpszFilter;
  65. lpFSChunk->of.lpstrCustomFilter = (LPSTR)NULL;
  66. lpFSChunk->of.nMaxCustFilter = 0L;
  67. lpFSChunk->of.nFilterIndex = 1L;
  68. lpFSChunk->of.lpstrFile = lpFSChunk->szFile;
  69. lpFSChunk->of.nMaxFile = (DWORD)sizeof(lpFSChunk->szFile);
  70. lpFSChunk->of.lpstrFileTitle = lpFSChunk->szFileTitle;
  71. lpFSChunk->of.nMaxFileTitle = 256;
  72. lpFSChunk->of.lpstrInitialDir = (LPSTR)NULL;
  73. lpFSChunk->of.lpstrTitle = (LPSTR)NULL;
  74. lpFSChunk->of.Flags = OFN_HIDEREADONLY |
  75. OFN_OVERWRITEPROMPT;
  76. lpFSChunk->of.nFileOffset = 0;
  77. lpFSChunk->of.nFileExtension = 0;
  78. lpFSChunk->of.lpstrDefExt = (LPSTR)"EMF";
  79. lpFSChunk->of.lCustData = 0L;
  80. lpFSChunk->of.lpfnHook = (LPOFNHOOKPROC)NULL;
  81. lpFSChunk->of.lpTemplateName = (LPSTR)NULL;
  82. break;
  83. default:
  84. break;
  85. }
  86. return;
  87. }
  88. /***********************************************************************
  89. FUNCTION : SplitPath
  90. PARAMETERS : LPSTR lpszFileName
  91. LPSTR lpszDrive
  92. LPSTR lpszDir
  93. LPSTR lpszFname
  94. LPSTR lpszExt
  95. PURPOSE : split the fully qualified path into its components
  96. CALLS : WINDOWS
  97. none
  98. APP
  99. none
  100. MESSAGES : none
  101. RETURNS : void
  102. COMMENTS :
  103. HISTORY : 1/16/91 - created - drc
  104. ************************************************************************/
  105. void SplitPath( lpszFileName, lpszDrive, lpszDir, lpszFname, lpszExt)
  106. LPSTR lpszFileName;
  107. LPSTR lpszDrive;
  108. LPSTR lpszDir;
  109. LPSTR lpszFname;
  110. LPSTR lpszExt;
  111. {
  112. char szPath[MAXFILTERLEN];
  113. LPSTR lpszPath;
  114. LPSTR lpszTemp;
  115. int nFileNameLen = nExtOffset - (nFileOffset + 1);
  116. int i;
  117. /* init ptrs */
  118. lpszPath = szPath;
  119. lpszTemp = lpszFileName;
  120. /* pick off the path */
  121. for (i = 0; i < nFileOffset; i++, lpszTemp++, lpszPath++)
  122. *lpszPath = *lpszTemp;
  123. *lpszPath = '\0';
  124. lpszPath = szPath;
  125. /* pick off the drive designator */
  126. for (i = 0; i < 2; i++, lpszPath++, lpszDrive++)
  127. *lpszDrive = *lpszPath;
  128. *lpszDrive = '\0';
  129. /* pick off the directory */
  130. while (*lpszPath != '\0')
  131. *lpszDir++ = *lpszPath++;
  132. *lpszDir = '\0';
  133. /* reset temp ptr */
  134. lpszTemp = lpszFileName;
  135. /* index to filename */
  136. lpszTemp += nFileOffset;
  137. /* pick off the filename */
  138. for (i = 0; i < nFileNameLen; i++, lpszTemp++, lpszFname++)
  139. *lpszFname = *lpszTemp;
  140. *lpszFname = '\0';
  141. /* reset temp ptr */
  142. lpszTemp = lpszFileName;
  143. /* index to file extension */
  144. lpszTemp += nExtOffset;
  145. /* pick off the ext */
  146. while (*lpszTemp != '\0')
  147. *lpszExt++ = *lpszTemp++;
  148. *lpszExt = '\0';
  149. }
  150. /***********************************************************************
  151. FUNCTION : OpenFileDialog
  152. PARAMETERS : LPSTR lpszOpenName
  153. PURPOSE : init the OPENFILE structure and call the file open
  154. common dialog
  155. CALLS : WINDOWS
  156. GlobalAlloc
  157. GlobalLock
  158. GlobalFree
  159. wsprintf
  160. GetOpenFileName
  161. APP
  162. InitializeStruct
  163. MESSAGES : none
  164. RETURNS : int (see returns for GetOpenFileName)
  165. COMMENTS :
  166. HISTORY : 11/25/91 - created - drc
  167. ************************************************************************/
  168. int OpenFileDialog(lpszOpenName)
  169. LPSTR lpszOpenName;
  170. {
  171. int nRet;
  172. HANDLE hChunk;
  173. LPFOCHUNK lpFOChunk;
  174. hChunk = GlobalAlloc(GMEM_FIXED, sizeof(FOCHUNK));
  175. if (hChunk) {
  176. lpFOChunk = (LPFOCHUNK)GlobalLock(hChunk);
  177. if (!lpFOChunk) {
  178. GlobalFree(hChunk);
  179. lpFOChunk=NULL;
  180. return(0);
  181. }
  182. }
  183. else {
  184. lpFOChunk=NULL;
  185. return(0);
  186. }
  187. InitializeStruct(FILEOPENDLG, (LPSTR)lpFOChunk, NULL);
  188. nRet = GetOpenFileName( &(lpFOChunk->of) );
  189. if (nRet) {
  190. wsprintf(lpszOpenName, (LPSTR)"%s", lpFOChunk->of.lpstrFile);
  191. nExtOffset = lpFOChunk->of.nFileExtension;
  192. nFileOffset = lpFOChunk->of.nFileOffset;
  193. }
  194. GlobalUnlock(hChunk);
  195. GlobalFree(hChunk);
  196. return(nRet);
  197. }
  198. /***********************************************************************
  199. FUNCTION : SaveFileDialog
  200. PARAMETERS : LPSTR lpszOpenName
  201. PURPOSE : init the OPENFILE structure and call the file open
  202. common dialog
  203. CALLS : WINDOWS
  204. GlobalAlloc
  205. GlobalLock
  206. GlobalFree
  207. wsprintf
  208. GetOpenFileName
  209. APP
  210. InitializeStruct
  211. MESSAGES : none
  212. RETURNS : int (see returns for GetSaveFileName)
  213. COMMENTS : this could easily be merged with OpenFileDialog. This
  214. would decrease the redundancy but this is more illustrative.
  215. HISTORY : 11/25/91 - created - drc
  216. ************************************************************************/
  217. int SaveFileDialog(lpszSaveName, lpszFilter)
  218. LPSTR lpszSaveName;
  219. LPSTR lpszFilter;
  220. {
  221. int nRet;
  222. HANDLE hChunk;
  223. LPFOCHUNK lpFOChunk;
  224. hChunk = GlobalAlloc(GMEM_FIXED, sizeof(FOCHUNK));
  225. if (hChunk) {
  226. lpFOChunk = (LPFOCHUNK)GlobalLock(hChunk);
  227. if (!lpFOChunk) {
  228. GlobalFree(hChunk);
  229. lpFOChunk=NULL;
  230. return(0);
  231. }
  232. }
  233. else {
  234. lpFOChunk=NULL;
  235. return(0);
  236. }
  237. InitializeStruct(FILESAVEDLG, (LPSTR)lpFOChunk, lpszFilter);
  238. nRet = GetSaveFileName( &(lpFOChunk->of) );
  239. if (nRet)
  240. wsprintf(lpszSaveName, (LPSTR)"%s", lpFOChunk->of.lpstrFile);
  241. GlobalUnlock(hChunk);
  242. GlobalFree(hChunk);
  243. return(nRet);
  244. }