-
Notifications
You must be signed in to change notification settings - Fork 6
/
SaveDlg.cpp
76 lines (54 loc) · 1.71 KB
/
SaveDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "stdafx.h"
#include "resource.h"
#include "SaveDlg.h"
#include "SettingsStorage.h"
CSaveDlg::CSaveDlg()
{
//m_psp.dwFlags |= PSP_USEICONID;
//m_psp.pszIcon = MAKEINTRESOURCE(IDI_SETTINGS);
//m_psp.hInstance = _Module.GetResourceInstance();
}
BOOL CSaveDlg::OnInitDialog ( HWND hwndFocus, LPARAM lParam )
{
SettingsStorage& store = SettingsStorage::GetStorage();
CheckDlgButton(IDC_CHECK_SAVE_TO_FILE, store.GetSaveToFile() ? BST_CHECKED : BST_UNCHECKED);
CRichEditCtrl edit(GetDlgItem(IDC_EDIT_FILENAME));
edit.SetWindowText(store.GetSaveFilename());
return 1;
}
LRESULT CSaveDlg::OnChooseSaveFilename(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
OPENFILENAME FileInfo;
memset(&FileInfo, 0, sizeof(FileInfo));
char szFileName[2048];
szFileName[0] = 0;
FileInfo.lStructSize = sizeof(FileInfo);
FileInfo.lpstrFilter = ".txt";
FileInfo.lpstrFile = szFileName;
FileInfo.nMaxFile = sizeof(szFileName);
FileInfo.Flags = OFN_EXPLORER;
FileInfo.lpstrTitle = "Save as...";
if (GetSaveFileName(&FileInfo))
{
CString filename(szFileName);
if (-1 == filename.Find("."))
filename += ".txt";
CRichEditCtrl edit(GetDlgItem(IDC_EDIT_FILENAME));
edit.SetWindowText(filename);
}
return 0;
}
void CSaveDlg::SaveSettings()
{
CString filename;
CRichEditCtrl edit(GetDlgItem(IDC_EDIT_FILENAME));
edit.GetWindowText(filename);
SettingsStorage& store = SettingsStorage::GetStorage();
store.SetSaveToFile(BST_CHECKED == IsDlgButtonChecked(IDC_CHECK_SAVE_TO_FILE));
store.SetSaveFilename(filename);
}
int CSaveDlg::OnApply()
{
SaveSettings();
return 1;
}