From 6146fd09b28d482a8a46f006f45c4c028a737e9f Mon Sep 17 00:00:00 2001 From: Rafal Harabien Date: Sun, 18 Dec 2011 23:41:49 +0000 Subject: [PATCH] [SHELL32] - Fix getting name for context menu item. Fixes two "find" items in My Computer context menu. - Minor code and comments improvements svn path=/trunk/; revision=54688 --- reactos/dll/win32/shell32/defcontextmenu.cpp | 53 +++++----------- reactos/dll/win32/shell32/folders/mycomp.cpp | 10 +-- reactos/dll/win32/shell32/openwithmenu.cpp | 64 +++++++++---------- reactos/dll/win32/shell32/openwithmenu.h | 65 ++++++++++---------- 4 files changed, 83 insertions(+), 109 deletions(-) diff --git a/reactos/dll/win32/shell32/defcontextmenu.cpp b/reactos/dll/win32/shell32/defcontextmenu.cpp index 6c686206a0e..9b86fc4427f 100644 --- a/reactos/dll/win32/shell32/defcontextmenu.cpp +++ b/reactos/dll/win32/shell32/defcontextmenu.cpp @@ -139,7 +139,7 @@ HRESULT WINAPI CDefaultContextMenu::Initialize(const DEFCONTEXTMENU *pdcm) } 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 @@ CDefaultContextMenu::AddStaticEntry(const WCHAR *szVerb, const WCHAR * szClass) return; } - - if (lastEntry) - { lastEntry->Next = curEntry; - } else - { shead = curEntry; - } } void @@ -196,19 +190,17 @@ CDefaultContextMenu::AddStaticEntryForKey(HKEY hKey, const WCHAR * szClass) 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 @@ CDefaultContextMenu::AddStaticContextMenusToMenu( UINT idResource; PStaticShellEntry curEntry; WCHAR szVerb[40]; - WCHAR szTemp[50]; DWORD dwSize; UINT fState; UINT Length; @@ -618,6 +609,8 @@ CDefaultContextMenu::AddStaticContextMenusToMenu( while(curEntry) { fState = MFS_ENABLED; + mii.dwTypeData = NULL; + if (!wcsicmp(curEntry->szVerb, L"open")) { fState |= MFS_DEFAULT; @@ -644,38 +637,26 @@ CDefaultContextMenu::AddStaticContextMenusToMenu( if (idResource > 0) { if (LoadStringW(shell32_hInstance, idResource, szVerb, sizeof(szVerb) / sizeof(WCHAR))) - { - /* use translated verb */ - szVerb[(sizeof(szVerb)/sizeof(WCHAR))-1] = L'\0'; - mii.dwTypeData = szVerb; - } + 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(szTemp) / sizeof(WCHAR)) + if (Length < sizeof(wszKey) / sizeof(WCHAR)) { - wcscpy(szTemp, curEntry->szClass); - wcscat(szTemp, L"\\shell\\"); - wcscat(szTemp, curEntry->szVerb); + wcscpy(wszKey, curEntry->szClass); + wcscat(wszKey, L"\\shell\\"); + wcscat(wszKey, 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; - } + 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 - { - /* use verb for the menu entry */ - mii.dwTypeData = curEntry->szVerb; - } + mii.dwTypeData = curEntry->szVerb; /* use verb for the menu entry */ } - } mii.cch = wcslen(mii.dwTypeData); @@ -689,7 +670,7 @@ CDefaultContextMenu::AddStaticContextMenusToMenu( return indexMenu; } -void WINAPI _InsertMenuItemW ( +void WINAPI _InsertMenuItemW( HMENU hmenu, UINT indexMenu, BOOL fByPosition, diff --git a/reactos/dll/win32/shell32/folders/mycomp.cpp b/reactos/dll/win32/shell32/folders/mycomp.cpp index 384542fcf58..001f5c9a44c 100644 --- a/reactos/dll/win32/shell32/folders/mycomp.cpp +++ b/reactos/dll/win32/shell32/folders/mycomp.cpp @@ -42,7 +42,6 @@ CDrivesFolderEnum is only responsible for returning the physical items. class CDrivesFolderEnum : public IEnumIDListImpl { - private: public: CDrivesFolderEnum(); ~CDrivesFolderEnum(); @@ -79,17 +78,18 @@ HRESULT WINAPI CDrivesFolderEnum::Initialize(HWND hwndOwner, DWORD dwFlags) { 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 @@ HRESULT WINAPI CDrivesFolder::CreateViewObject(HWND hwndOwner, REFIID riid, LPVO } /************************************************************************** -* ISF_MyComputer_fnGetAttributesOf +* CDrivesFolder::GetAttributesOf */ -HRESULT WINAPI CDrivesFolder::GetAttributesOf (UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut) +HRESULT WINAPI CDrivesFolder::GetAttributesOf(UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut) { HRESULT hr = S_OK; static const DWORD dwComputerAttributes = @@ -662,7 +662,7 @@ HRESULT WINAPI CDrivesFolder::GetDisplayNameOf(LPCITEMIDLIST pidl, DWORD dwFlags } /************************************************************************** -* ISF_MyComputer_fnSetNameOf +* CDrivesFolder::SetNameOf * Changes the name of a file object or subfolder, possibly changing its item * identifier in the process. * diff --git a/reactos/dll/win32/shell32/openwithmenu.cpp b/reactos/dll/win32/shell32/openwithmenu.cpp index e5eebe7bea8..f7e0a122ede 100644 --- a/reactos/dll/win32/shell32/openwithmenu.cpp +++ b/reactos/dll/win32/shell32/openwithmenu.cpp @@ -59,11 +59,11 @@ typedef struct _LANGANDCODEPAGE_ WORD code; } LANGANDCODEPAGE, *LPLANGANDCODEPAGE; -HANDLE OpenMRUList(HKEY hKey); +static 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 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 @@ COpenWithMenu::~COpenWithMenu() TRACE(" destroying IContextMenu(%p)\n", this); } -VOID +static VOID AddItem(HMENU hMenu, UINT idCmdFirst) { MENUITEMINFOW mii; @@ -105,8 +105,7 @@ AddItem(HMENU hMenu, UINT idCmdFirst) InsertMenuItemW(hMenu, -1, TRUE, &mii); } -static -void +static VOID LoadOWItems(POPEN_WITH_CONTEXT pContext, LPCWSTR szName) { const WCHAR * szExt; @@ -138,8 +137,6 @@ LoadOWItems(POPEN_WITH_CONTEXT pContext, LPCWSTR szName) } } - - HRESULT WINAPI COpenWithMenu::QueryContextMenu( HMENU hmenu, UINT indexMenu, @@ -204,13 +201,13 @@ HRESULT WINAPI COpenWithMenu::QueryContextMenu( 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 @@ FreeListItems(HWND hwndDlg) } } -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 @@ BOOL HideApplicationFromList(WCHAR * pFileName) return FALSE; } -VOID +static VOID WriteStaticShellExtensionKey(HKEY hRootKey, const WCHAR * pVerb, WCHAR *pFullPath) { HKEY hShell; @@ -287,7 +285,7 @@ WriteStaticShellExtensionKey(HKEY hRootKey, const WCHAR * pVerb, WCHAR *pFullPat RegCloseKey(hShell); } -VOID +static VOID StoreNewSettings(LPCWSTR szFileName, WCHAR *szAppName) { WCHAR szBuffer[100] = { L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\"}; @@ -326,7 +324,7 @@ StoreNewSettings(LPCWSTR szFileName, WCHAR *szAppName) RegCloseKey(hKey); } -VOID +static VOID SetProgrammAsDefaultHandler(LPCWSTR szFileName, WCHAR * szAppName) { HKEY hKey; @@ -404,7 +402,7 @@ SetProgrammAsDefaultHandler(LPCWSTR szFileName, WCHAR * szAppName) RegCloseKey(hKey); } -void +static VOID BrowseForApplication(HWND hwndDlg) { WCHAR szBuffer[64] = {0}; @@ -450,7 +448,7 @@ BrowseForApplication(HWND hwndDlg) SendMessage(Context.hDlgCtrl, LB_SETCURSEL, count, 0); } -POPEN_ITEM_CONTEXT +static POPEN_ITEM_CONTEXT GetCurrentOpenItemContext(HWND hwndDlg) { LRESULT result; @@ -468,7 +466,7 @@ GetCurrentOpenItemContext(HWND hwndDlg) return (POPEN_ITEM_CONTEXT)result; } -void +static VOID ExecuteOpenItem(POPEN_ITEM_CONTEXT pItemContext, LPCWSTR FileName) { STARTUPINFOW si; @@ -492,8 +490,8 @@ ExecuteOpenItem(POPEN_ITEM_CONTEXT pItemContext, LPCWSTR FileName) } } - -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 @@ static INT_PTR CALLBACK OpenWithProgrammDlg(HWND hwndDlg, UINT uMsg, WPARAM wPar return FALSE; } -void +static VOID FreeMenuItemContext(HMENU hMenu) { INT Count; @@ -664,7 +662,6 @@ FreeMenuItemContext(HMENU hMenu) } } - HRESULT WINAPI COpenWithMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpici ) { @@ -788,10 +785,7 @@ GetManufacturer(WCHAR * szAppName, POPEN_ITEM_CONTEXT pContext) HeapFree(GetProcessHeap(), 0, pBuf); } - - - -void +static VOID InsertOpenWithItem(POPEN_WITH_CONTEXT pContext, WCHAR * szAppName) { MENUITEMINFOW mii; @@ -843,13 +837,13 @@ InsertOpenWithItem(POPEN_WITH_CONTEXT pContext, WCHAR * szAppName) } } -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 @@ OpenMRUList(HKEY hKey) return CreateMRUListW(&info); } -void +static VOID AddItemFromMRUList(POPEN_WITH_CONTEXT pContext, HKEY hKey) { HANDLE hList; @@ -900,9 +894,7 @@ AddItemFromMRUList(POPEN_WITH_CONTEXT pContext, HKEY hKey) FreeMRUList(hList); } - - -void +static VOID LoadItemFromHKCR(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt) { HKEY hKey; @@ -986,7 +978,7 @@ LoadItemFromHKCR(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt) } } -void +static VOID LoadItemFromHKCU(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt) { WCHAR szBuffer[MAX_PATH]; @@ -1013,7 +1005,7 @@ LoadItemFromHKCU(POPEN_WITH_CONTEXT pContext, const WCHAR * szExt) } HRESULT -COpenWithMenu::SHEOW_LoadOpenWithItems(IDataObject *pdtobj) +COpenWithMenu::LoadOpenWithItems(IDataObject *pdtobj) { STGMEDIUM medium; FORMATETC fmt; @@ -1024,7 +1016,7 @@ COpenWithMenu::SHEOW_LoadOpenWithItems(IDataObject *pdtobj) 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 @@ COpenWithMenu::Initialize(LPCITEMIDLIST pidlFolder, if (pdtobj == NULL) return E_INVALIDARG; - return SHEOW_LoadOpenWithItems(pdtobj); + return LoadOpenWithItems(pdtobj); } HRESULT WINAPI diff --git a/reactos/dll/win32/shell32/openwithmenu.h b/reactos/dll/win32/shell32/openwithmenu.h index f4cf23b3b7a..cf966235a4a 100644 --- a/reactos/dll/win32/shell32/openwithmenu.h +++ b/reactos/dll/win32/shell32/openwithmenu.h @@ -1,5 +1,5 @@ /* - * Open With Context Menu extension + * Open With Context Menu extension * * Copyright 2007 Johannes Anderwald * Copyright 2009 Andrew Hill @@ -23,43 +23,44 @@ #define _SHE_OCMENU_H_ class COpenWithMenu : - public CComCoClass, - public CComObjectRootEx, - 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, + public CComObjectRootEx, + 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_