Clone
ixen <ixen@copyhandler.com>
committed
on 28 Feb 17
Fixed issue with duplicate items appearing in the shell extension context menu (CH-333).
ch-1.40 + 2 more
src/chext/MenuExt.cpp (+7 -1)
88 88                 if(SUCCEEDED(hResult))
89 89                 {
90 90                         hResult = m_tShellExtData.GatherDataFromInitialize(pidlFolder, piDataObject);
91 91                         LOG_HRESULT(m_spLog, hResult) << L"Gather data from initialize";
92 92                 }
93 93
94 94                 return hResult;
95 95         }
96 96         catch(const std::exception& e)
97 97         {
98 98                 LOG_CRITICAL(m_spLog) << L"Unexpected std exception encountered in " << __FUNCTION__ << L": " << e.what();
99 99                 return E_FAIL;
100 100         }
101 101         catch(...)
102 102         {
103 103                 LOG_CRITICAL(m_spLog) << L"Unexpected other exception encountered in " << __FUNCTION__ << L".";
104 104                 return E_FAIL;
105 105         }
106 106 }
107 107
108   STDMETHODIMP CMenuExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/)
  108 STDMETHODIMP CMenuExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
109 109 {
  110         idCmdLast;
  111         uFlags;
  112
110 113         try
111 114         {
112 115                 LOG_DEBUG(m_spLog) << L"Querying context menu";
113 116
114 117                 if(!hMenu)
115 118                 {
116 119                         LOG_ERROR(m_spLog) << L"Received null hMenu from caller";
117 120                         return E_INVALIDARG;
118 121                 }
119 122
120 123                 // check options
121 124                 HWND hWnd = ShellExtensionVerifier::VerifyShellExt(m_piShellExtControl);
122 125                 if(!hWnd)
123 126                         return S_OK;
124 127
  128                 if (m_tContextMenuHandler.HasCHItems(hMenu))
  129                         return S_OK;
  130
125 131                 // current commands count in menu
126 132                 TCHAR szText[ _MAX_PATH ];
127 133                 int iCount = ::GetMenuItemCount(hMenu);
128 134
129 135                 // find a place where the commands should be inserted
130 136                 for(int iMenuIndex = 0; iMenuIndex < iCount; iMenuIndex++)
131 137                 {
132 138                         MENUITEMINFO mii = { 0 };
133 139                         mii.cbSize = sizeof(mii);
134 140                         mii.fMask = MIIM_STRING;
135 141                         mii.dwTypeData = szText;
136 142                         mii.cch = _MAX_PATH;
137 143
138 144                         if(!::GetMenuItemInfo(hMenu, iMenuIndex, TRUE, &mii))
139 145                                 continue;
140 146
141 147                         // get rid of &
142 148                         CutAmpersands(szText);
143 149                         _tcslwr(szText);
144 150