FILE.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:2k
源码类别:

Windows编程

开发平台:

Visual C++

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