home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / VIEWER / FILE.CPP < prev    next >
C/C++ Source or Header  |  1996-08-28  |  2KB  |  55 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.  
  15. char* OpenNewFile( HWND hwnd, const char *wndTitle )
  16. {
  17.     static char file[256];
  18.     static char fileTitle[256];
  19.     static char filter[] = "X files (*.x)\0*.x\0"
  20.                            "All Files (*.*)\0*.*\0";
  21.     OPENFILENAME ofn;
  22.  
  23.     lstrcpy( file, "");
  24.     lstrcpy( fileTitle, "");
  25.  
  26.     ofn.lStructSize       = sizeof(OPENFILENAME);
  27.     ofn.hwndOwner         = hwnd;
  28. #ifdef WIN32
  29.     ofn.hInstance         = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
  30. #else
  31.     ofn.hInstance         = (HINSTANCE) GetWindowWord(hwnd, GWW_HINSTANCE);
  32. #endif
  33.     ofn.lpstrFilter       = filter;
  34.     ofn.lpstrCustomFilter = (LPSTR) NULL;
  35.     ofn.nMaxCustFilter    = 0L;
  36.     ofn.nFilterIndex      = 1L;
  37.     ofn.lpstrFile         = file;
  38.     ofn.nMaxFile          = sizeof(file);
  39.     ofn.lpstrFileTitle    = fileTitle;
  40.     ofn.nMaxFileTitle     = sizeof(fileTitle);
  41.     ofn.lpstrInitialDir   = NULL;
  42.     ofn.lpstrTitle        = wndTitle;
  43.     ofn.nFileOffset       = 0;
  44.     ofn.nFileExtension    = 0;
  45.     ofn.lpstrDefExt       = "*.x";
  46.     ofn.lCustData         = 0;
  47.  
  48.     ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  49.  
  50.     if (GetOpenFileName(&ofn))
  51.         return (char*)ofn.lpstrFile;
  52.     else
  53.         return NULL;
  54. }
  55.