1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2011 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | // |
---|
5 | // $Id: MainDialog.h 30 2011-10-18 07:36:17Z roman $ |
---|
6 | |
---|
7 | #pragma once |
---|
8 | |
---|
9 | #include "AboutDialog.h" |
---|
10 | |
---|
11 | //////////////////////////////////////////////////////////// |
---|
12 | // CMainDialog |
---|
13 | |
---|
14 | class CMainDialog : |
---|
15 | public CAxDialogImpl<CMainDialog> |
---|
16 | { |
---|
17 | public: |
---|
18 | enum { IDD = IDD_MAIN }; |
---|
19 | |
---|
20 | BEGIN_MSG_MAP_EX(CMainDialog) |
---|
21 | CHAIN_MSG_MAP(CAxDialogImpl<CMainDialog>) |
---|
22 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
23 | MSG_WM_DESTROY(OnDestroy) |
---|
24 | MSG_WM_CHANGECBCHAIN(OnChangeCbChain) |
---|
25 | MSG_WM_DRAWCLIPBOARD(OnDrawClipboard) |
---|
26 | MSG_WM_SYSCOMMAND(OnSysCommand) |
---|
27 | COMMAND_ID_HANDLER_EX(IDCANCEL, OnCommand) |
---|
28 | NOTIFY_RANGE_CODE_HANDLER_EX(IDC_MAIN_DEGREES_LATITUDE, IDC_MAIN_DEGREESMINUTESSECONDS_LONGITUDELATITUDE, CRoHyperStatic::NC_ANCHORCLICKED, OnStaticAnchorClicked) |
---|
29 | MSG_WM_HOTKEY(OnHotKey) |
---|
30 | REFLECT_NOTIFICATIONS() |
---|
31 | END_MSG_MAP() |
---|
32 | |
---|
33 | private: |
---|
34 | CRoIconStatic m_IntroductionStatic; |
---|
35 | CRoHyperStatic m_pStatics[12]; |
---|
36 | CRoHyperStatic m_GoogleMapsStatic; |
---|
37 | CRoHyperStatic m_YandexMapsStatic; |
---|
38 | BOOL m_bSetClipboardTextActive; |
---|
39 | CWindow m_NextClipboardViewerWindow; |
---|
40 | |
---|
41 | public: |
---|
42 | // CMainDialog |
---|
43 | CMainDialog() |
---|
44 | { |
---|
45 | } |
---|
46 | VOID SetLocation(DOUBLE fLatitude, DOUBLE fLongitude) |
---|
47 | { |
---|
48 | CString psTexts[12]; |
---|
49 | CString sGoogleMapsLocation, sYandexMapsLocation; |
---|
50 | #pragma region Degrees |
---|
51 | { |
---|
52 | const CString sLatitude = _StringHelper::FormatNumber(fLatitude, 6, FALSE); |
---|
53 | const CString sLongitude = _StringHelper::FormatNumber(fLongitude, 6, FALSE); |
---|
54 | psTexts[0] = sLatitude; |
---|
55 | psTexts[1] = sLongitude; |
---|
56 | psTexts[2] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); |
---|
57 | psTexts[3] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); |
---|
58 | sGoogleMapsLocation = AtlFormatString(_T("http://maps.google.com/maps/?ll=%s,%s"), sLatitude, sLongitude); |
---|
59 | sYandexMapsLocation = AtlFormatString(_T("http://maps.yandex.ru/?ll=%s,%s"), sLongitude, sLatitude); |
---|
60 | } |
---|
61 | #pragma endregion |
---|
62 | #pragma region Degrees, Minutes |
---|
63 | { |
---|
64 | CString sLatitude, sLongitude; |
---|
65 | #pragma region Latitude |
---|
66 | sLatitude.Append((fLatitude >= 0) ? _T("N ") : _T("S ")); |
---|
67 | DOUBLE fPartialLatitude = abs(fLatitude); |
---|
68 | const INT nPartialLatitude = (INT) fPartialLatitude; |
---|
69 | sLatitude.AppendFormat(_T("%02d "), nPartialLatitude); |
---|
70 | const DOUBLE fPartialLatitudeMinute = (fPartialLatitude - nPartialLatitude) * 60; |
---|
71 | const INT nPartialLatitudeMinute = (INT) fPartialLatitudeMinute; |
---|
72 | sLatitude.AppendFormat(_T("%02d"), nPartialLatitudeMinute); |
---|
73 | sLatitude.AppendFormat(_T(".%03d "), (INT) ((fPartialLatitudeMinute - nPartialLatitudeMinute) * 1000 + 0.5 - 1E-6)); |
---|
74 | #pragma endregion |
---|
75 | #pragma region Latitude |
---|
76 | sLongitude.Append((fLongitude >= 0) ? _T("E ") : _T("W ")); |
---|
77 | DOUBLE fPartialLongitude = abs(fLongitude); |
---|
78 | const INT nPartialLongitude = (INT) fPartialLongitude; |
---|
79 | sLongitude.AppendFormat(_T("%03d "), nPartialLongitude); |
---|
80 | const DOUBLE fPartialLongitudeMinute = (fPartialLongitude - nPartialLongitude) * 60; |
---|
81 | const INT nPartialLongitudeMinute = (INT) fPartialLongitudeMinute; |
---|
82 | sLongitude.AppendFormat(_T("%02d"), nPartialLongitudeMinute); |
---|
83 | sLongitude.AppendFormat(_T(".%03d "), (INT) ((fPartialLongitudeMinute - nPartialLongitudeMinute) * 1000 + 0.5 - 1E-6)); |
---|
84 | #pragma endregion |
---|
85 | psTexts[4] = sLatitude; |
---|
86 | psTexts[5] = sLongitude; |
---|
87 | psTexts[6] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); |
---|
88 | psTexts[7] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); |
---|
89 | } |
---|
90 | #pragma endregion |
---|
91 | #pragma region Degrees, Minutes, Seconds |
---|
92 | { |
---|
93 | CString sLatitude, sLongitude; |
---|
94 | #pragma region Latitude |
---|
95 | sLatitude.Append((fLatitude >= 0) ? _T("N ") : _T("S ")); |
---|
96 | DOUBLE fPartialLatitude = abs(fLatitude); |
---|
97 | const INT nPartialLatitude = (INT) fPartialLatitude; |
---|
98 | sLatitude.AppendFormat(_T("%02d "), nPartialLatitude); |
---|
99 | const DOUBLE fPartialLatitudeMinute = (fPartialLatitude - nPartialLatitude) * 60; |
---|
100 | const INT nPartialLatitudeMinute = (INT) fPartialLatitudeMinute; |
---|
101 | sLatitude.AppendFormat(_T("%02d "), nPartialLatitudeMinute); |
---|
102 | const DOUBLE fPartialLatitudeSecond = (fPartialLatitudeMinute - nPartialLatitudeMinute) * 60; |
---|
103 | const INT nPartialLatitudeSecond = (INT) fPartialLatitudeSecond; |
---|
104 | sLatitude.AppendFormat(_T("%02d"), nPartialLatitudeSecond); |
---|
105 | sLatitude.AppendFormat(_T(".%02d "), (INT) ((fPartialLatitudeSecond - nPartialLatitudeSecond) * 100 + 0.5 - 1E-6)); |
---|
106 | #pragma endregion |
---|
107 | #pragma region Latitude |
---|
108 | sLongitude.Append((fLongitude >= 0) ? _T("E ") : _T("W ")); |
---|
109 | DOUBLE fPartialLongitude = abs(fLongitude); |
---|
110 | INT nPartialLongitude = (INT) fPartialLongitude; |
---|
111 | sLongitude.AppendFormat(_T("%03d "), nPartialLongitude); |
---|
112 | DOUBLE fPartialLongitudeMinute = (fPartialLongitude - nPartialLongitude) * 60; |
---|
113 | INT nPartialLongitudeMinute = (INT) fPartialLongitudeMinute; |
---|
114 | sLongitude.AppendFormat(_T("%02d "), nPartialLongitudeMinute); |
---|
115 | const DOUBLE fPartialLongitudeSecond = (fPartialLongitudeMinute - nPartialLongitudeMinute) * 60; |
---|
116 | const INT nPartialLongitudeSecond = (INT) fPartialLongitudeSecond; |
---|
117 | sLongitude.AppendFormat(_T("%02d"), nPartialLongitudeSecond); |
---|
118 | sLongitude.AppendFormat(_T(".%02d "), (INT) ((fPartialLongitudeSecond - nPartialLongitudeSecond) * 100 + 0.5 - 1E-6)); |
---|
119 | #pragma endregion |
---|
120 | psTexts[ 8] = sLatitude; |
---|
121 | psTexts[ 9] = sLongitude; |
---|
122 | psTexts[10] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); |
---|
123 | psTexts[11] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); |
---|
124 | } |
---|
125 | #pragma endregion |
---|
126 | for(SIZE_T nIndex = 0; nIndex < 12; nIndex++) |
---|
127 | m_pStatics[nIndex].SetWindowText(AtlFormatString(_T("<A HREF=\"%s\">%s</A> (F%d)"), psTexts[nIndex], psTexts[nIndex], nIndex + 1)); |
---|
128 | m_GoogleMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Google Maps\" HREF=\"%s\">%s</A>"), sGoogleMapsLocation, sGoogleMapsLocation)); |
---|
129 | m_YandexMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Yandex Maps\" HREF=\"%s\">%s</A>"), sYandexMapsLocation, sYandexMapsLocation)); |
---|
130 | } |
---|
131 | BOOL SetText(const CString& sText) |
---|
132 | { |
---|
133 | if(sText.GetLength() >= 4096) |
---|
134 | return FALSE; |
---|
135 | CRoReMatchContext MatchContext; |
---|
136 | #pragma region Google Maps |
---|
137 | static CAtlStaticRegExp<> g_ExpressionA(_T("^ *(http://)?[^/]*maps.google[^/]*/.+?") _T("ll={[\\.0-9]+},{[\\.0-9]+}"), FALSE); |
---|
138 | if(g_ExpressionA.Match(sText, &MatchContext)) |
---|
139 | { |
---|
140 | DOUBLE fLatitude, fLongitude; |
---|
141 | if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLatitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLongitude)) |
---|
142 | return FALSE; |
---|
143 | SetLocation(fLatitude, fLongitude); |
---|
144 | return TRUE; |
---|
145 | } |
---|
146 | #pragma endregion |
---|
147 | #pragma region Yandex Maps |
---|
148 | static CAtlStaticRegExp<> g_ExpressionB(_T("^ *(http://)?[^/]*maps.yandex[^/]*/.+?") _T("ll={[\\.0-9]+}(,|(\\%2C)){[\\.0-9]+}"), FALSE); |
---|
149 | if(g_ExpressionB.Match(sText, &MatchContext)) |
---|
150 | { |
---|
151 | DOUBLE fLatitude, fLongitude; |
---|
152 | if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLongitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLatitude)) |
---|
153 | return FALSE; |
---|
154 | SetLocation(fLatitude, fLongitude); |
---|
155 | return TRUE; |
---|
156 | } |
---|
157 | #pragma endregion |
---|
158 | #pragma region Degrees and Minutes |
---|
159 | static CAtlStaticRegExp<> g_ExpressionD0(_T("^[\t ]*") |
---|
160 | _T("{[NSCÞ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") |
---|
161 | _T("[^0-9\\.]+?") |
---|
162 | _T("{[EWÂÇ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") |
---|
163 | _T(""), FALSE); |
---|
164 | static CAtlStaticRegExp<> g_ExpressionD1(_T("^[\t ]*") |
---|
165 | _T("{[EWÂÇ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") |
---|
166 | _T("[^0-9\\.]+?") |
---|
167 | _T("{[NSCÞ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") |
---|
168 | _T(""), FALSE); |
---|
169 | static CAtlStaticRegExp<> g_ExpressionD2(_T("^[\t ]*") |
---|
170 | _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") _T("[\t ]*") _T("{[NSCÞ]}") |
---|
171 | _T("[^0-9\\.]+?") |
---|
172 | _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") _T("[\t ]*") _T("{[EWÂÇ]}") |
---|
173 | _T(""), FALSE); |
---|
174 | static CAtlStaticRegExp<> g_ExpressionD3(_T("^[\t ]*") |
---|
175 | _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") _T("[\t ]*") _T("{[EWÂÇ]}") |
---|
176 | _T("[^0-9\\.]+?") |
---|
177 | _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") _T("[\t ]*") _T("{[NSCÞ]}") |
---|
178 | _T(""), FALSE); |
---|
179 | INT nLayoutD = -1; |
---|
180 | if(g_ExpressionD0.Match(sText, &MatchContext)) |
---|
181 | nLayoutD = 0; |
---|
182 | else if(g_ExpressionD1.Match(sText, &MatchContext)) |
---|
183 | nLayoutD = 1; |
---|
184 | else if(g_ExpressionD2.Match(sText, &MatchContext)) |
---|
185 | nLayoutD = 2; |
---|
186 | else if(g_ExpressionD3.Match(sText, &MatchContext)) |
---|
187 | nLayoutD = 3; |
---|
188 | if(nLayoutD >= 0) |
---|
189 | { |
---|
190 | static const SIZE_T g_pnMap[4][6] = |
---|
191 | { |
---|
192 | { 0, 1, 2, 3, 4, 5, }, |
---|
193 | { 3, 4, 5, 0, 1, 2, }, |
---|
194 | { 2, 0, 1, 5, 3, 4, }, |
---|
195 | { 5, 3, 4, 2, 0, 1, }, |
---|
196 | }; |
---|
197 | const INT nLatitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutD][0]).FindOneOf(_T("SsÞþ")) >= 0) ? -1 : 1; |
---|
198 | const INT nLongitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutD][3]).FindOneOf(_T("WwÇç")) >= 0) ? -1 : 1; |
---|
199 | INT nLatitudeDegrees, nLongitudeDegrees; |
---|
200 | DOUBLE fLatitudeMinutes, fLongitudeMinutes; |
---|
201 | if(FALSE || |
---|
202 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutD][1]), nLatitudeDegrees) || |
---|
203 | !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutD][2]), fLatitudeMinutes) || |
---|
204 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutD][4]), nLongitudeDegrees) || |
---|
205 | !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutD][5]), fLongitudeMinutes) || |
---|
206 | FALSE) |
---|
207 | return FALSE; |
---|
208 | _A(fLatitudeMinutes >= 0 && fLongitudeMinutes >= 0); |
---|
209 | if(fLatitudeMinutes >= 60.0 || fLongitudeMinutes >= 60.0) |
---|
210 | return FALSE; |
---|
211 | const DOUBLE fLatitude = nLatitudeSign * (nLatitudeDegrees + fLatitudeMinutes / 60.0); |
---|
212 | const DOUBLE fLongitude = nLongitudeSign * (nLongitudeDegrees + fLongitudeMinutes / 60.0); |
---|
213 | SetLocation(fLatitude, fLongitude); |
---|
214 | return TRUE; |
---|
215 | } |
---|
216 | #pragma endregion |
---|
217 | #pragma region Degrees, Minutes and Seconds |
---|
218 | static CAtlStaticRegExp<> g_ExpressionE0(_T("^[\t ]*") |
---|
219 | _T("{[NSCÞ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") |
---|
220 | _T("[^0-9\\.]+?") |
---|
221 | _T("{[EWÂÇ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") |
---|
222 | _T(""), FALSE); |
---|
223 | static CAtlStaticRegExp<> g_ExpressionE1(_T("^[\t ]*") |
---|
224 | _T("{[EWÂÇ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") |
---|
225 | _T("[^0-9\\.]+?") |
---|
226 | _T("{[NSCÞ]}") _T("[\t ]*") _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") |
---|
227 | _T(""), FALSE); |
---|
228 | static CAtlStaticRegExp<> g_ExpressionE2(_T("^[\t ]*") |
---|
229 | _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") _T("[\t ]*") _T("{[NSCÞ]}") |
---|
230 | _T("[^0-9\\.]+?") |
---|
231 | _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") _T("[\t ]*") _T("{[EWÂÇ]}") |
---|
232 | _T(""), FALSE); |
---|
233 | static CAtlStaticRegExp<> g_ExpressionE3(_T("^[\t ]*") |
---|
234 | _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") _T("[\t ]*") _T("{[EWÂÇ]}") |
---|
235 | _T("[^0-9\\.]+?") |
---|
236 | _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+}") _T("[\t ]*") _T("{[NSCÞ]}") |
---|
237 | _T(""), FALSE); |
---|
238 | INT nLayoutE = -1; |
---|
239 | if(g_ExpressionE0.Match(sText, &MatchContext)) |
---|
240 | nLayoutE = 0; |
---|
241 | else if(g_ExpressionE1.Match(sText, &MatchContext)) |
---|
242 | nLayoutE = 1; |
---|
243 | else if(g_ExpressionE2.Match(sText, &MatchContext)) |
---|
244 | nLayoutE = 2; |
---|
245 | else if(g_ExpressionE3.Match(sText, &MatchContext)) |
---|
246 | nLayoutE = 3; |
---|
247 | if(nLayoutE >= 0) |
---|
248 | { |
---|
249 | static const SIZE_T g_pnMap[4][8] = |
---|
250 | { |
---|
251 | { 0, 1, 2, 3, 4, 5, 6, 7, }, |
---|
252 | { 4, 5, 6, 7, 0, 1, 2, 3, }, |
---|
253 | { 3, 0, 1, 2, 7, 4, 5, 6, }, |
---|
254 | { 7, 4, 5, 6, 3, 0, 1, 2, }, |
---|
255 | }; |
---|
256 | const INT nLatitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutE][0]).FindOneOf(_T("SsÞþ")) >= 0) ? -1 : 1; |
---|
257 | const INT nLongitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutE][4]).FindOneOf(_T("WwÇç")) >= 0) ? -1 : 1; |
---|
258 | INT nLatitudeDegrees, nLongitudeDegrees; |
---|
259 | INT nLatitudeMinutes, nLongitudeMinutes; |
---|
260 | INT nLatitudeSeconds, nLongitudeSeconds; |
---|
261 | if(FALSE || |
---|
262 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][1]), nLatitudeDegrees) || |
---|
263 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][2]), nLatitudeMinutes) || |
---|
264 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][3]), nLatitudeSeconds) || |
---|
265 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][5]), nLongitudeDegrees) || |
---|
266 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][6]), nLongitudeMinutes) || |
---|
267 | !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][7]), nLongitudeSeconds) || |
---|
268 | FALSE) |
---|
269 | return FALSE; |
---|
270 | _A(nLatitudeMinutes >= 0 && nLongitudeMinutes >= 0); |
---|
271 | if(nLatitudeMinutes >= 60 || nLongitudeMinutes >= 60) |
---|
272 | return FALSE; |
---|
273 | _A(nLatitudeSeconds >= 0 && nLongitudeSeconds >= 0); |
---|
274 | if(nLatitudeSeconds >= 60 || nLongitudeSeconds >= 60) |
---|
275 | return FALSE; |
---|
276 | const DOUBLE fLatitude = nLatitudeSign * (nLatitudeDegrees + (nLatitudeMinutes + nLatitudeSeconds / 60.0) / 60.0); |
---|
277 | const DOUBLE fLongitude = nLongitudeSign * (nLongitudeDegrees + (nLongitudeMinutes + nLongitudeSeconds / 60.0) / 60.0); |
---|
278 | SetLocation(fLatitude, fLongitude); |
---|
279 | return TRUE; |
---|
280 | } |
---|
281 | #pragma endregion |
---|
282 | #pragma region Degrees, Latitude and Longitude |
---|
283 | static CAtlStaticRegExp<> g_ExpressionC(_T("^ *") _T("{-?[0-9]+\\.[0-9]+}") _T("[^0-9\\.]+") _T("{-?[0-9]+\\.[0-9]+}"), FALSE); |
---|
284 | if(g_ExpressionC.Match(sText, &MatchContext)) |
---|
285 | { |
---|
286 | DOUBLE fLatitude, fLongitude; |
---|
287 | if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLatitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLongitude)) |
---|
288 | return FALSE; |
---|
289 | SetLocation(fLatitude, fLongitude); |
---|
290 | return TRUE; |
---|
291 | } |
---|
292 | #pragma endregion |
---|
293 | return FALSE; |
---|
294 | } |
---|
295 | BOOL SetText(LPCTSTR pszText) |
---|
296 | { |
---|
297 | return SetText(CString(pszText)); |
---|
298 | } |
---|
299 | |
---|
300 | // Window message handelrs |
---|
301 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
302 | { |
---|
303 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE); |
---|
304 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE); |
---|
305 | CMenuHandle Menu = GetSystemMenu(FALSE); |
---|
306 | _W(Menu.AppendMenu(MF_SEPARATOR)); |
---|
307 | _W(Menu.AppendMenu(MF_STRING, ID_APP_ABOUT, _T("&About..."))); |
---|
308 | _W(m_IntroductionStatic.SubclassWindow(GetDlgItem(IDC_MAIN_INTRODUCTION))); |
---|
309 | for(SIZE_T nIndex = 0; nIndex < 12; nIndex++) |
---|
310 | _W(m_pStatics[nIndex].SubclassWindow(GetDlgItem(IDC_MAIN_DEGREES_LATITUDE + nIndex))); |
---|
311 | _W(m_GoogleMapsStatic.SubclassWindow(GetDlgItem(IDC_MAIN_GOOGLEMAPS))); |
---|
312 | _W(m_YandexMapsStatic.SubclassWindow(GetDlgItem(IDC_MAIN_YANDEXMAPS))); |
---|
313 | _W(CenterWindow()); |
---|
314 | m_bSetClipboardTextActive = FALSE; |
---|
315 | m_NextClipboardViewerWindow = SetClipboardViewer(); |
---|
316 | for(SIZE_T nIndex = 0; nIndex < 12; nIndex++) |
---|
317 | _W(RegisterHotKey(m_hWnd, (INT) nIndex, MOD_CONTROL | MOD_SHIFT, VK_F1 + nIndex)); |
---|
318 | #if _DEVELOPMENT |
---|
319 | //SetText(_T("http://maps.google.com.ua/maps/ms?msid=206853065838475655514.0004af0a0899ed541f5f2&msa=0&ll=45.296505,35.771999&spn=0.039547,0.095272")); |
---|
320 | //SetText(_T("http://maps.yandex.ru/?ll=13.376147%2C45.797846&spn=2.820740%2C1.127727&z=9&l=map")); |
---|
321 | #endif // _DEVELOPMENT |
---|
322 | return TRUE; |
---|
323 | } |
---|
324 | LRESULT OnDestroy() throw() |
---|
325 | { |
---|
326 | for(SIZE_T nIndex = 0; nIndex < 12; nIndex++) |
---|
327 | _W(UnregisterHotKey(m_hWnd, (INT) nIndex)); |
---|
328 | _W(ChangeClipboardChain(m_NextClipboardViewerWindow)); |
---|
329 | return 0; |
---|
330 | } |
---|
331 | LRESULT OnChangeCbChain(CWindow RemovedWindow, CWindow NextWindow) |
---|
332 | { |
---|
333 | if(m_NextClipboardViewerWindow == RemovedWindow) |
---|
334 | m_NextClipboardViewerWindow = NextWindow; |
---|
335 | else if(m_NextClipboardViewerWindow) |
---|
336 | m_NextClipboardViewerWindow.SendMessage(WM_CHANGECBCHAIN, (WPARAM) (HWND) RemovedWindow, (LPARAM) (HWND) NextWindow); |
---|
337 | return 0; |
---|
338 | } |
---|
339 | LRESULT OnDrawClipboard() |
---|
340 | { |
---|
341 | if(m_bSetClipboardTextActive) |
---|
342 | return 0; |
---|
343 | if(OpenClipboard()) |
---|
344 | { |
---|
345 | _ATLTRY |
---|
346 | { |
---|
347 | if(IsClipboardFormatAvailable(CF_UNICODETEXT)) |
---|
348 | { |
---|
349 | CGlobalMemoryWeakHandle DataHandle = (HGLOBAL) GetClipboardData(CF_UNICODETEXT); |
---|
350 | __E(DataHandle); |
---|
351 | CGlobalMemoryHandle::CLockT<WCHAR> pszData(DataHandle); |
---|
352 | if(SetText(CW2CT(pszData))) |
---|
353 | { |
---|
354 | FLASHWINFO FlashWindowInformation = { sizeof FlashWindowInformation, m_hWnd, FLASHW_CAPTION, 5 }; |
---|
355 | _W(FlashWindowEx(&FlashWindowInformation)); |
---|
356 | //MessageBeep(MB_OK); |
---|
357 | } |
---|
358 | } |
---|
359 | } |
---|
360 | _ATLCATCHALL() |
---|
361 | { |
---|
362 | _W(CloseClipboard()); |
---|
363 | _ATLRETHROW; |
---|
364 | } |
---|
365 | _W(CloseClipboard()); |
---|
366 | } |
---|
367 | return 0; |
---|
368 | } |
---|
369 | LRESULT OnSysCommand(UINT nCommand, CPoint) |
---|
370 | { |
---|
371 | switch(nCommand) |
---|
372 | { |
---|
373 | case ID_APP_ABOUT: |
---|
374 | { |
---|
375 | CAboutDialog Dialog; |
---|
376 | Dialog.DoModal(m_hWnd); |
---|
377 | } |
---|
378 | break; |
---|
379 | default: |
---|
380 | SetMsgHandled(FALSE); |
---|
381 | } |
---|
382 | return 0; |
---|
383 | } |
---|
384 | LRESULT OnCommand(UINT, INT nIdentifier, HWND) |
---|
385 | { |
---|
386 | _W(EndDialog(nIdentifier)); |
---|
387 | return 0; |
---|
388 | } |
---|
389 | LRESULT OnStaticAnchorClicked(NMHDR* pHeader) |
---|
390 | { |
---|
391 | CRoHyperStatic::NMANCHORCLICKED* pHeaderEx = (CRoHyperStatic::NMANCHORCLICKED*) pHeader; |
---|
392 | m_bSetClipboardTextActive = TRUE; |
---|
393 | SetClipboardText(m_hWnd, pHeaderEx->pszLocation); |
---|
394 | m_bSetClipboardTextActive = FALSE; |
---|
395 | pHeaderEx->bShellExecuteLocation = FALSE; |
---|
396 | MessageBeep(MB_OK); |
---|
397 | return 0; |
---|
398 | } |
---|
399 | LRESULT OnHotKey(INT nIdentifier, UINT nModifierFlags, UINT nVirtualKey) |
---|
400 | { |
---|
401 | nModifierFlags; nVirtualKey; |
---|
402 | if(nIdentifier < 12) |
---|
403 | { |
---|
404 | CString sText; |
---|
405 | m_pStatics[nIdentifier].GetWindowText(sText); |
---|
406 | CRoReMatchContext MatchContext; |
---|
407 | static CAtlStaticRegExp<> g_Expression(_T("HREF=\"{.+?}\""), FALSE); |
---|
408 | if(g_Expression.Match(sText, &MatchContext)) |
---|
409 | { |
---|
410 | m_bSetClipboardTextActive = TRUE; |
---|
411 | SetClipboardText(m_hWnd, MatchContext.GetMatchString(0)); |
---|
412 | m_bSetClipboardTextActive = FALSE; |
---|
413 | MessageBeep(MB_OK); |
---|
414 | } |
---|
415 | } |
---|
416 | return 0; |
---|
417 | } |
---|
418 | }; |
---|