Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.8 KiB

  1. #if !defined(WINVER) || (WINVER < 0x0500)
  2. #undef WINVER
  3. #pragma message("Defining WINVER as 0x0500")
  4. #define WINVER 0x0500
  5. #endif //WINVER
  6. #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
  7. #undef _WIN32_WINNT
  8. #pragma message("Defining _WIN32_WINNT as 0x0500")
  9. #define _WIN32_WINNT 0x0500
  10. #endif //_WIN32_WINNT
  11. #if !defined(_WIN32_WINDOWS) || (_WIN32_WINDOWS < 0x0500)
  12. #undef _WIN32_WINDOWS
  13. #pragma message("Defining _WIN32_WINDOWS as 0x0500")
  14. #define _WIN32_WINDOWS 0x0500
  15. #endif //_WIN32_WINDOWS
  16. #if !defined(_WIN32_IE) || (_WIN32_IE < 0x0500)
  17. #undef _WIN32_IE
  18. #pragma message("Defining _WIN32_IE as 0x0500")
  19. #define _WIN32_IE 0x0500
  20. #endif //_WIN32_IE
  21. #include <windows.h>
  22. #include <commdlg.h>
  23. #include <cderr.h>
  24. #include "ofn.h"
  25. ////////////////////////////////////////////////////////////////////////////
  26. //
  27. COpenFileName::COpenFileName(BOOL bOpenFileDialog)
  28. {
  29. m_bOpenFileDialog = bOpenFileDialog;
  30. m_pofn = new OPENFILENAME;
  31. if (m_pofn) {
  32. memset(m_pofn, 0, sizeof(OPENFILENAME));
  33. m_pofn->lStructSize = sizeof(OPENFILENAME);
  34. }
  35. }
  36. COpenFileName::~COpenFileName()
  37. {
  38. delete m_pofn;
  39. }
  40. int COpenFileName::DoModal()
  41. {
  42. int nResult;
  43. if (m_bOpenFileDialog)
  44. nResult = ::GetOpenFileName(m_pofn);
  45. else
  46. nResult = ::GetSaveFileName(m_pofn);
  47. if (!nResult && (CDERR_STRUCTSIZE == CommDlgExtendedError())) {
  48. // if comdlg32 does not recognize the OPENFILENAME size
  49. // retry with the old (ver 4) struct size
  50. m_pofn->lStructSize = OPENFILENAME_SIZE_VERSION_400;
  51. if (m_bOpenFileDialog)
  52. nResult = ::GetOpenFileName(m_pofn);
  53. else
  54. nResult = ::GetSaveFileName(m_pofn);
  55. }
  56. return nResult ? nResult : IDCANCEL;
  57. }