1
- // ////////////////////////////////////////////////////////////////////////////////////////
2
- // File: GUIEditorLib.h
3
- // ////////////////////////////////////////////////////////////////////////////////////////
4
- // Description: GUI Editor Library Functions
5
- // Project: GUI Library
6
- // Author(s): Jason Boettcher
7
-
1
+ #include " GUIEditorLib.h"
8
2
9
3
#include < Windows.h>
10
4
#include < commdlg.h>
11
5
#include < direct.h>
12
- #include " GUIEditorLib.h"
13
-
14
-
15
- HINSTANCE g_hInstance = 0 ;
16
- HWND g_hWnd = 0 ;
17
-
18
-
19
- // ////////////////////////////////////////////////////////////////////////////////////////
20
- // Method: QuitMessageBox
21
- // ////////////////////////////////////////////////////////////////////////////////////////
22
- // Description: Call quit messagebox
23
- // Returns: 1 for quit & save, -1 for quit, no save, 0 for cancel
24
-
25
- int GUIEditorLib::QuitMessageBox (string strMessage, string strTitle)
26
- {
27
- int nRetCode = MessageBoxA (g_hWnd, strMessage.c_str (), strTitle.c_str (), MB_YESNOCANCEL);
28
-
29
- if (nRetCode == IDNO)
30
- return -1 ;
31
- if (nRetCode == IDYES)
32
- return 1 ;
33
-
34
- return 0 ; // Cancel
35
- }
36
6
7
+ namespace GUI {
37
8
38
- // ////////////////////////////////////////////////////////////////////////////////////////
39
- // Method: DisplayLoadGUIFile
40
- // ////////////////////////////////////////////////////////////////////////////////////////
41
- // Description: Display load gui file OS dialog box
9
+ HINSTANCE g_hInstance = 0 ;
10
+ HWND g_hWnd = 0 ;
42
11
43
- bool GUIEditorLib::DisplayLoadGUIFile (string *strFilename)
44
- {
45
- OPENFILENAMEA ofn; // common dialog box structure
46
- char szFile[260 ]; // File name
12
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47
13
48
- // Save the current working directory
49
- char szCurrentDir[_MAX_PATH];
50
- _getcwd (szCurrentDir,_MAX_PATH);
14
+ int GUIEditorLib::QuitMessageBox (std::string strMessage, std::string strTitle) {
15
+ int nRetCode = MessageBoxA (g_hWnd, strMessage.c_str (), strTitle.c_str (), MB_YESNOCANCEL);
51
16
52
- // Clear the filename (otherwise it won't work)
53
- memset (szFile, 0 , sizeof (szFile));
54
-
55
- // Initialize OPENFILENAME
56
- ZeroMemory (&ofn, sizeof (OPENFILENAME));
57
- ofn.lStructSize = sizeof (OPENFILENAME);
58
- ofn.hInstance = g_hInstance;
59
- ofn.hwndOwner = g_hWnd;
60
- ofn.lpstrFile = szFile;
61
- ofn.nMaxFile = sizeof (szFile);
62
- ofn.lpstrFilter = " GUI Files (*.ini)\0 *.ini\0 All Files\0 *.*" ;
63
- ofn.nFilterIndex = 1 ;
64
- ofn.lpstrFileTitle = NULL ;
65
- ofn.nMaxFileTitle = 0 ;
66
- ofn.lpstrTitle = " Open" ;
67
- ofn.lpstrInitialDir = szCurrentDir;
68
- ofn.Flags = OFN_PATHMUSTEXIST;
69
- ofn.lpstrDefExt = " ini" ;
70
-
71
- if (GetOpenFileNameA (&ofn)) {
17
+ if (nRetCode == IDNO) { return -1 ; }
18
+ if (nRetCode == IDYES) { return 1 ; }
19
+ return 0 ; // Cancel
20
+ }
72
21
73
- *strFilename = string (szFile);
22
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
23
+
24
+ bool GUIEditorLib::DisplayLoadGUIFile (std::string *strFilename) {
25
+ OPENFILENAMEA ofn; // common dialog box structure
26
+ char szFile[260 ]; // File name
27
+
28
+ // Save the current working directory
29
+ char szCurrentDir[_MAX_PATH];
30
+ _getcwd (szCurrentDir, _MAX_PATH);
31
+
32
+ // Clear the filename (otherwise it won't work)
33
+ memset (szFile, 0 , sizeof (szFile));
34
+
35
+ // Initialize OPENFILENAME
36
+ ZeroMemory (&ofn, sizeof (OPENFILENAME));
37
+ ofn.lStructSize = sizeof (OPENFILENAME);
38
+ ofn.hInstance = g_hInstance;
39
+ ofn.hwndOwner = g_hWnd;
40
+ ofn.lpstrFile = szFile;
41
+ ofn.nMaxFile = sizeof (szFile);
42
+ ofn.lpstrFilter = " GUI Files (*.ini)\0 *.ini\0 All Files\0 *.*" ;
43
+ ofn.nFilterIndex = 1 ;
44
+ ofn.lpstrFileTitle = NULL ;
45
+ ofn.nMaxFileTitle = 0 ;
46
+ ofn.lpstrTitle = " Open" ;
47
+ ofn.lpstrInitialDir = szCurrentDir;
48
+ ofn.Flags = OFN_PATHMUSTEXIST;
49
+ ofn.lpstrDefExt = " ini" ;
50
+
51
+ if (GetOpenFileNameA (&ofn)) {
52
+ *strFilename = std::string (szFile);
53
+ _chdir (szCurrentDir);
54
+ return true ;
55
+ }
74
56
_chdir (szCurrentDir);
75
-
76
- return true ;
57
+ return false ;
77
58
}
78
59
79
- _chdir (szCurrentDir);
80
- return false ;
81
- }
82
-
83
-
84
- // ////////////////////////////////////////////////////////////////////////////////////////
85
- // Method: DisplaySaveGUIFile
86
- // ////////////////////////////////////////////////////////////////////////////////////////
87
- // Description: Display save gui file OS dialog box
88
-
89
- bool GUIEditorLib::DisplaySaveGUIFile (string *strFilename)
90
- {
91
- OPENFILENAMEA ofn; // common dialog box structure
92
- char szFile[260 ]; // File name
93
-
94
- // Save the current working directory
95
- char szCurrentDir[_MAX_PATH];
96
- _getcwd (szCurrentDir,_MAX_PATH);
97
-
98
- // Clear the filename (otherwise it won't work)
99
- memset (szFile, 0 , sizeof (szFile));
100
-
101
- // Initialize OPENFILENAME
102
- ZeroMemory (&ofn, sizeof (OPENFILENAME));
103
- ofn.lStructSize = sizeof (OPENFILENAME);
104
- ofn.hInstance = g_hInstance;
105
- ofn.hwndOwner = g_hWnd;
106
- ofn.lpstrFile = szFile;
107
- ofn.nMaxFile = sizeof (szFile);
108
- ofn.lpstrFilter = " GUI Files (*.ini)\0 *.ini\0 All Files\0 *.*" ;
109
- ofn.nFilterIndex = 1 ;
110
- ofn.lpstrFileTitle = NULL ;
111
- ofn.nMaxFileTitle = 0 ;
112
- ofn.lpstrTitle = " Save As" ;
113
- ofn.lpstrInitialDir = szCurrentDir;
114
- ofn.Flags = OFN_PATHMUSTEXIST;
115
- ofn.lpstrDefExt = " ini" ;
116
-
117
- if (GetSaveFileNameA (&ofn)) {
118
-
119
- // Check if the file exists
120
- FILE *fp = fopen (szFile," rt" );
121
- if ( fp ) {
122
- fclose (fp);
123
- if (MessageBoxA (g_hWnd, " File Exists\n Overwrite it?" , " Confirmation" ,MB_YESNO) == IDNO) {
124
- _chdir (szCurrentDir);
125
- return false ;
60
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61
+
62
+ bool GUIEditorLib::DisplaySaveGUIFile (std::string *strFilename) {
63
+ OPENFILENAMEA ofn; // common dialog box structure
64
+ char szFile[260 ]; // File name
65
+
66
+ // Save the current working directory
67
+ char szCurrentDir[_MAX_PATH];
68
+ _getcwd (szCurrentDir, _MAX_PATH);
69
+
70
+ // Clear the filename (otherwise it won't work)
71
+ memset (szFile, 0 , sizeof (szFile));
72
+
73
+ // Initialize OPENFILENAME
74
+ ZeroMemory (&ofn, sizeof (OPENFILENAME));
75
+ ofn.lStructSize = sizeof (OPENFILENAME);
76
+ ofn.hInstance = g_hInstance;
77
+ ofn.hwndOwner = g_hWnd;
78
+ ofn.lpstrFile = szFile;
79
+ ofn.nMaxFile = sizeof (szFile);
80
+ ofn.lpstrFilter = " GUI Files (*.ini)\0 *.ini\0 All Files\0 *.*" ;
81
+ ofn.nFilterIndex = 1 ;
82
+ ofn.lpstrFileTitle = NULL ;
83
+ ofn.nMaxFileTitle = 0 ;
84
+ ofn.lpstrTitle = " Save As" ;
85
+ ofn.lpstrInitialDir = szCurrentDir;
86
+ ofn.Flags = OFN_PATHMUSTEXIST;
87
+ ofn.lpstrDefExt = " ini" ;
88
+
89
+ if (GetSaveFileNameA (&ofn)) {
90
+ // Check if the file exists
91
+ FILE *fp = fopen (szFile, " rt" );
92
+ if (fp) {
93
+ fclose (fp);
94
+ if (MessageBoxA (g_hWnd, " File Exists\n Overwrite it?" , " Confirmation" , MB_YESNO) == IDNO) {
95
+ _chdir (szCurrentDir);
96
+ return false ;
97
+ }
126
98
}
99
+ *strFilename = std::string (szFile);
100
+ _chdir (szCurrentDir);
101
+ return true ;
127
102
}
128
- *strFilename = string (szFile);
103
+ // Restore the current working directory
129
104
_chdir (szCurrentDir);
130
-
131
- return true ;
105
+ return false ;
132
106
}
133
-
134
- // Restore the current working directory
135
- _chdir (szCurrentDir);
136
-
137
- return false ;
138
107
}
0 commit comments