Counter Strike : Global Offensive Source Code
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.

108 lines
2.5 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxFileDialog.cpp
  5. // implementation: Win32 API
  6. // last modified: Mar 14 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #include "mxtk/mxFileDialog.h"
  15. #include "mxtk/mxWindow.h"
  16. #include <windows.h>
  17. #include <commdlg.h>
  18. #include <string.h>
  19. static char sd_path[_MAX_PATH] = "";
  20. const char*
  21. mxGetOpenFileName (mxWindow *parent, const char *path, const char *filter)
  22. {
  23. CHAR szPath[_MAX_PATH], szFilter[_MAX_PATH];
  24. strcpy (sd_path, "");
  25. if (path)
  26. strcpy (szPath, path);
  27. else
  28. strcpy (szPath, "");
  29. if (filter)
  30. {
  31. memset (szFilter, 0, _MAX_PATH);
  32. strcpy (szFilter, filter);
  33. strcpy (szFilter + strlen (szFilter) + 1, filter);
  34. }
  35. else
  36. strcpy (szFilter, "");
  37. OPENFILENAME ofn;
  38. memset (&ofn, 0, sizeof (ofn));
  39. ofn.lStructSize = sizeof (ofn);
  40. if (parent)
  41. ofn.hwndOwner = (HWND) parent->getHandle ();
  42. ofn.hInstance = (HINSTANCE) GetModuleHandle (NULL);
  43. ofn.lpstrFilter = szFilter;
  44. ofn.nFilterIndex = 1;
  45. ofn.lpstrFile = sd_path;
  46. ofn.nMaxFile = _MAX_PATH;
  47. if (path && strlen (path))
  48. ofn.lpstrInitialDir = szPath;
  49. ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  50. if (GetOpenFileName (&ofn))
  51. return sd_path;
  52. else
  53. return 0;
  54. }
  55. const char*
  56. mxGetSaveFileName (mxWindow *parent, const char *path, const char *filter)
  57. {
  58. CHAR szPath[_MAX_PATH], szFilter[_MAX_PATH];
  59. strcpy (sd_path, "");
  60. if (path)
  61. strcpy (szPath, path);
  62. else
  63. strcpy (szPath, "");
  64. if (filter)
  65. {
  66. memset (szFilter, 0, _MAX_PATH);
  67. strcpy (szFilter, filter);
  68. strcpy (szFilter + strlen (szFilter) + 1, filter);
  69. }
  70. else
  71. strcpy (szFilter, "");
  72. OPENFILENAME ofn;
  73. memset (&ofn, 0, sizeof (ofn));
  74. ofn.lStructSize = sizeof (ofn);
  75. if (parent)
  76. ofn.hwndOwner = (HWND) parent->getHandle ();
  77. ofn.hInstance = (HINSTANCE) GetModuleHandle (NULL);
  78. ofn.lpstrFilter = szFilter;
  79. ofn.lpstrFile = sd_path;
  80. ofn.nMaxFile = _MAX_PATH;
  81. if (path && strlen (path))
  82. ofn.lpstrInitialDir = szPath;
  83. ofn.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  84. if (GetSaveFileName (&ofn))
  85. return sd_path;
  86. else
  87. return 0;
  88. }