Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/FileIO/src/OptionDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 119 - (show annotations) (download) (as text)
Fri Oct 8 15:41:45 2010 UTC (13 years, 7 months ago) by kamoya
File MIME type: text/x-c++src
File size: 3419 byte(s)
avoid ARRAYSIZE macro
1 #include "OptionDlg.h"
2
3 #include <vector>
4
5 #include <shlobj.h>
6
7 #include "../../Common/StrResource.h"
8
9 #include "FileIOConfig.h"
10 #include "DlgOption.h"
11
12 extern HINSTANCE g_hInstance;
13
14 namespace Regnessem
15 {
16 namespace AddIn
17 {
18 namespace FileIO
19 {
20 const LPCTSTR OptionDlg::SectionName = TEXT("Dialog");
21
22 const LPCTSTR OptionDlg::KeyName::DialogCaption = TEXT("DialogCaption");
23 const LPCTSTR OptionDlg::KeyName::Ok = TEXT("Ok");
24 const LPCTSTR OptionDlg::KeyName::Cancel = TEXT("Cancel");
25 const LPCTSTR OptionDlg::KeyName::PlaceToStoreReceivedFile = TEXT("PlaceToStoreReceivedFile");
26 const LPCTSTR OptionDlg::KeyName::SelectFilePath = TEXT("SelectFilePath");
27
28 INT_PTR OptionDlg::ShowOptionDialog(HWND parent) const
29 {
30 return DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_OPTION), parent, DialogFunc, reinterpret_cast<LPARAM>(this));
31 }
32
33 void OptionDlg::OnInitDialog(HWND hDialog) const
34 {
35 SetWindowText(hDialog, StrRsc::g_StrResource->GetLocalStr(SectionName, KeyName::DialogCaption).c_str());
36
37 SetDlgItemText(hDialog, IDC_LABEL100,
38 StrRsc::g_StrResource->GetLocalStr(SectionName, KeyName::PlaceToStoreReceivedFile).c_str());
39
40 SetDlgItemText(hDialog, IDOK,
41 StrRsc::g_StrResource->GetLocalStr(SectionName, KeyName::Ok).c_str());
42
43 SetDlgItemText(hDialog, IDCANCEL,
44 StrRsc::g_StrResource->GetLocalStr(SectionName, KeyName::Cancel).c_str());
45
46 //--
47
48 SetDlgItemText(hDialog, IDC_EDTRCVDIR, FileDir.c_str());
49 }
50
51 void OptionDlg::OnEndDialog(HWND hDialog, DWORD modalResult)
52 {
53 if(modalResult == IDOK)
54 {
55 LRESULT len = SendDlgItemMessage(hDialog, IDC_EDTRCVDIR, WM_GETTEXTLENGTH, 0, 0);
56
57 std::vector<TCHAR> fileDir(len + 1);
58
59 SendDlgItemMessage(hDialog, IDC_EDTRCVDIR, WM_GETTEXT, fileDir.size(), reinterpret_cast<LPARAM>(fileDir.data()));
60 FileDir = fileDir.data();
61 }
62 }
63
64 INT_PTR CALLBACK OptionDlg::DialogFunc(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam)
65 {
66 OptionDlg *const dlg = (message != WM_INITDIALOG) ?
67 reinterpret_cast<OptionDlg*>(GetWindowLongPtr(hDialog, GWLP_USERDATA)) : reinterpret_cast<OptionDlg*>(lParam);
68
69 switch(message)
70 {
71 case WM_INITDIALOG:
72 SetWindowLongPtr(hDialog, GWLP_USERDATA, lParam);
73 dlg->OnInitDialog(hDialog);
74 return TRUE;
75 case WM_COMMAND:
76 DWORD id = LOWORD(wParam);
77 switch(id)
78 {
79 case IDOK:
80 case IDCANCEL:
81 dlg->OnEndDialog(hDialog, id);
82 EndDialog(hDialog, id);
83 return TRUE;
84 case IDC_BTNSELFILE:
85 const tstring title =
86 StrRsc::g_StrResource->GetLocalStr(SectionName, KeyName::SelectFilePath, TEXT("�����t�H���_���I��"));
87
88 TCHAR path[MAX_PATH] = {};
89
90 BROWSEINFO browse = {};
91 browse.hwndOwner = hDialog;
92 browse.lpszTitle = title.c_str();
93 browse.ulFlags = BIF_RETURNONLYFSDIRS;
94 browse.pszDisplayName = path;
95
96 if(SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
97 {
98 PIDLIST_ABSOLUTE idList = SHBrowseForFolder(&browse);
99 if(idList)
100 {
101 SHGetPathFromIDList(idList, path);
102 SetDlgItemText(hDialog, IDC_EDTRCVDIR, path);
103 CoTaskMemFree(idList);
104 }
105
106 CoUninitialize();
107 }
108
109 break;
110 }
111 break;
112 }
113
114 return FALSE;
115 }
116 }
117 }
118 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26