Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/StrRsc/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: 4171 byte(s)
avoid ARRAYSIZE macro
1 #include "OptionDlg.h"
2
3 #include <array>
4 #include <shlwapi.h>
5 #if defined(_MSC_VER)
6 #pragma comment(lib, "shlwapi.lib")
7 #endif
8
9 #include "../../Common/dummy.h"
10 #include "../../Common/StrResource.h"
11
12 #include "DlgOption.h"
13
14 #define RS_OK TEXT("Ok")
15 #define RS_CANCEL TEXT("Cancel")
16
17 extern HINSTANCE g_hInstance;
18
19 namespace Regnessem
20 {
21 namespace AddIn
22 {
23 namespace StrRsc
24 {
25 const LPCTSTR OptionDlg::SectionName = TEXT("general");
26
27 INT_PTR OptionDlg::ShowOptionDialog(const HWND parent) const
28 {
29 return DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_OPTION),parent,DialogFunc,reinterpret_cast<LPARAM>(this));
30 }
31
32 // 特定パス直下のディレクトリのリストを返す
33 void OptionDlg::GetDirList(DirectoryList& list,const tstring &path)
34 {
35 class FindFileHandle
36 {
37 public:
38 HANDLE Handle;
39 FindFileHandle(HANDLE handle)
40 :Handle(handle)
41 {}
42 ~FindFileHandle()
43 {
44 if(Handle != INVALID_HANDLE_VALUE)
45 FindClose(Handle);
46 }
47 };
48
49 list.clear();
50
51 if(!PathFileExists(path.c_str()))
52 return;
53
54 WIN32_FIND_DATA fd;
55 FindFileHandle h(FindFirstFile((path + TEXT("*.*")).c_str(),&fd));
56
57 if(h.Handle == INVALID_HANDLE_VALUE)
58 return;
59
60 do
61 {
62 tstring filename(fd.cFileName);
63 if(filename != TEXT(".") && filename != TEXT("..") &&
64 (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
65 {
66 list.push_back(fd.cFileName);
67 }
68 }while(FindNextFile(h.Handle,&fd));
69 }
70
71 void OptionDlg::OnInitDialog(const HWND hDialog) const
72 {
73 // ダイアログ文字列初期化
74 SetWindowText(hDialog, g_StrResource->GetLocalStr(SectionName, TEXT("DIALOG_CAPTION"), TEXT("Setting")).c_str());
75
76 // ラベル文字列初期化
77 SetDlgItemText(hDialog,IDC_LABEL,g_StrResource->GetLocalStr(SectionName,TEXT("LANG"),TEXT("Language")).c_str());
78 SetDlgItemText(hDialog,IDC_LABEL_CAUTION,g_StrResource->GetLocalStr(SectionName,TEXT("CAUTION")).c_str());
79
80 SetDlgItemText(hDialog,IDOK,
81 StrRsc::g_StrResource->GetLocalStr(SectionName,RS_OK).c_str());
82
83 SetDlgItemText(hDialog,IDCANCEL,
84 StrRsc::g_StrResource->GetLocalStr(SectionName,RS_CANCEL).c_str());
85
86 // ロケール設定
87 std::array<TCHAR, MAX_PATH> exePath;
88 GetModuleFileName(NULL, exePath.data(), std::tuple_size<decltype(exePath)>::value);
89
90 const tstring langDir = ExtractFilePath(exePath.data()) + TEXT("Plugins\\StrRsc\\Language\\");
91
92 DirectoryList localeList;
93
94 GetDirList(localeList,langDir);
95
96 size_t index=0;
97 for(DirectoryList::const_iterator it=localeList.begin();it!=localeList.end();++it,++index)
98 {
99 SendDlgItemMessage(hDialog, IDC_COMBOBOX, CB_INSERTSTRING,index, reinterpret_cast<LPARAM>((*it).c_str()));
100
101 if(Locale == (*it))
102 SendDlgItemMessage(hDialog, IDC_COMBOBOX, CB_SETCURSEL, index, 0);
103 }
104 }
105
106 void OptionDlg::OnEndDialog(const HWND hDialog,const DWORD modalResult)
107 {
108 if(modalResult == IDOK)
109 {
110 const LRESULT index = SendDlgItemMessage(hDialog, IDC_COMBOBOX, CB_GETCURSEL, 0, 0);
111
112 const LRESULT len = SendDlgItemMessage(hDialog, IDC_COMBOBOX, CB_GETLBTEXTLEN, index, 0);
113
114 std::vector<TCHAR> locale(len+1);
115
116 SendDlgItemMessage(hDialog, IDC_COMBOBOX, CB_GETLBTEXT , index, reinterpret_cast<LPARAM>(&locale[0]));
117 Locale = &locale[0];
118 }
119 }
120
121 INT_PTR CALLBACK OptionDlg::DialogFunc(const HWND hDialog,const UINT message,const WPARAM wParam,const LPARAM lParam)
122 {
123 OptionDlg *const dlg = (message != WM_INITDIALOG) ?
124 reinterpret_cast<OptionDlg*>(GetWindowLongPtr(hDialog,GWLP_USERDATA)) : reinterpret_cast<OptionDlg*>(lParam);
125
126 switch(message)
127 {
128 case WM_INITDIALOG:
129 SetWindowLongPtr(hDialog,GWLP_USERDATA,lParam);
130 dlg->OnInitDialog(hDialog);
131 return TRUE;
132 case WM_COMMAND:
133 DWORD id = LOWORD(wParam);
134 switch(id)
135 {
136 case IDCANCEL:
137 case IDOK:
138 dlg->OnEndDialog(hDialog, id);
139 EndDialog(hDialog, id);
140 return TRUE;
141 }
142 break;
143 }
144 return FALSE;
145 }
146 }
147 }
148 }

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