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.

84 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. {
  33. ZeroMemory(m_pofn, sizeof(OPENFILENAME));
  34. m_pofn->lStructSize = sizeof(OPENFILENAME);
  35. }
  36. }
  37. COpenFileName::~COpenFileName()
  38. {
  39. delete m_pofn;
  40. }
  41. int COpenFileName::DoModal()
  42. {
  43. int nResult;
  44. if (m_bOpenFileDialog)
  45. {
  46. nResult = ::GetOpenFileName(m_pofn);
  47. }
  48. else
  49. {
  50. nResult = ::GetSaveFileName(m_pofn);
  51. }
  52. if (!nResult && (CDERR_STRUCTSIZE == CommDlgExtendedError()))
  53. {
  54. // if comdlg32 does not recognize the OPENFILENAME size
  55. // retry with the old (ver 4) struct size
  56. m_pofn->lStructSize = OPENFILENAME_SIZE_VERSION_400;
  57. if (m_bOpenFileDialog)
  58. {
  59. nResult = ::GetOpenFileName(m_pofn);
  60. }
  61. else
  62. {
  63. nResult = ::GetSaveFileName(m_pofn);
  64. }
  65. }
  66. return nResult ? nResult : IDCANCEL;
  67. }