source: trunk/Utilities/GpsLocationConverter/MainDialog.h @ 32

Last change on this file since 32 was 32, checked in by roman, 12 years ago

more URL shortcuts for: Bing Maps, Yahoo Maps, OpenStreetMap? and WikiMapia?

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