[ros-diffs] [rharabien] 54688: [SHELL32] - Fix getting name for context menu item. Fixes two "find" items in My Computer context menu. - Minor code and comments improvements

rharabien at svn.reactos.org rharabien at svn.reactos.org
Sun Dec 18 23:41:49 UTC 2011


Author: rharabien
Date: Sun Dec 18 23:41:49 2011
New Revision: 54688

URL: http://svn.reactos.org/svn/reactos?rev=54688&view=rev
Log:
[SHELL32]
- Fix getting name for context menu item. Fixes two "find" items in My Computer context menu.
- Minor code and comments improvements

Modified:
    trunk/reactos/dll/win32/shell32/defcontextmenu.cpp
    trunk/reactos/dll/win32/shell32/folders/mycomp.cpp
    trunk/reactos/dll/win32/shell32/openwithmenu.cpp
    trunk/reactos/dll/win32/shell32/openwithmenu.h

Modified: trunk/reactos/dll/win32/shell32/defcontextmenu.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/defcontextmenu.cpp?rev=54688&r1=54687&r2=54688&view=diff
==============================================================================
--- trunk/reactos/dll/win32/shell32/defcontextmenu.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/defcontextmenu.cpp [iso-8859-1] Sun Dec 18 23:41:49 2011
@@ -139,7 +139,7 @@
 }
 
 void
-CDefaultContextMenu::AddStaticEntry(const WCHAR *szVerb, const WCHAR * szClass)
+CDefaultContextMenu::AddStaticEntry(const WCHAR *szVerb, const WCHAR *szClass)
 {
     PStaticShellEntry curEntry;
     PStaticShellEntry lastEntry = NULL;
@@ -178,16 +178,10 @@
         return;
     }
 
-
-
     if (lastEntry)
-    {
         lastEntry->Next = curEntry;
-    }
     else
-    {
         shead = curEntry;
-    }
 }
 
 void
@@ -196,19 +190,17 @@
     LONG result;
     DWORD dwIndex;
     WCHAR szName[40];
-    DWORD dwName;
+    DWORD dwSize;
 
     dwIndex = 0;
     do
     {
         szName[0] = 0;
-        dwName = sizeof(szName) / sizeof(WCHAR);
-        result = RegEnumKeyExW(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL);
-        szName[(sizeof(szName)/sizeof(WCHAR))-1] = 0;
+        dwSize = sizeof(szName) / sizeof(WCHAR);
+        result = RegEnumKeyExW(hKey, dwIndex, szName, &dwSize, NULL, NULL, NULL, NULL);
         if (result == ERROR_SUCCESS)
-        {
             AddStaticEntry(szName, szClass);
-        }
+
         dwIndex++;
     } while(result == ERROR_SUCCESS);
 }
@@ -600,7 +592,6 @@
     UINT idResource;
     PStaticShellEntry curEntry;
     WCHAR szVerb[40];
-    WCHAR szTemp[50];
     DWORD dwSize;
     UINT fState;
     UINT Length;
@@ -618,6 +609,8 @@
     while(curEntry)
     {
         fState = MFS_ENABLED;
+        mii.dwTypeData = NULL;
+
         if (!wcsicmp(curEntry->szVerb, L"open"))
         {
             fState |= MFS_DEFAULT;
@@ -644,38 +637,26 @@
         if (idResource > 0)
         {
             if (LoadStringW(shell32_hInstance, idResource, szVerb, sizeof(szVerb) / sizeof(WCHAR)))
+                mii.dwTypeData = szVerb; /* use translated verb */
+            else
+                ERR("Failed to load string, defaulting to NULL value for mii.dwTypeData\n");
+        }
+        else
+        {
+            WCHAR wszKey[256];
+            Length = wcslen(curEntry->szClass) + wcslen(curEntry->szVerb) + 8;
+            if (Length < sizeof(wszKey) / sizeof(WCHAR))
             {
-                /* use translated verb */
-                szVerb[(sizeof(szVerb)/sizeof(WCHAR))-1] = L'\0';
-                mii.dwTypeData = szVerb;
+                wcscpy(wszKey, curEntry->szClass);
+                wcscat(wszKey, L"\\shell\\");
+                wcscat(wszKey, curEntry->szVerb);
+                dwSize = sizeof(szVerb);
+
+                if (RegGetValueW(HKEY_CLASSES_ROOT, wszKey, NULL, RRF_RT_REG_SZ, NULL, szVerb, &dwSize) == ERROR_SUCCESS)
+                    mii.dwTypeData = szVerb; /* use description for the menu entry */
+                else
+                    mii.dwTypeData = curEntry->szVerb; /* use verb for the menu entry */
             }
-            else
-            {
-                ERR("Failed to load string, defaulting to NULL value for mii.dwTypeData\n");
-            }
-        }
-        else
-        {
-            Length = wcslen(curEntry->szClass) + wcslen(curEntry->szVerb) + 8;
-            if (Length < sizeof(szTemp) / sizeof(WCHAR))
-            {
-                wcscpy(szTemp, curEntry->szClass);
-                wcscat(szTemp, L"\\shell\\");
-                wcscat(szTemp, curEntry->szVerb);
-                dwSize = sizeof(szVerb);
-
-                if (RegGetValueW(HKEY_CLASSES_ROOT, szTemp, NULL, RRF_RT_REG_SZ, NULL, szVerb, &dwSize) == ERROR_SUCCESS)
-                {
-                    /* use description for the menu entry */
-                    mii.dwTypeData = szVerb;
-                }
-                else
-                {
-                    /* use verb for the menu entry */
-                    mii.dwTypeData = curEntry->szVerb;
-                }
-            }
-
         }
 
         mii.cch = wcslen(mii.dwTypeData);
@@ -689,7 +670,7 @@
     return indexMenu;
 }
 
-void WINAPI _InsertMenuItemW (
+void WINAPI _InsertMenuItemW(
     HMENU hmenu,
     UINT indexMenu,
     BOOL fByPosition,

Modified: trunk/reactos/dll/win32/shell32/folders/mycomp.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/mycomp.cpp?rev=54688&r1=54687&r2=54688&view=diff
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/mycomp.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/mycomp.cpp [iso-8859-1] Sun Dec 18 23:41:49 2011
@@ -42,7 +42,6 @@
 class CDrivesFolderEnum :
     public IEnumIDListImpl
 {
-    private:
     public:
         CDrivesFolderEnum();
         ~CDrivesFolderEnum();
@@ -79,17 +78,18 @@
 {
     if (CreateMyCompEnumList(dwFlags) == FALSE)
         return E_FAIL;
+
     return S_OK;
 }
 
 /**************************************************************************
  *  CDrivesFolderEnum::CreateMyCompEnumList()
  */
-static const WCHAR MyComputer_NameSpaceW[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MyComputer\\Namespace";
 
 BOOL CDrivesFolderEnum::CreateMyCompEnumList(DWORD dwFlags)
 {
     BOOL bRet = TRUE;
+    static const WCHAR MyComputer_NameSpaceW[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MyComputer\\Namespace";
 
     TRACE("(%p)->(flags=0x%08x)\n", this, dwFlags);
 
@@ -361,9 +361,9 @@
 }
 
 /**************************************************************************
-*  ISF_MyComputer_fnGetAttributesOf
-*/
-HRESULT WINAPI CDrivesFolder::GetAttributesOf (UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
+*  CDrivesFolder::GetAttributesOf
+*/
+HRESULT WINAPI CDrivesFolder::GetAttributesOf(UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
 {
     HRESULT hr = S_OK;
     static const DWORD dwComputerAttributes =
@@ -662,7 +662,7 @@
 }
 
 /**************************************************************************
-*  ISF_MyComputer_fnSetNameOf
+*  CDrivesFolder::SetNameOf
 *  Changes the name of a file object or subfolder, possibly changing its item
 *  identifier in the process.
 *

Modified: trunk/reactos/dll/win32/shell32/openwithmenu.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/openwithmenu.cpp?rev=54688&r1=54687&r2=54688&view=diff
==============================================================================
--- trunk/reactos/dll/win32/shell32/openwithmenu.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/openwithmenu.cpp [iso-8859-1] Sun Dec 18 23:41:49 2011
@@ -59,11 +59,11 @@
     WORD code;
 } LANGANDCODEPAGE, *LPLANGANDCODEPAGE;
 
-HANDLE OpenMRUList(HKEY hKey);
-
-void LoadItemFromHKCU(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt);
-void LoadItemFromHKCR(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt);
-void InsertOpenWithItem(POPEN_WITH_CONTEXT pContext, WCHAR * szAppName);
+static HANDLE OpenMRUList(HKEY hKey);
+
+static VOID LoadItemFromHKCU(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt);
+static VOID LoadItemFromHKCR(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt);
+static VOID InsertOpenWithItem(POPEN_WITH_CONTEXT pContext, WCHAR * szAppName);
 
 COpenWithMenu::COpenWithMenu()
 {
@@ -76,7 +76,7 @@
     TRACE(" destroying IContextMenu(%p)\n", this);
 }
 
-VOID
+static VOID
 AddItem(HMENU hMenu, UINT idCmdFirst)
 {
     MENUITEMINFOW mii;
@@ -105,8 +105,7 @@
     InsertMenuItemW(hMenu, -1, TRUE, &mii);
 }
 
-static
-void
+static VOID
 LoadOWItems(POPEN_WITH_CONTEXT pContext, LPCWSTR szName)
 {
     const WCHAR * szExt;
@@ -137,8 +136,6 @@
         LoadItemFromHKCR(pContext, szPath);
     }
 }
-
-
 
 HRESULT WINAPI COpenWithMenu::QueryContextMenu(
     HMENU hmenu,
@@ -204,13 +201,13 @@
 
     mii.wID = Context.idCmdFirst;
     mii.fType = MFT_STRING;
-    if (InsertMenuItemW( hmenu, pos, TRUE, &mii))
+    if (InsertMenuItemW(hmenu, pos, TRUE, &mii))
         Context.Count++;
 
     return MAKE_HRESULT(SEVERITY_SUCCESS, 0, Context.Count);
 }
 
-void
+static VOID
 FreeListItems(HWND hwndDlg)
 {
     HWND hList;
@@ -234,7 +231,8 @@
     }
 }
 
-BOOL HideApplicationFromList(WCHAR * pFileName)
+static BOOL
+HideApplicationFromList(WCHAR * pFileName)
 {
     WCHAR szBuffer[100] = {'A', 'p', 'p', 'l', 'i', 'c', 'a', 't', 'i', 'o', 'n', 's', '\\', 0};
     DWORD dwSize = 0;
@@ -257,7 +255,7 @@
         return FALSE;
 }
 
-VOID
+static VOID
 WriteStaticShellExtensionKey(HKEY hRootKey, const WCHAR * pVerb, WCHAR *pFullPath)
 {
     HKEY hShell;
@@ -287,7 +285,7 @@
     RegCloseKey(hShell);
 }
 
-VOID
+static VOID
 StoreNewSettings(LPCWSTR szFileName, WCHAR *szAppName)
 {
     WCHAR szBuffer[100] = { L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\"};
@@ -326,7 +324,7 @@
     RegCloseKey(hKey);
 }
 
-VOID
+static VOID
 SetProgrammAsDefaultHandler(LPCWSTR szFileName, WCHAR * szAppName)
 {
     HKEY hKey;
@@ -404,7 +402,7 @@
     RegCloseKey(hKey);
 }
 
-void
+static VOID
 BrowseForApplication(HWND hwndDlg)
 {
     WCHAR szBuffer[64] = {0};
@@ -450,7 +448,7 @@
     SendMessage(Context.hDlgCtrl, LB_SETCURSEL, count, 0);
 }
 
-POPEN_ITEM_CONTEXT
+static POPEN_ITEM_CONTEXT
 GetCurrentOpenItemContext(HWND hwndDlg)
 {
     LRESULT result;
@@ -468,7 +466,7 @@
     return (POPEN_ITEM_CONTEXT)result;
 }
 
-void
+static VOID
 ExecuteOpenItem(POPEN_ITEM_CONTEXT pItemContext, LPCWSTR FileName)
 {
     STARTUPINFOW si;
@@ -492,8 +490,8 @@
     }
 }
 
-
-static INT_PTR CALLBACK OpenWithProgrammDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+static INT_PTR CALLBACK
+OpenWithProgrammDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
     LPMEASUREITEMSTRUCT lpmis;
     LPDRAWITEMSTRUCT lpdis;
@@ -636,7 +634,7 @@
     return FALSE;
 }
 
-void
+static VOID
 FreeMenuItemContext(HMENU hMenu)
 {
     INT Count;
@@ -663,7 +661,6 @@
         }
     }
 }
-
 
 HRESULT WINAPI
 COpenWithMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpici )
@@ -788,10 +785,7 @@
     HeapFree(GetProcessHeap(), 0, pBuf);
 }
 
-
-
-
-void
+static VOID
 InsertOpenWithItem(POPEN_WITH_CONTEXT pContext, WCHAR * szAppName)
 {
     MENUITEMINFOW mii;
@@ -843,13 +837,13 @@
     }
 }
 
-void
+static VOID
 AddItemFromProgIDList(POPEN_WITH_CONTEXT pContext, HKEY hKey)
 {
     FIXME("implement me :)))\n");
 }
 
-HANDLE
+static HANDLE
 OpenMRUList(HKEY hKey)
 {
     CREATEMRULISTW info;
@@ -866,7 +860,7 @@
     return CreateMRUListW(&info);
 }
 
-void
+static VOID
 AddItemFromMRUList(POPEN_WITH_CONTEXT pContext, HKEY hKey)
 {
     HANDLE hList;
@@ -900,9 +894,7 @@
     FreeMRUList(hList);
 }
 
-
-
-void
+static VOID
 LoadItemFromHKCR(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt)
 {
     HKEY hKey;
@@ -986,7 +978,7 @@
     }
 }
 
-void
+static VOID
 LoadItemFromHKCU(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt)
 {
     WCHAR szBuffer[MAX_PATH];
@@ -1013,7 +1005,7 @@
 }
 
 HRESULT
-COpenWithMenu::SHEOW_LoadOpenWithItems(IDataObject *pdtobj)
+COpenWithMenu::LoadOpenWithItems(IDataObject *pdtobj)
 {
     STGMEDIUM medium;
     FORMATETC fmt;
@@ -1024,7 +1016,7 @@
     LPCITEMIDLIST pidl;
     DWORD dwType;
     LPWSTR pszExt;
-    static const WCHAR szShortCut[] = { '.', 'l', 'n', 'k', 0 };
+    static const WCHAR szShortCut[] = L".lnk";
 
     fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLIST);
     fmt.ptd = NULL;
@@ -1100,7 +1092,7 @@
 
     if (pdtobj == NULL)
         return E_INVALIDARG;
-    return SHEOW_LoadOpenWithItems(pdtobj);
+    return LoadOpenWithItems(pdtobj);
 }
 
 HRESULT WINAPI

Modified: trunk/reactos/dll/win32/shell32/openwithmenu.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/openwithmenu.h?rev=54688&r1=54687&r2=54688&view=diff
==============================================================================
--- trunk/reactos/dll/win32/shell32/openwithmenu.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/openwithmenu.h [iso-8859-1] Sun Dec 18 23:41:49 2011
@@ -1,5 +1,5 @@
 /*
- *	Open With  Context Menu extension
+ *  Open With  Context Menu extension
  *
  * Copyright 2007 Johannes Anderwald <janderwald at reactos.org>
  * Copyright 2009 Andrew Hill
@@ -23,43 +23,44 @@
 #define _SHE_OCMENU_H_
 
 class COpenWithMenu :
-	public CComCoClass<COpenWithMenu, &CLSID_OpenWithMenu>,
-	public CComObjectRootEx<CComMultiThreadModelNoCS>,
-	public IContextMenu2,
-	public IShellExtInit
-{	
-private:
-	LONG  wId;
-    BOOL NoOpen;
-    UINT count;
-    WCHAR szPath[MAX_PATH];
-    HMENU hSubMenu;
-public:
-	COpenWithMenu();
-	~COpenWithMenu();
-	HRESULT SHEOW_LoadOpenWithItems(IDataObject *pdtobj);
+    public CComCoClass<COpenWithMenu, &CLSID_OpenWithMenu>,
+    public CComObjectRootEx<CComMultiThreadModelNoCS>,
+    public IContextMenu2,
+    public IShellExtInit
+{
+    private:
+        LONG  wId;
+        BOOL NoOpen;
+        UINT count;
+        WCHAR szPath[MAX_PATH];
+        HMENU hSubMenu;
 
-	// IContextMenu
-	virtual HRESULT WINAPI QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
-	virtual HRESULT WINAPI InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
-	virtual HRESULT WINAPI GetCommandString(UINT_PTR idCommand,UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen);
+    public:
+        COpenWithMenu();
+        ~COpenWithMenu();
+        HRESULT LoadOpenWithItems(IDataObject *pdtobj);
 
-	// IContextMenu2
-	virtual HRESULT WINAPI HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
+        // IContextMenu
+        virtual HRESULT WINAPI QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
+        virtual HRESULT WINAPI InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
+        virtual HRESULT WINAPI GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen);
 
-	// IShellExtInit
-	virtual HRESULT STDMETHODCALLTYPE Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID);
+        // IContextMenu2
+        virtual HRESULT WINAPI HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-DECLARE_NO_REGISTRY()
-DECLARE_NOT_AGGREGATABLE(COpenWithMenu)
+        // IShellExtInit
+        virtual HRESULT STDMETHODCALLTYPE Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID);
 
-DECLARE_PROTECT_FINAL_CONSTRUCT()
+        DECLARE_NO_REGISTRY()
+        DECLARE_NOT_AGGREGATABLE(COpenWithMenu)
 
-BEGIN_COM_MAP(COpenWithMenu)
-	COM_INTERFACE_ENTRY_IID(IID_IContextMenu2, IContextMenu2)
-	COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)
-	COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit)
-END_COM_MAP()
+        DECLARE_PROTECT_FINAL_CONSTRUCT()
+
+        BEGIN_COM_MAP(COpenWithMenu)
+        COM_INTERFACE_ENTRY_IID(IID_IContextMenu2, IContextMenu2)
+        COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)
+        COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit)
+        END_COM_MAP()
 };
 
 #endif // _SHE_OCMENU_H_




More information about the Ros-diffs mailing list