11
22#include " stdafx.h"
33#include " Main.h"
4- #include " Util.h"
5- #include " atlstr.h"
6- #include " wincodec.h"
74
85
96Item::~Item ()
@@ -22,7 +19,7 @@ BOOL FileExist(std::wstring file)
2219 return false ;
2320
2421 DWORD dwAttrib = GetFileAttributes (file.c_str ());
25- return ( dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY ) );
22+ return dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY );
2623}
2724
2825
@@ -87,16 +84,15 @@ HBITMAP ConvertIconToBitmap(HICON hicon)
8784}
8885
8986
90- HRESULT SetIcon (HMENU menu, UINT command , Item* item)
87+ HRESULT SetIcon (HMENU menu, UINT position, UINT flags , Item* item)
9188{
9289 if (!FileExist (item->IconFile ))
9390 return S_OK ;
9491
9592 if (!item->Icon )
9693 {
9794 HICON iconSmall;
98- HICON iconLarge = NULL ;
99- int res = ExtractIconEx (item->IconFile .c_str (), item->IconIndex , &iconLarge, &iconSmall, 1 );
95+ int res = ExtractIconEx (item->IconFile .c_str (), item->IconIndex , NULL , &iconSmall, 1 );
10096
10197 if (!res)
10298 return E_FAIL ;
@@ -106,16 +102,13 @@ HRESULT SetIcon(HMENU menu, UINT command, Item* item)
106102 if (iconSmall)
107103 DestroyIcon (iconSmall);
108104
109- if (iconLarge)
110- DestroyIcon (iconLarge);
111-
112105 if (!bmp)
113106 return E_FAIL ;
114107
115108 item->Icon = bmp;
116109 }
117110
118- int res = SetMenuItemBitmaps (menu, command, MF_BYCOMMAND , item->Icon , item->Icon );
111+ int res = SetMenuItemBitmaps (menu, position, flags , item->Icon , item->Icon );
119112
120113 if (!res)
121114 return E_FAIL ;
@@ -172,62 +165,61 @@ HRESULT CMain::LoadXML()
172165
173166 g_Items.clear ();
174167
175- TCHAR path[MAX_PATH ];
176- SHRegGetPath (HKEY_CURRENT_USER , L" Software\\ " PRODUCT_NAME ,
177- L" SettingsLocation" , path, NULL );
168+ WCHAR path[MAX_PATH ];
169+ SHRegGetPath (HKEY_CURRENT_USER , L" Software\\ " PRODUCT_NAME , L" SettingsLocation" , path, NULL );
178170
179171 if (!FileExist (path))
180172 return E_FAIL ;
181173
182- CComPtr<IXMLDOMDocument> doc;
174+ ATL :: CComPtr<IXMLDOMDocument> doc;
183175 HRESULT hr = doc.CoCreateInstance (__uuidof (DOMDocument));
184176
185177 if (FAILED (hr))
186178 return hr;
187179
188180 VARIANT_BOOL success;
189- hr = doc->load (CComVariant (path), &success);
181+ hr = doc->load (ATL:: CComVariant (path), &success);
190182
191183 if (FAILED (hr))
192184 return hr;
193185
194- CComPtr<IXMLDOMNodeList> items;
195- hr = doc->selectNodes (CComBSTR (L" AppSettings/Items/Item" ), &items);
186+ ATL :: CComPtr<IXMLDOMNodeList> items;
187+ hr = doc->selectNodes (ATL:: CComBSTR (L" AppSettings/Items/Item" ), &items);
196188
197189 if (FAILED (hr))
198190 return hr;
199191
200- IXMLDOMNode * itemNode;
192+ IXMLDOMNode* itemNode;
201193
202- while (! items->nextNode (&itemNode))
194+ while (S_OK == items->nextNode (&itemNode))
203195 {
204196 Item* item = new Item ();
205197
206- CComPtr<IXMLDOMNodeList> itemFields;
198+ ATL :: CComPtr<IXMLDOMNodeList> itemFields;
207199 hr = itemNode->get_childNodes (&itemFields);
208200
209201 if FAILED (hr)
210202 hr;
211203
212- IXMLDOMNode * itemField;
204+ IXMLDOMNode* itemField;
213205
214- while (! itemFields->nextNode (&itemField))
206+ while (S_OK == itemFields->nextNode (&itemField))
215207 {
216208 BSTR nodeName;
217209 hr = itemField->get_nodeName (&nodeName);
218210
219211 if FAILED (hr)
220212 return hr;
221213
222- CComBSTR cNodeName (nodeName);
214+ ATL :: CComBSTR cNodeName (nodeName);
223215
224216 BSTR nodeText;
225217 hr = itemField->get_text (&nodeText);
226218
227219 if FAILED (hr)
228220 return hr;
229221
230- CComBSTR cNodeText (nodeText);
222+ ATL :: CComBSTR cNodeText (nodeText);
231223
232224 if (cNodeName == L" Name" )
233225 item->Name = cNodeText;
@@ -280,29 +272,29 @@ STDMETHODIMP CMain::Initialize(
280272
281273 int uNumFiles = DragQueryFile ((HDROP )stg.hGlobal , 0xFFFFFFFF , NULL , 0 );
282274
283- if (0 == uNumFiles)
275+ if (! uNumFiles)
284276 {
285277 ReleaseStgMedium (&stg);
286278 return E_INVALIDARG ;
287279 }
288280
289281 for (int i = 0 ; i < uNumFiles; i++)
290282 {
291- TCHAR buf [MAX_PATH ];
292- DragQueryFile ((HDROP )stg.hGlobal , i, buf , MAX_PATH );
293- g_ShellItems.push_back (buf );
283+ WCHAR buffer [MAX_PATH ];
284+ DragQueryFile ((HDROP )stg.hGlobal , i, buffer , MAX_PATH );
285+ g_ShellItems.push_back (buffer );
294286 }
295287
296288 ReleaseStgMedium (&stg);
297289 }
298290 else if (pidlFolder)
299291 {
300- TCHAR buf [MAX_PATH ];
292+ WCHAR buffer [MAX_PATH ];
301293
302- if (!SHGetPathFromIDList (pidlFolder, buf ))
294+ if (!SHGetPathFromIDList (pidlFolder, buffer ))
303295 return E_FAIL ;
304296
305- g_ShellItems.push_back (buf );
297+ g_ShellItems.push_back (buffer );
306298 }
307299 else
308300 return E_FAIL ;
@@ -314,12 +306,11 @@ STDMETHODIMP CMain::Initialize(
314306STDMETHODIMP CMain::QueryContextMenu (
315307 HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd, UINT uidLastCmd, UINT uFlags)
316308{
317- if (g_Items.size () == 0 || SHRegGetBoolUSValue (
309+ if (! g_Items.size () || SHRegGetBoolUSValue (
318310 L" Software\\ " PRODUCT_NAME , L" Reload" , FALSE , TRUE ))
319311 {
320312 REGISTRY_ENTRY re = GetRegEntry (HKEY_CURRENT_USER ,
321- L" Software\\ " PRODUCT_NAME , L" Reload" ,
322- NULL , REG_DWORD , 0 );
313+ L" Software\\ " PRODUCT_NAME , L" Reload" , NULL , REG_DWORD , 0 );
323314
324315 if (FAILED (CreateRegKeyAndSetValue (&re)))
325316 return E_FAIL ;
@@ -366,7 +357,7 @@ STDMETHODIMP CMain::QueryContextMenu(
366357 if (!res)
367358 return E_FAIL ;
368359
369- SetIcon (hmenu, command, g_Items[i]);
360+ SetIcon (hmenu, command, MF_BYCOMMAND , g_Items[i]);
370361 addSubSep = true ;
371362 }
372363 else
@@ -376,7 +367,7 @@ STDMETHODIMP CMain::QueryContextMenu(
376367 if (!res)
377368 return E_FAIL ;
378369
379- SetIcon (hmenu, command , g_Items[i]);
370+ SetIcon (hmenu, uMenuIndex, MF_BYPOSITION , g_Items[i]);
380371 uMenuIndex += 1 ;
381372 }
382373
@@ -408,7 +399,7 @@ STDMETHODIMP CMain::QueryContextMenu(
408399 if (!res)
409400 return E_FAIL ;
410401
411- SetIcon (hmenu, command, g_Items[i]);
402+ SetIcon (hmenu, command, MF_BYCOMMAND , g_Items[i]);
412403 addSubSep2 = true ;
413404 }
414405 else
@@ -418,7 +409,7 @@ STDMETHODIMP CMain::QueryContextMenu(
418409 if (!res)
419410 return E_FAIL ;
420411
421- SetIcon (hmenu, command , g_Items[i]);
412+ SetIcon (hmenu, uMenuIndex, MF_BYPOSITION , g_Items[i]);
422413 uMenuIndex += 1 ;
423414 }
424415
@@ -470,15 +461,15 @@ STDMETHODIMP CMain::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
470461 if (args.find (L" %items%" ) != std::wstring::npos)
471462 {
472463 std::wstring joined = L" \" " + JoinList (&g_ShellItems, L" \" \" " ) + L" \" " ;
473- CString argh = args.c_str ();
464+ ATL :: CString argh = args.c_str ();
474465 argh.Replace (L" %items%" , joined.c_str ());
475466 args = argh.GetBuffer ();
476467 }
477468
478469 if (args.find (L" %paths%" ) != std::wstring::npos)
479470 {
480471 std::wstring joined = L" \" " + JoinList (&g_ShellItems, L" \" \" " ) + L" \" " ;
481- CString argh = args.c_str ();
472+ ATL :: CString argh = args.c_str ();
482473 argh.Replace (L" %paths%" , joined.c_str ());
483474 args = argh.GetBuffer ();
484475 }
0 commit comments