home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / DS3DVIEW / FILE.CPP < prev    next >
C/C++ Source or Header  |  1996-08-28  |  3KB  |  109 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File: file.cpp
  6.  *
  7.  *  DESCRIPTION: Functionality to let users pick files and return their
  8.  *                           names to the object viewer (one for XOF, one for WAV)
  9.  *
  10.  ***************************************************************************/
  11.  
  12. #include "d3drmwin.h"
  13. #include "resource.h"
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. /*
  19. ** Lets the user select a new geometry file to load and returns the full path and filename
  20. */
  21.  
  22. char* OpenNewFile( HWND hwnd )
  23. {
  24.     static char file[256];
  25.     static char fileTitle[256];
  26.     static char filter[] = "Geometry files (*.x)\0*.x\0"
  27.                            "All Files (*.*)\0*.*\0";
  28.     OPENFILENAME ofn;
  29.  
  30.     strcpy( file, "");
  31.     strcpy( fileTitle, "");
  32.  
  33.         // Set up the OPENFILENAME structure
  34.     ofn.lStructSize       = sizeof(OPENFILENAME);
  35.     ofn.hwndOwner         = hwnd;
  36. #ifdef WIN32
  37.     ofn.hInstance         = (HANDLE) GetWindowLong(hwnd, GWL_HINSTANCE);
  38. #else
  39.     ofn.hInstance         = (HANDLE) GetWindowWord(hwnd, GWW_HINSTANCE);
  40. #endif
  41.     ofn.lpstrFilter       = filter;
  42.     ofn.lpstrCustomFilter = (LPSTR) NULL;
  43.     ofn.nMaxCustFilter    = 0L;
  44.     ofn.nFilterIndex      = 1L;
  45.     ofn.lpstrFile         = file;
  46.     ofn.nMaxFile          = sizeof(file);
  47.     ofn.lpstrFileTitle    = fileTitle;
  48.     ofn.nMaxFileTitle     = sizeof(fileTitle);
  49.     ofn.lpstrInitialDir   = NULL;
  50.     ofn.lpstrTitle        = "Open a File";
  51.     ofn.nFileOffset       = 0;
  52.     ofn.nFileExtension    = 0;
  53.     ofn.lpstrDefExt       = "*.x";
  54.     ofn.lCustData         = 0;
  55.  
  56.     ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  57.  
  58.         // Call windows functionality to make it happen!
  59.     if (GetOpenFileName(&ofn))
  60.         return (char*)ofn.lpstrFile;
  61.     else
  62.         return NULL;
  63. }
  64.  
  65. /*
  66. ** Lets the user select a new .WAV file to load and returns it's full path and filename
  67. */
  68.  
  69. char* OpenNewSoundFile( HWND hwnd )
  70. {
  71.     static char file[256];
  72.     static char fileTitle[256];
  73.     static char filter[] = "Sound files (*.wav)\0*.wav\0"
  74.                            "All Files (*.*)\0*.*\0";
  75.     OPENFILENAME ofn;
  76.  
  77.     strcpy( file, "");
  78.     strcpy( fileTitle, "");
  79.  
  80.     ofn.lStructSize       = sizeof(OPENFILENAME);
  81.     ofn.hwndOwner         = hwnd;
  82. #ifdef WIN32
  83.     ofn.hInstance         = (HANDLE) GetWindowLong(hwnd, GWL_HINSTANCE);
  84. #else
  85.     ofn.hInstance         = (HANDLE) GetWindowWord(hwnd, GWW_HINSTANCE);
  86. #endif
  87.     ofn.lpstrFilter       = filter;
  88.     ofn.lpstrCustomFilter = (LPSTR) NULL;
  89.     ofn.nMaxCustFilter    = 0L;
  90.     ofn.nFilterIndex      = 1L;
  91.     ofn.lpstrFile         = file;
  92.     ofn.nMaxFile          = sizeof(file);
  93.     ofn.lpstrFileTitle    = fileTitle;
  94.     ofn.nMaxFileTitle     = sizeof(fileTitle);
  95.     ofn.lpstrInitialDir   = NULL;
  96.     ofn.lpstrTitle        = "Open a File";
  97.     ofn.nFileOffset       = 0;
  98.     ofn.nFileExtension    = 0;
  99.     ofn.lpstrDefExt       = "*.wav";
  100.     ofn.lCustData         = 0;
  101.  
  102.     ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  103.  
  104.     if (GetOpenFileName(&ofn))
  105.         return (char*)ofn.lpstrFile;
  106.     else
  107.         return NULL;
  108. }
  109.