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.

444 lines
11 KiB

  1. /*++
  2. Copyright (c) 1993-2002 Microsoft Corporation
  3. Module Name:
  4. browse.cpp
  5. Abstract:
  6. This file implements the functions that make use of the common
  7. file open dialogs for browsing for files/directories.
  8. Author:
  9. Wesley Witt (wesw) 1-May-1993
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "pch.cpp"
  14. static _TCHAR szHelpFileName[MAX_PATH];
  15. static _TCHAR szLastWaveFile[MAX_PATH];
  16. static _TCHAR szLastDumpFile[MAX_PATH];
  17. int CALLBACK
  18. BrowseHookProc(
  19. HWND hwnd,
  20. UINT message,
  21. LPARAM lParam,
  22. LPARAM lpData
  23. )
  24. /*++
  25. Routine Description:
  26. Hook procedure for directory browse common file dialog. This hook
  27. procedure is required to provide help, put the window in the
  28. foreground, and set the edit so that the common file dialog dll
  29. thinks the user entered a value.
  30. Arguments:
  31. hwnd - window handle to the dialog box
  32. message - message number
  33. wParam - first message parameter
  34. lParam - Caller's data
  35. Return Value:
  36. TRUE - did not process the message
  37. FALSE - did process the message
  38. --*/
  39. {
  40. switch (message) {
  41. case BFFM_INITIALIZED:
  42. SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
  43. break;
  44. }
  45. return FALSE;
  46. }
  47. BOOL
  48. BrowseForDirectory(
  49. HWND hwnd,
  50. _TCHAR *szCurrDir,
  51. DWORD len
  52. )
  53. /*++
  54. Routine Description:
  55. Presents a common file open dialog that contains only the directory
  56. tree. The use can select a directory for use as a storage location
  57. for the DRWTSN32 log file.
  58. Arguments:
  59. szCurrDir - current directory
  60. Return Value:
  61. TRUE - got a good directory (user pressed the OK button)
  62. FALSE - got nothing (user pressed the CANCEL button)
  63. the szCurrDir is also changed to have the selected directory.
  64. --*/
  65. {
  66. BROWSEINFO browseinfo;
  67. LPITEMIDLIST pitemidlist;
  68. _TCHAR title [MAX_PATH];
  69. _TCHAR fname [MAX_PATH];
  70. _TCHAR szDir [MAX_PATH];
  71. browseinfo.hwndOwner = hwnd;
  72. browseinfo.pidlRoot = NULL;
  73. browseinfo.pszDisplayName = fname;
  74. LoadRcStringBuf( IDS_LOGBROWSE_TITLE, title, _tsizeof(title) );
  75. browseinfo.lpszTitle = title;
  76. browseinfo.ulFlags = BIF_NEWDIALOGSTYLE |
  77. BIF_RETURNONLYFSDIRS ;
  78. browseinfo.lpfn = BrowseHookProc;
  79. browseinfo.lParam = (LPARAM) szCurrDir;
  80. if (pitemidlist = SHBrowseForFolder(&browseinfo)) {
  81. if (SHGetPathFromIDList(pitemidlist,
  82. szDir )) {
  83. lstrcpyn( szCurrDir, szDir, len );
  84. return TRUE;
  85. }
  86. }
  87. return FALSE;
  88. }
  89. UINT_PTR
  90. WaveHookProc(
  91. HWND hwnd,
  92. UINT message,
  93. WPARAM wParam,
  94. LPARAM lParam
  95. )
  96. /*++
  97. Routine Description:
  98. Hook procedure for wave file selection common file dialog. This hook
  99. procedure is required to provide help, put the window in the
  100. foreground, and provide a test button for listening to a wave file.
  101. Arguments:
  102. hwnd - window handle to the dialog box
  103. message - message number
  104. wParam - first message parameter
  105. lParam - second message parameter
  106. Return Value:
  107. TRUE - did not process the message
  108. FALSE - did process the message
  109. --*/
  110. {
  111. _TCHAR szWave[MAX_PATH];
  112. NMHDR *pnmhdr;
  113. switch (message) {
  114. case WM_INITDIALOG:
  115. SetForegroundWindow( hwnd );
  116. return (TRUE);
  117. break;
  118. case WM_COMMAND:
  119. switch (wParam) {
  120. case ID_TEST_WAVE:
  121. CommDlg_OpenSave_GetFilePath(GetParent(hwnd), szWave, sizeof(szWave) / sizeof(_TCHAR));
  122. PlaySound( szWave, NULL, SND_FILENAME );
  123. break;
  124. }
  125. break;
  126. case WM_NOTIFY:
  127. pnmhdr = (NMHDR *) lParam;
  128. if (pnmhdr->code == CDN_HELP) {
  129. LPOFNOTIFY pofn = (LPOFNOTIFY) lParam;
  130. PostMessage(pofn->lpOFN->hwndOwner, IDH_WAVE_FILE, 0 , 0);
  131. return TRUE;
  132. GetHtmlHelpFileName( szHelpFileName, sizeof( szHelpFileName ) / sizeof(_TCHAR) );
  133. HtmlHelp(pofn->lpOFN->hwndOwner,
  134. szHelpFileName,
  135. HH_DISPLAY_TOPIC,
  136. (DWORD_PTR) (IDHH_WAVEFILE)
  137. );
  138. return TRUE;
  139. }
  140. }
  141. return FALSE;
  142. }
  143. BOOL
  144. GetWaveFileName(
  145. HWND hwnd,
  146. _TCHAR *szWaveName,
  147. DWORD len
  148. )
  149. /*++
  150. Routine Description:
  151. Presents a common file open dialog for the purpose of selecting a
  152. wave file to be played when an application error occurs.
  153. Arguments:
  154. szWaveName - name of the selected wave file
  155. Return Value:
  156. TRUE - got a good wave file name (user pressed the OK button)
  157. FALSE - got nothing (user pressed the CANCEL button)
  158. the szWaveName is changed to have the selected wave file name.
  159. --*/
  160. {
  161. OPENFILENAME of;
  162. _TCHAR ftitle[MAX_PATH];
  163. _TCHAR title[MAX_PATH];
  164. _TCHAR fname[MAX_PATH];
  165. _TCHAR filter[1024];
  166. _TCHAR szDrive [_MAX_DRIVE];
  167. _TCHAR szDir [_MAX_DIR];
  168. _TCHAR szDefExt[]=_T("*.wav");
  169. LPTSTR pszfil;
  170. ZeroMemory(&of, sizeof(OPENFILENAME));
  171. ftitle[0] = 0;
  172. lstrcpyn( fname, (*szWaveName ? szWaveName : szDefExt), _tsizeof(fname) );
  173. of.lStructSize = sizeof(OPENFILENAME);
  174. of.hwndOwner = hwnd;
  175. of.hInstance = GetModuleHandle( NULL );
  176. LoadRcStringBuf( IDS_WAVE_FILTER, filter, _tsizeof(filter) - 1);
  177. pszfil=&filter[_tcslen(filter)+1];
  178. if (pszfil < filter + (_tsizeof(filter) - _tsizeof(szDefExt) - 1)) {
  179. _tcscpy( pszfil, szDefExt );
  180. pszfil += _tcslen(pszfil) + 1;
  181. }
  182. *pszfil = _T('\0');
  183. of.lpstrFilter = filter;
  184. of.lpstrCustomFilter = NULL;
  185. of.nMaxCustFilter = 0;
  186. of.nFilterIndex = 0;
  187. of.lpstrFile = fname;
  188. of.nMaxFile = MAX_PATH;
  189. of.lpstrFileTitle = ftitle;
  190. of.nMaxFileTitle = MAX_PATH;
  191. LoadRcStringBuf( IDS_WAVEBROWSE_TITLE, title, _tsizeof(title) );
  192. of.lpstrTitle = title;
  193. of.Flags = OFN_NONETWORKBUTTON |
  194. OFN_HIDEREADONLY |
  195. OFN_ENABLEHOOK |
  196. OFN_ENABLETEMPLATE |
  197. #if 1
  198. OFN_SHOWHELP |
  199. #endif
  200. OFN_NOCHANGEDIR |
  201. OFN_EXPLORER |
  202. OFN_ENABLESIZING |
  203. OFN_NODEREFERENCELINKS;
  204. of.nFileOffset = 0;
  205. of.nFileExtension = 0;
  206. of.lpstrDefExt = szDefExt + 2;
  207. of.lCustData = 0;
  208. of.lpfnHook = WaveHookProc;
  209. of.lpTemplateName = MAKEINTRESOURCE(WAVEFILEOPENDIALOG2);
  210. if (GetOpenFileName( &of )) {
  211. lstrcpyn( szWaveName, fname, len );
  212. _tsplitpath( fname, szDrive, szDir, NULL, NULL );
  213. _tcscpy( szLastWaveFile, szDrive );
  214. _tcscat( szLastWaveFile, szDir );
  215. return TRUE;
  216. }
  217. return FALSE;
  218. }
  219. UINT_PTR
  220. DumpHookProc(
  221. HWND hwnd,
  222. UINT message,
  223. WPARAM wParam,
  224. LPARAM lParam
  225. )
  226. /*++
  227. Routine Description:
  228. Hook procedure for wave file selection common file dialog. This hook
  229. procedure is required to provide help, put the window in the
  230. foreground, and provide a test button for listening to a wave file.
  231. Arguments:
  232. hwnd - window handle to the dialog box
  233. message - message number
  234. wParam - first message parameter
  235. lParam - second message parameter
  236. Return Value:
  237. TRUE - did not process the message
  238. FALSE - did process the message
  239. --*/
  240. {
  241. NMHDR *pnmhdr;
  242. switch (message) {
  243. case WM_NOTIFY:
  244. pnmhdr = (NMHDR *) lParam;
  245. if (pnmhdr->code == CDN_HELP) {
  246. LPOFNOTIFY pofn = (LPOFNOTIFY) lParam;
  247. PostMessage(pofn->lpOFN->hwndOwner, IDH_CRASH_DUMP, 0 , 0);
  248. return TRUE;
  249. GetHtmlHelpFileName( szHelpFileName, sizeof( szHelpFileName ) / sizeof(_TCHAR) );
  250. HtmlHelp(pofn->lpOFN->hwndOwner,
  251. szHelpFileName,
  252. HH_DISPLAY_TOPIC,
  253. (DWORD_PTR) (IDHH_CRASH_DUMP)
  254. );
  255. return TRUE;
  256. }
  257. case WM_CLOSE:
  258. HtmlHelp( NULL, NULL, HH_CLOSE_ALL, 0);
  259. break;
  260. }
  261. return FALSE;
  262. }
  263. BOOL
  264. GetDumpFileName(
  265. HWND hwnd,
  266. _TCHAR *szDumpName,
  267. DWORD len
  268. )
  269. /*++
  270. Routine Description:
  271. Presents a common file open dialog for the purpose of selecting a
  272. wave file to be played when an application error occurs.
  273. Arguments:
  274. szWaveName - name of the selected wave file
  275. Return Value:
  276. TRUE - got a good wave file name (user pressed the OK button)
  277. FALSE - got nothing (user pressed the CANCEL button)
  278. the szWaveName is changed to have the selected wave file name.
  279. --*/
  280. {
  281. OPENFILENAME of;
  282. _TCHAR ftitle[MAX_PATH];
  283. _TCHAR title[MAX_PATH];
  284. _TCHAR fname[MAX_PATH];
  285. _TCHAR filter[1024];
  286. _TCHAR szDrive [_MAX_DRIVE];
  287. _TCHAR szDir [_MAX_DIR];
  288. _TCHAR szDefExt[]=_T("*.dmp");
  289. LPTSTR pszfil;
  290. ZeroMemory(&of, sizeof(OPENFILENAME));
  291. ftitle[0] = 0;
  292. lstrcpyn( fname, (*szDumpName ? szDumpName : szDefExt), _tsizeof(fname) );
  293. of.lStructSize = sizeof(OPENFILENAME);
  294. of.hwndOwner = hwnd;
  295. of.hInstance = GetModuleHandle( NULL );
  296. LoadRcStringBuf( IDS_DUMP_FILTER, filter, _tsizeof(filter) - 1 );
  297. pszfil=&filter[_tcslen(filter)+1];
  298. if (pszfil < filter + (_tsizeof(filter) - _tsizeof(szDefExt) - 1)) {
  299. _tcscpy( pszfil, szDefExt );
  300. pszfil += _tcslen(pszfil) + 1;
  301. }
  302. *pszfil = _T('\0');
  303. of.lpstrFilter = filter;
  304. of.lpstrCustomFilter = NULL;
  305. of.nMaxCustFilter = 0;
  306. of.nFilterIndex = 0;
  307. of.lpstrFile = fname;
  308. of.nMaxFile = MAX_PATH;
  309. of.lpstrFileTitle = ftitle;
  310. of.nMaxFileTitle = MAX_PATH;
  311. LoadRcStringBuf( IDS_DUMPBROWSE_TITLE, title, _tsizeof(title) );
  312. of.lpstrTitle = title;
  313. of.Flags = //OFN_NONETWORKBUTTON |
  314. OFN_HIDEREADONLY |
  315. OFN_ENABLEHOOK |
  316. #if 1
  317. OFN_SHOWHELP |
  318. #endif
  319. OFN_NOCHANGEDIR |
  320. OFN_EXPLORER |
  321. OFN_ENABLESIZING;
  322. of.nFileOffset = 0;
  323. of.nFileExtension = 0;
  324. of.lpstrDefExt = szDefExt + 2;
  325. of.lCustData = 0;
  326. of.lpfnHook = DumpHookProc;
  327. of.lpTemplateName = MAKEINTRESOURCE(DUMPFILEOPENDIALOG);
  328. if (GetOpenFileName( &of )) {
  329. lstrcpyn( szDumpName, fname, len );
  330. _tsplitpath( fname, szDrive, szDir, NULL, NULL );
  331. _tcscpy( szLastDumpFile, szDrive );
  332. _tcscat( szLastDumpFile, szDir );
  333. return TRUE;
  334. }
  335. return FALSE;
  336. }