|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1993 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: browse.c ! 8: ! 9: Abstract: ! 10: This file implements the functions that make use of the common ! 11: file open dialogs for browsing for files/directories. ! 12: ! 13: Author: ! 14: ! 15: Wesley Witt (wesw) 1-May-1993 ! 16: ! 17: Environment: ! 18: ! 19: User Mode ! 20: ! 21: --*/ ! 22: ! 23: #include <windows.h> ! 24: #include <stdlib.h> ! 25: #include <stdio.h> ! 26: #include <string.h> ! 27: #include <commdlg.h> ! 28: #include <mmsystem.h> ! 29: #include <direct.h> ! 30: ! 31: #include "drwatson.h" ! 32: #include "proto.h" ! 33: #include "resource.h" ! 34: ! 35: ! 36: static char szHelpFileName[MAX_PATH]; ! 37: static char szLastWaveFile[MAX_PATH]; ! 38: ! 39: ! 40: ! 41: LRESULT PASCAL ! 42: BrowseHookProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) ! 43: ! 44: /*++ ! 45: ! 46: Routine Description: ! 47: ! 48: Hook procedure for directory browse common file dialog. This hook ! 49: procedure is required to provide help, put the window in the ! 50: foreground, and set the edit so that the common file dialog dll ! 51: thinks the user entered a value. ! 52: ! 53: Arguments: ! 54: ! 55: hwnd - window handle to the dialog box ! 56: message - message number ! 57: wParam - first message parameter ! 58: lParam - second message parameter ! 59: ! 60: Return Value: ! 61: ! 62: TRUE - did not process the message ! 63: FALSE - did process the message ! 64: ! 65: --*/ ! 66: ! 67: { ! 68: if (message==WM_INITDIALOG) { ! 69: SetForegroundWindow( hwnd ); ! 70: } ! 71: else ! 72: if (message==WM_PAINT) { ! 73: SetDlgItemText( hwnd, edt1, "drwatson.log" ); ! 74: } ! 75: else ! 76: if (message==WM_COMMAND && wParam==psh15) { ! 77: // ! 78: // get the help file name ! 79: // ! 80: GetHelpFileName( szHelpFileName, sizeof( szHelpFileName ) ); ! 81: ! 82: // ! 83: // call winhelp ! 84: // ! 85: WinHelp( hwnd, szHelpFileName, HELP_CONTEXT, IDH_LOGFILELOCATION ); ! 86: } ! 87: return FALSE; ! 88: } ! 89: ! 90: BOOL ! 91: BrowseForDirectory( char *szCurrDir ) ! 92: ! 93: /*++ ! 94: ! 95: Routine Description: ! 96: ! 97: Presents a common file open dialog that contains only the directory ! 98: tree. The use can select a directory for use as a storage location ! 99: for the DRWTSN32 log file. ! 100: ! 101: Arguments: ! 102: ! 103: szCurrDir - current directory ! 104: ! 105: Return Value: ! 106: ! 107: TRUE - got a good directory (user pressed the OK button) ! 108: FALSE - got nothing (user pressed the CANCEL button) ! 109: ! 110: the szCurrDir is also changed to have the selected directory. ! 111: ! 112: --*/ ! 113: ! 114: { ! 115: OPENFILENAME of; ! 116: char ftitle [MAX_PATH]; ! 117: char title [MAX_PATH]; ! 118: char fname [MAX_PATH]; ! 119: char szDrive [_MAX_DRIVE]; ! 120: char szDir [_MAX_DIR]; ! 121: char szFname [_MAX_FNAME]; ! 122: char szExt [_MAX_EXT]; ! 123: ! 124: ! 125: ftitle[0] = 0; ! 126: strcpy( fname, "*.*" ); ! 127: of.lStructSize = sizeof( OPENFILENAME ); ! 128: of.hwndOwner = NULL; ! 129: of.hInstance = GetModuleHandle( NULL ); ! 130: of.lpstrFilter = NULL; ! 131: of.lpstrCustomFilter = NULL; ! 132: of.nMaxCustFilter = 0; ! 133: of.nFilterIndex = 0; ! 134: of.lpstrFile = fname; ! 135: of.nMaxFile = MAX_PATH; ! 136: of.lpstrFileTitle = ftitle; ! 137: of.nMaxFileTitle = MAX_PATH; ! 138: of.lpstrInitialDir = szCurrDir; ! 139: strcpy( title, LoadRcString( IDS_LOGBROWSE_TITLE ) ); ! 140: of.lpstrTitle = title; ! 141: of.Flags = OFN_NONETWORKBUTTON | ! 142: OFN_ENABLEHOOK | ! 143: OFN_NOCHANGEDIR | ! 144: OFN_SHOWHELP | ! 145: OFN_ENABLETEMPLATE; ! 146: of.nFileOffset = 0; ! 147: of.nFileExtension = 0; ! 148: of.lpstrDefExt = NULL; ! 149: of.lCustData = 0; ! 150: of.lpfnHook = BrowseHookProc; ! 151: of.lpTemplateName = MAKEINTRESOURCE(DIRBROWSEDIALOG); ! 152: if (GetSaveFileName( &of )) { ! 153: _splitpath( fname, szDrive, szDir, szFname, szExt ); ! 154: strcpy( szCurrDir, szDrive ); ! 155: strcat( szCurrDir, szDir ); ! 156: szCurrDir[strlen(szCurrDir)-1] = '\0'; ! 157: return TRUE; ! 158: } ! 159: return FALSE; ! 160: } ! 161: ! 162: LRESULT PASCAL ! 163: WaveHookProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) ! 164: ! 165: /*++ ! 166: ! 167: Routine Description: ! 168: ! 169: Hook procedure for wave file selection common file dialog. This hook ! 170: procedure is required to provide help, put the window in the ! 171: foreground, and provide a test button for listening to a wave file. ! 172: ! 173: Arguments: ! 174: ! 175: hwnd - window handle to the dialog box ! 176: message - message number ! 177: wParam - first message parameter ! 178: lParam - second message parameter ! 179: ! 180: Return Value: ! 181: ! 182: TRUE - did not process the message ! 183: FALSE - did process the message ! 184: ! 185: --*/ ! 186: ! 187: { ! 188: char szWave[MAX_PATH]; ! 189: ! 190: if (message==WM_INITDIALOG) { ! 191: SetForegroundWindow( hwnd ); ! 192: } ! 193: else ! 194: if (message == WM_COMMAND) { ! 195: switch (wParam) { ! 196: case ID_TEST_WAVE: ! 197: GetDlgItemText( hwnd, edt1, szWave, sizeof(szWave) ); ! 198: PlaySound( szWave, NULL, SND_FILENAME ); ! 199: break; ! 200: ! 201: case psh15: ! 202: // ! 203: // get the help file name ! 204: // ! 205: GetHelpFileName( szHelpFileName, sizeof( szHelpFileName ) ); ! 206: ! 207: // ! 208: // call winhelp ! 209: // ! 210: WinHelp( hwnd, szHelpFileName, HELP_CONTEXT, IDH_WAVEFILE ); ! 211: break; ! 212: } ! 213: } ! 214: ! 215: return FALSE; ! 216: } ! 217: ! 218: BOOL ! 219: GetWaveFileName( char *szWaveName ) ! 220: ! 221: /*++ ! 222: ! 223: Routine Description: ! 224: ! 225: Presents a common file open dialog for the purpose of selecting a ! 226: wave file to be played when an application error occurs. ! 227: ! 228: Arguments: ! 229: ! 230: szWaveName - name of the selected wave file ! 231: ! 232: Return Value: ! 233: ! 234: TRUE - got a good wave file name (user pressed the OK button) ! 235: FALSE - got nothing (user pressed the CANCEL button) ! 236: ! 237: the szWaveName is changed to have the selected wave file name. ! 238: ! 239: --*/ ! 240: ! 241: { ! 242: OPENFILENAME of; ! 243: char ftitle[MAX_PATH]; ! 244: char title[MAX_PATH]; ! 245: char fname[MAX_PATH]; ! 246: char filter[1024]; ! 247: char szDrive [_MAX_DRIVE]; ! 248: char szDir [_MAX_DIR]; ! 249: char szFname [_MAX_FNAME]; ! 250: char szExt [_MAX_EXT]; ! 251: ! 252: ! 253: ftitle[0] = 0; ! 254: strcpy( fname, "*.wav" ); ! 255: of.lStructSize = sizeof( OPENFILENAME ); ! 256: of.hwndOwner = NULL; ! 257: of.hInstance = GetModuleHandle( NULL ); ! 258: strcpy( filter, LoadRcString( IDS_WAVE_FILTER ) ); ! 259: strcpy( &filter[strlen(filter)+1], "*.wav" ); ! 260: filter[strlen(filter)+1] = '\0'; ! 261: of.lpstrFilter = filter; ! 262: of.lpstrCustomFilter = NULL; ! 263: of.nMaxCustFilter = 0; ! 264: of.nFilterIndex = 0; ! 265: of.lpstrFile = fname; ! 266: of.nMaxFile = MAX_PATH; ! 267: of.lpstrFileTitle = ftitle; ! 268: of.nMaxFileTitle = MAX_PATH; ! 269: of.lpstrInitialDir = szLastWaveFile; ! 270: strcpy( title, LoadRcString( IDS_WAVEBROWSE_TITLE ) ); ! 271: of.lpstrTitle = title; ! 272: of.Flags = OFN_NONETWORKBUTTON | ! 273: OFN_ENABLEHOOK | ! 274: OFN_ENABLETEMPLATE | ! 275: OFN_SHOWHELP | ! 276: OFN_NOCHANGEDIR; ! 277: of.nFileOffset = 0; ! 278: of.nFileExtension = 0; ! 279: of.lpstrDefExt = "wav"; ! 280: of.lCustData = 0; ! 281: of.lpfnHook = WaveHookProc; ! 282: of.lpTemplateName = MAKEINTRESOURCE(WAVEFILEOPENDIALOG); ! 283: if (GetOpenFileName( &of )) { ! 284: strcpy( szWaveName, fname ); ! 285: _splitpath( fname, szDrive, szDir, szFname, szExt ); ! 286: strcpy( szLastWaveFile, szDrive ); ! 287: strcat( szLastWaveFile, szDir ); ! 288: return TRUE; ! 289: } ! 290: return FALSE; ! 291: } ! 292:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.