home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / directx / viewer / file.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  1.6 KB  |  56 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995, 1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File: file.cpp
  6.  *
  7.  ***************************************************************************/
  8.  
  9. #include <d3drmwin.h>
  10. #include "viewer.h"
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <commdlg.h>
  15.  
  16. char* OpenNewFile( HWND hwnd, const char *wndTitle )
  17. {
  18.     static char file[256];
  19.     static char fileTitle[256];
  20.     static char filter[] = "X files (*.x)\0*.x\0"
  21.                "All Files (*.*)\0*.*\0";
  22.     OPENFILENAME ofn;
  23.  
  24.     lstrcpy( file, "");
  25.     lstrcpy( fileTitle, "");
  26.  
  27.     ofn.lStructSize       = sizeof(OPENFILENAME);
  28.     ofn.hwndOwner         = hwnd;
  29. #ifdef WIN32
  30.     ofn.hInstance         = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
  31. #else
  32.     ofn.hInstance         = (HINSTANCE) GetWindowWord(hwnd, GWW_HINSTANCE);
  33. #endif
  34.     ofn.lpstrFilter       = filter;
  35.     ofn.lpstrCustomFilter = (LPSTR) NULL;
  36.     ofn.nMaxCustFilter    = 0L;
  37.     ofn.nFilterIndex      = 1L;
  38.     ofn.lpstrFile         = file;
  39.     ofn.nMaxFile          = sizeof(file);
  40.     ofn.lpstrFileTitle    = fileTitle;
  41.     ofn.nMaxFileTitle     = sizeof(fileTitle);
  42.     ofn.lpstrInitialDir   = NULL;
  43.     ofn.lpstrTitle        = wndTitle;
  44.     ofn.nFileOffset       = 0;
  45.     ofn.nFileExtension    = 0;
  46.     ofn.lpstrDefExt       = "*.x";
  47.     ofn.lCustData         = 0;
  48.  
  49.     ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  50.  
  51.     if (GetOpenFileName(&ofn))
  52.         return (char*)ofn.lpstrFile;
  53.     else
  54.         return NULL;
  55. }
  56.