1 #include "precomp.h"
2
3 static OPENFILENAME ofn;
4
5 /*
6 * Initialize file open / save structure
7 */
FileInitialize(HWND hwnd)8 VOID FileInitialize(HWND hwnd)
9 {
10 ZeroMemory(&ofn, sizeof(ofn));
11 ofn.lStructSize = sizeof(OPENFILENAME);
12 ofn.hwndOwner = hwnd;
13 ofn.nMaxFile = MAX_PATH;
14 ofn.nMaxFileTitle = MAX_PATH;
15 ofn.lpstrDefExt = _T("bmp");
16 }
17
18
19 static BOOL
DoWriteFile(LPCTSTR pszFileName)20 DoWriteFile(LPCTSTR pszFileName)
21 {
22 return TRUE;
23 }
24
25
26 BOOL
DoOpenFile(HWND hwnd,LPTSTR szFileName,LPTSTR szTitleName)27 DoOpenFile(HWND hwnd,
28 LPTSTR szFileName,
29 LPTSTR szTitleName)
30 {
31 DWORD err;
32
33 static TCHAR Filter[] = _T("All documents (*.txt,*.rtf)\0*.txt;*.rtf\0") \
34 _T("Rich Text Document (*.rtf)\0*.rtf\0") \
35 _T("Text Document (*.txt)\0*.txt\0");
36
37
38 ofn.lpstrFilter = Filter;
39 ofn.lpstrFile = szFileName;
40 ofn.lpstrFileTitle = szTitleName;
41 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
42
43 if (GetOpenFileName(&ofn))
44 {
45 return TRUE;
46 }
47
48 err = CommDlgExtendedError();
49
50 if (err != CDERR_GENERALCODES)
51 MessageBox(NULL, _T("Open file failed"), NULL, 0);
52
53 return FALSE;
54 }
55
56
57
58 BOOL
DoSaveFile(HWND hwnd)59 DoSaveFile(HWND hwnd)
60 {
61 TCHAR szFileName[MAX_PATH] = _T("");
62 static TCHAR Filter[] = _T("Rich Text Document (*.rtf)\0*.rtf\0") \
63 _T("Text Document (*.txt)\0*.txt\0");
64
65 ofn.lpstrFilter = Filter;
66 ofn.lpstrFile = szFileName;
67 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
68
69 if (GetSaveFileName(&ofn))
70 {
71 if (DoWriteFile(szFileName))
72 return TRUE;
73 }
74
75 if (CommDlgExtendedError() != CDERR_GENERALCODES)
76 MessageBox(NULL, _T("Save to file failed"), NULL, 0);
77
78 return FALSE;
79 }
80
81