home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / image / drwatson / browse.c next >
C/C++ Source or Header  |  1996-06-06  |  11KB  |  408 lines

  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. static char   szLastDumpFile[MAX_PATH];
  39.  
  40.  
  41.  
  42. LRESULT PASCAL
  43. BrowseHookProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  44.  
  45. /*++
  46.  
  47. Routine Description:
  48.  
  49.     Hook procedure for directory browse common file dialog.  This hook
  50.     procedure is required to provide help, put the window in the
  51.     foreground, and set the edit so that the common file dialog dll
  52.     thinks the user entered a value.
  53.  
  54. Arguments:
  55.  
  56.     hwnd       - window handle to the dialog box
  57.     message    - message number
  58.     wParam     - first message parameter
  59.     lParam     - second message parameter
  60.  
  61. Return Value:
  62.  
  63.     TRUE       - did not process the message
  64.     FALSE      - did process the message
  65.  
  66. --*/
  67.  
  68. {
  69.     if (message==WM_INITDIALOG) {
  70.         SetForegroundWindow( hwnd );
  71.     }
  72.     else
  73.     if (message==WM_PAINT) {
  74.         SetDlgItemText( hwnd, edt1, "drwatson.log" );
  75.     }
  76.     else
  77.     if (message==WM_COMMAND && wParam==psh15) {
  78.         //
  79.         // get the help file name
  80.         //
  81.         GetHelpFileName( szHelpFileName, sizeof( szHelpFileName ) );
  82.  
  83.         //
  84.         // call winhelp
  85.         //
  86.         WinHelp( hwnd, szHelpFileName, HELP_FINDER, IDH_LOGFILELOCATION );
  87.     }
  88.     return FALSE;
  89. }
  90.  
  91. BOOL
  92. BrowseForDirectory( char *szCurrDir )
  93.  
  94. /*++
  95.  
  96. Routine Description:
  97.  
  98.     Presents a common file open dialog that contains only the directory
  99.     tree.  The use can select a directory for use as a storage location
  100.     for the DRWTSN32 log file.
  101.  
  102. Arguments:
  103.  
  104.     szCurrDir  - current directory
  105.  
  106. Return Value:
  107.  
  108.     TRUE       - got a good directory (user pressed the OK button)
  109.     FALSE      - got nothing (user pressed the CANCEL button)
  110.  
  111.     the szCurrDir is also changed to have the selected directory.
  112.  
  113. --*/
  114.  
  115. {
  116.     OPENFILENAME   of;
  117.     char           ftitle     [MAX_PATH];
  118.     char           title      [MAX_PATH];
  119.     char           fname      [MAX_PATH];
  120.     char           szDrive    [_MAX_DRIVE];
  121.     char           szDir      [_MAX_DIR];
  122.  
  123.     ftitle[0] = 0;
  124.     strcpy( fname, "*.*" );
  125.     of.lStructSize = sizeof( OPENFILENAME );
  126.     of.hwndOwner = NULL;
  127.     of.hInstance = GetModuleHandle( NULL );
  128.     of.lpstrFilter = NULL;
  129.     of.lpstrCustomFilter = NULL;
  130.     of.nMaxCustFilter = 0;
  131.     of.nFilterIndex = 0;
  132.     of.lpstrFile = fname;
  133.     of.nMaxFile = MAX_PATH;
  134.     of.lpstrFileTitle = ftitle;
  135.     of.nMaxFileTitle = MAX_PATH;
  136.     of.lpstrInitialDir = szCurrDir;
  137.     strcpy( title, LoadRcString( IDS_LOGBROWSE_TITLE ) );
  138.     of.lpstrTitle = title;
  139.     of.Flags = OFN_NONETWORKBUTTON |
  140.                OFN_ENABLEHOOK      |
  141.                OFN_NOCHANGEDIR     |
  142.                OFN_SHOWHELP        |
  143.                OFN_ENABLETEMPLATE;
  144.     of.nFileOffset = 0;
  145.     of.nFileExtension = 0;
  146.     of.lpstrDefExt = NULL;
  147.     of.lCustData = 0;
  148.     of.lpfnHook = BrowseHookProc;
  149.     of.lpTemplateName = MAKEINTRESOURCE(DIRBROWSEDIALOG);
  150.     if (GetSaveFileName( &of )) {
  151.         _splitpath( fname, szDrive, szDir, NULL, NULL );
  152.         strcpy( szCurrDir, szDrive );
  153.         strcat( szCurrDir, szDir );
  154.         szCurrDir[strlen(szCurrDir)-1] = '\0';
  155.         return TRUE;
  156.     }
  157.     return FALSE;
  158. }
  159.  
  160. LRESULT PASCAL
  161. WaveHookProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  162.  
  163. /*++
  164.  
  165. Routine Description:
  166.  
  167.     Hook procedure for wave file selection common file dialog.  This hook
  168.     procedure is required to provide help, put the window in the
  169.     foreground, and provide a test button for listening to a wave file.
  170.  
  171. Arguments:
  172.  
  173.     hwnd       - window handle to the dialog box
  174.     message    - message number
  175.     wParam     - first message parameter
  176.     lParam     - second message parameter
  177.  
  178. Return Value:
  179.  
  180.     TRUE       - did not process the message
  181.     FALSE      - did process the message
  182.  
  183. --*/
  184.  
  185. {
  186.     char szWave[MAX_PATH];
  187.  
  188.     if (message==WM_INITDIALOG) {
  189.         SetForegroundWindow( hwnd );
  190.     }
  191.     else
  192.     if (message == WM_COMMAND) {
  193.         switch (wParam) {
  194.             case ID_TEST_WAVE:
  195.                 GetDlgItemText( hwnd, edt1, szWave, sizeof(szWave) );
  196.                 PlaySound( szWave, NULL, SND_FILENAME );
  197.                 break;
  198.  
  199.             case psh15:
  200.                 //
  201.                 // get the help file name
  202.                 //
  203.                 GetHelpFileName( szHelpFileName, sizeof( szHelpFileName ) );
  204.  
  205.                 //
  206.                 // call winhelp
  207.                 //
  208.                 WinHelp( hwnd, szHelpFileName, HELP_FINDER, IDH_WAVEFILE );
  209.                 break;
  210.         }
  211.     }
  212.  
  213.     return FALSE;
  214. }
  215.  
  216. BOOL
  217. GetWaveFileName( char *szWaveName )
  218.  
  219. /*++
  220.  
  221. Routine Description:
  222.  
  223.     Presents a common file open dialog for the purpose of selecting a
  224.     wave file to be played when an application error occurs.
  225.  
  226. Arguments:
  227.  
  228.     szWaveName - name of the selected wave file
  229.  
  230. Return Value:
  231.  
  232.     TRUE       - got a good wave file name (user pressed the OK button)
  233.     FALSE      - got nothing (user pressed the CANCEL button)
  234.  
  235.     the szWaveName is changed to have the selected wave file name.
  236.  
  237. --*/
  238.  
  239. {
  240.     OPENFILENAME   of;
  241.     char           ftitle[MAX_PATH];
  242.     char           title[MAX_PATH];
  243.     char           fname[MAX_PATH];
  244.     char           filter[1024];
  245.     char           szDrive    [_MAX_DRIVE];
  246.     char           szDir      [_MAX_DIR];
  247.  
  248.     ftitle[0] = 0;
  249.     strcpy( fname, "*.wav" );
  250.     of.lStructSize = sizeof( OPENFILENAME );
  251.     of.hwndOwner = NULL;
  252.     of.hInstance = GetModuleHandle( NULL );
  253.     strcpy( filter, LoadRcString( IDS_WAVE_FILTER ) );
  254.     strcpy( &filter[strlen(filter)+1], "*.wav" );
  255.     filter[strlen(filter)+1] = '\0';
  256.     of.lpstrFilter = filter;
  257.     of.lpstrCustomFilter = NULL;
  258.     of.nMaxCustFilter = 0;
  259.     of.nFilterIndex = 0;
  260.     of.lpstrFile = fname;
  261.     of.nMaxFile = MAX_PATH;
  262.     of.lpstrFileTitle = ftitle;
  263.     of.nMaxFileTitle = MAX_PATH;
  264.     of.lpstrInitialDir = szLastWaveFile;
  265.     strcpy( title, LoadRcString( IDS_WAVEBROWSE_TITLE ) );
  266.     of.lpstrTitle = title;
  267.     of.Flags = OFN_NONETWORKBUTTON |
  268.                OFN_ENABLEHOOK      |
  269.                OFN_ENABLETEMPLATE  |
  270.                OFN_SHOWHELP        |
  271.                OFN_NOCHANGEDIR;
  272.     of.nFileOffset = 0;
  273.     of.nFileExtension = 0;
  274.     of.lpstrDefExt = "wav";
  275.     of.lCustData = 0;
  276.     of.lpfnHook = WaveHookProc;
  277.     of.lpTemplateName = MAKEINTRESOURCE(WAVEFILEOPENDIALOG);
  278.     if (GetOpenFileName( &of )) {
  279.         strcpy( szWaveName, fname );
  280.         _splitpath( fname, szDrive, szDir, NULL, NULL );
  281.         strcpy( szLastWaveFile, szDrive );
  282.         strcat( szLastWaveFile, szDir );
  283.         return TRUE;
  284.     }
  285.     return FALSE;
  286. }
  287.  
  288. LRESULT PASCAL
  289. DumpHookProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  290.  
  291. /*++
  292.  
  293. Routine Description:
  294.  
  295.     Hook procedure for wave file selection common file dialog.  This hook
  296.     procedure is required to provide help, put the window in the
  297.     foreground, and provide a test button for listening to a wave file.
  298.  
  299. Arguments:
  300.  
  301.     hwnd       - window handle to the dialog box
  302.     message    - message number
  303.     wParam     - first message parameter
  304.     lParam     - second message parameter
  305.  
  306. Return Value:
  307.  
  308.     TRUE       - did not process the message
  309.     FALSE      - did process the message
  310.  
  311. --*/
  312.  
  313. {
  314.     if (message == WM_INITDIALOG) {
  315.         SetForegroundWindow( hwnd );
  316.     }
  317.     else
  318.     if (message == WM_COMMAND) {
  319.         switch (wParam) {
  320.             case psh15:
  321.                 //
  322.                 // get the help file name
  323.                 //
  324.                 GetHelpFileName( szHelpFileName, sizeof( szHelpFileName ) );
  325.  
  326.                 //
  327.                 // call winhelp
  328.                 //
  329.                 WinHelp( hwnd, szHelpFileName, HELP_FINDER, IDH_CRASH_DUMP );
  330.                 break;
  331.         }
  332.     }
  333.  
  334.     return FALSE;
  335. }
  336.  
  337. BOOL
  338. GetDumpFileName( char *szDumpName )
  339.  
  340. /*++
  341.  
  342. Routine Description:
  343.  
  344.     Presents a common file open dialog for the purpose of selecting a
  345.     wave file to be played when an application error occurs.
  346.  
  347. Arguments:
  348.  
  349.     szWaveName - name of the selected wave file
  350.  
  351. Return Value:
  352.  
  353.     TRUE       - got a good wave file name (user pressed the OK button)
  354.     FALSE      - got nothing (user pressed the CANCEL button)
  355.  
  356.     the szWaveName is changed to have the selected wave file name.
  357.  
  358. --*/
  359.  
  360. {
  361.     OPENFILENAME   of;
  362.     char           ftitle[MAX_PATH];
  363.     char           title[MAX_PATH];
  364.     char           fname[MAX_PATH];
  365.     char           filter[1024];
  366.     char           szDrive    [_MAX_DRIVE];
  367.     char           szDir      [_MAX_DIR];
  368.  
  369.     ftitle[0] = 0;
  370.     strcpy( fname, "*.dmp" );
  371.     of.lStructSize = sizeof( OPENFILENAME );
  372.     of.hwndOwner = NULL;
  373.     of.hInstance = GetModuleHandle( NULL );
  374.     strcpy( filter, LoadRcString( IDS_DUMP_FILTER ) );
  375.     strcpy( &filter[strlen(filter)+1], "*.dmp" );
  376.     filter[strlen(filter)+1] = '\0';
  377.     of.lpstrFilter = filter;
  378.     of.lpstrCustomFilter = NULL;
  379.     of.nMaxCustFilter = 0;
  380.     of.nFilterIndex = 0;
  381.     of.lpstrFile = fname;
  382.     of.nMaxFile = MAX_PATH;
  383.     of.lpstrFileTitle = ftitle;
  384.     of.nMaxFileTitle = MAX_PATH;
  385.     of.lpstrInitialDir = szLastDumpFile;
  386.     strcpy( title, LoadRcString( IDS_DUMPBROWSE_TITLE ) );
  387.     of.lpstrTitle = title;
  388.     of.Flags = OFN_NONETWORKBUTTON |
  389.                OFN_ENABLEHOOK      |
  390.                OFN_ENABLETEMPLATE  |
  391.                OFN_SHOWHELP        |
  392.                OFN_NOCHANGEDIR;
  393.     of.nFileOffset = 0;
  394.     of.nFileExtension = 0;
  395.     of.lpstrDefExt = "dmp";
  396.     of.lCustData = 0;
  397.     of.lpfnHook = DumpHookProc;
  398.     of.lpTemplateName = MAKEINTRESOURCE(DUMPFILEOPENDIALOG);
  399.     if (GetOpenFileName( &of )) {
  400.         strcpy( szDumpName, fname );
  401.         _splitpath( fname, szDrive, szDir, NULL, NULL );
  402.         strcpy( szLastDumpFile, szDrive );
  403.         strcat( szLastDumpFile, szDir );
  404.         return TRUE;
  405.     }
  406.     return FALSE;
  407. }
  408.