1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include "resource.h"
  4. #include <Commdlg.h>
  5. //
  6. // Gobal Variables and declarations.
  7. //
  8. OPENFILENAME ofn ;
  9. // a another memory buffer to contain the file name
  10. char szFile[100] ;
  11. int WINAPI WinMain( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nCmdShow )
  12. {
  13. // open a file name
  14. ZeroMemory( &ofn , sizeof( ofn));
  15. ofn.lStructSize = sizeof ( ofn );
  16. ofn.hwndOwner = NULL ;
  17. ofn.lpstrFile = szFile ;
  18. ofn.lpstrFile[0] = '\0';
  19. ofn.nMaxFile = sizeof( szFile );
  20. ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
  21. ofn.nFilterIndex =1;
  22. ofn.lpstrFileTitle = NULL ;
  23. ofn.nMaxFileTitle = 0 ;
  24. ofn.lpstrInitialDir=NULL ;
  25. ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
  26. GetOpenFileName( &ofn );
  27. // Now simpley display the file name
  28. MessageBox ( NULL , ofn.lpstrFile , "File Name" , MB_OK);
  29. return 0;
  30. }
Advertisements