ReactOS 0.4.16-dev-2293-g4d8327b
CNewMenu Class Reference

#include <CNewMenu.h>

Inheritance diagram for CNewMenu:
Collaboration diagram for CNewMenu:

Classes

struct  SHELLNEW_ITEM
 

Public Member Functions

 CNewMenu ()
 
 ~CNewMenu ()
 
STDMETHOD() SetSite (IUnknown *pUnkSite) override
 
STDMETHOD() GetSite (REFIID riid, void **ppvSite) override
 
STDMETHOD() QueryContextMenu (HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override
 
STDMETHOD() InvokeCommand (LPCMINVOKECOMMANDINFO lpcmi) override
 
STDMETHOD() GetCommandString (UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen) override
 
STDMETHOD() HandleMenuMsg2 (UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult) override
 
STDMETHOD() HandleMenuMsg (UINT uMsg, WPARAM wParam, LPARAM lParam) override
 
STDMETHOD() Initialize (PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) override
 
- Public Member Functions inherited from ATL::CComObjectRootEx< CComMultiThreadModelNoCS >
 ~CComObjectRootEx ()
 
ULONG InternalAddRef ()
 
ULONG InternalRelease ()
 
void Lock ()
 
void Unlock ()
 
HRESULT _AtlInitialConstruct ()
 
- Public Member Functions inherited from ATL::CComObjectRootBase
 CComObjectRootBase ()
 
 ~CComObjectRootBase ()
 
void SetVoid (void *)
 
HRESULT _AtlFinalConstruct ()
 
HRESULT FinalConstruct ()
 
void InternalFinalConstructAddRef ()
 
void InternalFinalConstructRelease ()
 
void FinalRelease ()
 
- Public Member Functions inherited from IObjectWithSite
HRESULT SetSite ([in] IUnknown *pUnkSite)
 
HRESULT GetSite ([in] REFIID riid, [out, iid_is(riid)] PVOID *ppvSite)
 
- Public Member Functions inherited from IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 
HRESULT HandleMenuMsg2 ([in] UINT uMsg, [in] WPARAM wParam, [in] LPARAM lParam, [out] LRESULT *plResult)
 
HRESULT HandleMenuMsg ([in] UINT uMsg, [in] WPARAM wParam, [in] LPARAM lParam)
 
HRESULT QueryContextMenu ([in] HMENU hmenu, [in] UINT indexMenu, [in] UINT idCmdFirst, [in] UINT idCmdLast, [in] UINT uFlags)
 
HRESULT InvokeCommand ([in] LPCMINVOKECOMMANDINFO lpici)
 
HRESULT GetCommandString ([in] UINT_PTR idCmd, [in] UINT uType, [out] UINT *pwReserved, [out, size_is(cchMax)] LPSTR pszName, [in] UINT cchMax)
 
HRESULT Initialize ([in] PCIDLIST_ABSOLUTE pidlFolder, [in] IDataObject *pdtobj, [in] HKEY hkeyProgID)
 

Private Types

enum  SHELLNEW_TYPE {
  SHELLNEW_TYPE_INVALID = -1 , SHELLNEW_TYPE_COMMAND = 1 , SHELLNEW_TYPE_DATA = 2 , SHELLNEW_TYPE_FILENAME = 4 ,
  SHELLNEW_TYPE_NULLFILE = 8
}
 

Private Member Functions

SHELLNEW_ITEMLoadItem (LPCWSTR pwszExt)
 
void UnloadItem (SHELLNEW_ITEM *pItem)
 
void UnloadAllItems ()
 
BOOL CacheItems ()
 
BOOL LoadCachedItems ()
 
BOOL LoadAllItems ()
 
UINT InsertShellNewItems (HMENU hMenu, UINT idFirst, UINT idMenu)
 
SHELLNEW_ITEMFindItemFromIdOffset (UINT IdOffset)
 
HRESULT CreateNewFolder (LPCMINVOKECOMMANDINFO lpici)
 
HRESULT CreateNewItem (SHELLNEW_ITEM *pItem, LPCMINVOKECOMMANDINFO lpcmi)
 
HRESULT SelectNewItem (LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
 
HRESULT NewItemByCommand (SHELLNEW_ITEM *pItem, LPCWSTR wszPath)
 
HRESULT NewItemByNonCommand (SHELLNEW_ITEM *pItem, LPWSTR wszName, DWORD cchNameMax, LPCWSTR wszPath)
 

Private Attributes

LPITEMIDLIST m_pidlFolder
 
SHELLNEW_ITEMm_pItems
 
SHELLNEW_ITEMm_pLinkItem
 
CComPtr< IUnknownm_pSite
 
HMENU m_hSubMenu
 
UINT m_idCmdFirst
 
UINT m_idCmdFolder
 
UINT m_idCmdLink
 
BOOL m_bCustomIconFolder
 
BOOL m_bCustomIconLink
 
HICON m_hIconFolder
 
HICON m_hIconLink
 

Additional Inherited Members

- Public Types inherited from IObjectWithSite
typedef IObjectWithSiteLPOBJECTWITHSITE
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 
- Public Types inherited from IContextMenu3
typedef IContextMenu3LPCONTEXTMENU3
 
- Public Types inherited from IContextMenu2
typedef IContextMenu2LPCONTEXTMENU2
 
- Public Types inherited from IContextMenu
typedef IContextMenuLPCONTEXTMENU
 
typedef struct IContextMenu::tagCMINVOKECOMMANDINFO CMINVOKECOMMANDINFO
 
typedef struct IContextMenu::tagCMINVOKECOMMANDINFOLPCMINVOKECOMMANDINFO
 
typedef struct IContextMenu::tagCMInvokeCommandInfoEx CMINVOKECOMMANDINFOEX
 
typedef struct IContextMenu::tagCMInvokeCommandInfoExLPCMINVOKECOMMANDINFOEX
 
- Public Types inherited from IShellExtInit
typedef IShellExtInitLPSHELLEXTINIT
 
- Static Public Member Functions inherited from ATL::CComObjectRootBase
static void WINAPI ObjectMain (bool)
 
static const struct _ATL_CATMAP_ENTRYGetCategoryMap ()
 
static HRESULT WINAPI InternalQueryInterface (void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
 
- Public Attributes inherited from ATL::CComObjectRootBase
LONG m_dwRef
 
- Static Public Attributes inherited from IContextMenu
static const WCHAR CMDSTR_NEWFOLDERW [] = {'N','e','w','F','o','l','d','e','r',0}
 
static const WCHAR CMDSTR_VIEWLISTW [] = {'V','i','e','w','L','i','s','t',0}
 
static const WCHAR CMDSTR_VIEWDETAILSW [] = {'V','i','e','w','D','e','t','a','i','l','s',0}
 

Detailed Description

Definition at line 28 of file CNewMenu.h.

Member Enumeration Documentation

◆ SHELLNEW_TYPE

Enumerator
SHELLNEW_TYPE_INVALID 
SHELLNEW_TYPE_COMMAND 
SHELLNEW_TYPE_DATA 
SHELLNEW_TYPE_FILENAME 
SHELLNEW_TYPE_NULLFILE 

Definition at line 36 of file CNewMenu.h.

37 {
43 };
@ SHELLNEW_TYPE_COMMAND
Definition: CNewMenu.h:39
@ SHELLNEW_TYPE_FILENAME
Definition: CNewMenu.h:41
@ SHELLNEW_TYPE_DATA
Definition: CNewMenu.h:40
@ SHELLNEW_TYPE_NULLFILE
Definition: CNewMenu.h:42
@ SHELLNEW_TYPE_INVALID
Definition: CNewMenu.h:38

Constructor & Destructor Documentation

◆ CNewMenu()

CNewMenu::CNewMenu ( )

Definition at line 28 of file CNewMenu.cpp.

28 :
33 m_idCmdFirst(0),
34 m_idCmdFolder(-1),
35 m_idCmdLink(-1),
40{
41}
HICON m_hIconFolder
Definition: CNewMenu.h:63
BOOL m_bCustomIconLink
Definition: CNewMenu.h:62
UINT m_idCmdLink
Definition: CNewMenu.h:61
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
BOOL m_bCustomIconFolder
Definition: CNewMenu.h:62
HICON m_hIconLink
Definition: CNewMenu.h:63
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:57
UINT m_idCmdFirst
Definition: CNewMenu.h:61
UINT m_idCmdFolder
Definition: CNewMenu.h:61
CComPtr< IUnknown > m_pSite
Definition: CNewMenu.h:59
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117

◆ ~CNewMenu()

CNewMenu::~CNewMenu ( )

Definition at line 43 of file CNewMenu.cpp.

44{
46
51 if (m_pidlFolder)
53}
void UnloadAllItems()
Definition: CNewMenu.cpp:68
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:1051
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2422

Member Function Documentation

◆ CacheItems()

BOOL CNewMenu::CacheItems ( )
private

Definition at line 189 of file CNewMenu.cpp.

190{
191 HKEY hKey;
192 DWORD dwSize = 0;
193 DWORD dwIndex = 0;
194 LPWSTR lpValue;
195 LPWSTR lpValues;
196 WCHAR wszName[MAX_PATH];
197 SHELLNEW_ITEM *pNewItem;
198 SHELLNEW_ITEM *pCurItem = NULL;
199
200 /* Enumerate all extensions */
201 while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS)
202 {
203 if (wszName[0] != L'.')
204 continue;
205
206 pNewItem = LoadItem(wszName);
207 if (pNewItem)
208 {
209 dwSize += wcslen(wszName) + 1;
210 if (!m_pLinkItem && _wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
211 {
212 /* The unique link handler */
213 m_pLinkItem = pNewItem;
214 }
215
216 /* Add at the end of the list */
217 if (pCurItem)
218 {
219 pCurItem->pNext = pNewItem;
220 pCurItem = pNewItem;
221 }
222 else
223 {
224 pCurItem = m_pItems = pNewItem;
225 }
226 }
227 }
228
229 dwSize++;
230
231 lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize * sizeof(WCHAR));
232 if (!lpValues)
233 return FALSE;
234
235 for (pCurItem = m_pItems, lpValue = lpValues; pCurItem; pCurItem = pCurItem->pNext)
236 {
237 memcpy(lpValue, pCurItem->pwszExt, (wcslen(pCurItem->pwszExt) + 1) * sizeof(WCHAR));
238 lpValue += wcslen(pCurItem->pwszExt) + 1;
239 }
240
242 {
243 HeapFree(GetProcessHeap(), 0, lpValues);
244 return FALSE;
245 }
246
247 if (RegSetValueExW(hKey, L"Classes", NULL, REG_MULTI_SZ, (LPBYTE)lpValues, dwSize * sizeof(WCHAR)) != ERROR_SUCCESS)
248 {
249 HeapFree(GetProcessHeap(), 0, lpValues);
251 return FALSE;
252 }
253
254 HeapFree(GetProcessHeap(), 0, lpValues);
256
257 return TRUE;
258}
const WCHAR ShellNewKey[]
Definition: CNewMenu.h:26
#define RegCloseKey(hKey)
Definition: registry.h:49
SHELLNEW_ITEM * LoadItem(LPCWSTR pwszExt)
Definition: CNewMenu.cpp:83
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegEnumKeyW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cbName)
Definition: reg.c:2393
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
#define REG_MULTI_SZ
Definition: nt_native.h:1504
#define KEY_WRITE
Definition: nt_native.h:1034
#define _countof(array)
Definition: sndvol32.h:70
SHELLNEW_ITEM * pNext
Definition: CNewMenu.h:53
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegCreateKeyEx
Definition: winreg.h:508
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by LoadAllItems().

◆ CreateNewFolder()

HRESULT CNewMenu::CreateNewFolder ( LPCMINVOKECOMMANDINFO  lpici)
private

Definition at line 465 of file CNewMenu.cpp.

466{
467 WCHAR wszPath[MAX_PATH];
468 WCHAR wszName[MAX_PATH];
469 WCHAR wszNewFolder[25];
470 HRESULT hr;
471
472 /* Get folder path */
475 return hr;
476
477 if (!LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, _countof(wszNewFolder)))
478 return E_FAIL;
479
480 /* Create the name of the new directory */
481 if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, wszNewFolder))
482 return E_FAIL;
483
484 /* Create the new directory and show the appropriate dialog in case of error */
485 if (SHCreateDirectory(lpici->hwnd, wszName) != ERROR_SUCCESS)
486 return E_FAIL;
487
488 /* Show and select the new item in the def view */
490
491 return S_OK;
492}
#define shell32_hInstance
HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
Definition: CNewMenu.cpp:426
#define E_FAIL
Definition: ddrawi.h:102
INT WINAPI DECLSPEC_HOTPATCH LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
Definition: string.c:1220
BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname)
Definition: shellpath.c:848
#define FAILED_UNEXPECTEDLY
Definition: utils.cpp:30
#define IDS_NEWFOLDER
#define S_OK
Definition: intsafe.h:52
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1496
int WINAPI SHCreateDirectory(HWND hWnd, LPCWSTR path)
Definition: shlfileop.cpp:948
HRESULT hr
Definition: shlfolder.c:183
#define SHCNE_MKDIR
Definition: shlobj.h:1900
#define SHCNF_PATHW
Definition: shlobj.h:1933

Referenced by InvokeCommand().

◆ CreateNewItem()

HRESULT CNewMenu::CreateNewItem ( SHELLNEW_ITEM pItem,
LPCMINVOKECOMMANDINFO  lpcmi 
)
private

Definition at line 593 of file CNewMenu.cpp.

594{
595 HRESULT hr;
596 WCHAR wszPath[MAX_PATH], wszName[MAX_PATH];
597
598 /* Get folder path */
601 return hr;
602
603 if (pItem == m_pLinkItem)
604 {
605 NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
606 NewItemByCommand(pItem, wszName);
607 return S_OK;
608 }
609
610 switch (pItem->Type)
611 {
613 NewItemByCommand(pItem, wszPath);
614 break;
615
619 NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
620 break;
621
623 ERR("Invalid type\n");
624 break;
625 }
626
627 return S_OK;
628}
#define ERR(fmt,...)
Definition: precomp.h:57
HRESULT NewItemByNonCommand(SHELLNEW_ITEM *pItem, LPWSTR wszName, DWORD cchNameMax, LPCWSTR wszPath)
Definition: CNewMenu.cpp:537
HRESULT NewItemByCommand(SHELLNEW_ITEM *pItem, LPCWSTR wszPath)
Definition: CNewMenu.cpp:494

Referenced by InvokeCommand().

◆ FindItemFromIdOffset()

CNewMenu::SHELLNEW_ITEM * CNewMenu::FindItemFromIdOffset ( UINT  IdOffset)
private

Definition at line 404 of file CNewMenu.cpp.

405{
406 /* Folder */
407 if (m_idCmdFirst + IdOffset == m_idCmdFolder)
408 return NULL;
409
410 /* Shortcut */
411 if (m_idCmdFirst + IdOffset == m_idCmdLink)
412 return m_pLinkItem;
413
414 /* Find shell new item - Retrieve menu item info */
415 MENUITEMINFOW mii;
416 ZeroMemory(&mii, sizeof(mii));
417 mii.cbSize = sizeof(mii);
418 mii.fMask = MIIM_DATA;
419
420 if (GetMenuItemInfoW(m_hSubMenu, m_idCmdFirst + IdOffset, FALSE, &mii) && mii.dwItemData)
421 return (SHELLNEW_ITEM *)mii.dwItemData;
422 else
423 return NULL;
424}
HMENU m_hSubMenu
Definition: CNewMenu.h:60
#define ZeroMemory
Definition: minwinbase.h:31
ULONG_PTR dwItemData
Definition: winuser.h:3370
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
#define MIIM_DATA
Definition: winuser.h:737

Referenced by HandleMenuMsg2(), and InvokeCommand().

◆ GetCommandString()

HRESULT WINAPI CNewMenu::GetCommandString ( UINT_PTR  idCommand,
UINT  uFlags,
UINT lpReserved,
LPSTR  lpszName,
UINT  uMaxNameLen 
)
override

Implements IContextMenu.

Definition at line 704 of file CNewMenu.cpp.

709{
710 FIXME("%p %lu %u %p %p %u\n", this,
711 idCmd, uType, pwReserved, pszName, cchMax );
712
713 return E_NOTIMPL;
714}
UINT cchMax
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ GetSite()

HRESULT STDMETHODCALLTYPE CNewMenu::GetSite ( REFIID  riid,
void **  ppvSite 
)
override

Definition at line 636 of file CNewMenu.cpp.

637{
638 return m_pSite->QueryInterface(riid, ppvSite);
639}
REFIID riid
Definition: atlbase.h:39

◆ HandleMenuMsg()

HRESULT WINAPI CNewMenu::HandleMenuMsg ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
override

Implements IContextMenu2.

Definition at line 718 of file CNewMenu.cpp.

719{
720 return HandleMenuMsg2(uMsg, wParam, lParam, NULL);
721}
STDMETHOD() HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult) override
Definition: CNewMenu.cpp:725
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139

◆ HandleMenuMsg2()

HRESULT WINAPI CNewMenu::HandleMenuMsg2 ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
LRESULT plResult 
)
override

Implements IContextMenu3.

Definition at line 725 of file CNewMenu.cpp.

726{
727 switch (uMsg)
728 {
729 case WM_MEASUREITEM:
730 {
731 MEASUREITEMSTRUCT* lpmis = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
732 if (!lpmis || lpmis->CtlType != ODT_MENU)
733 break;
734
737 if (lpmis->itemHeight < 16)
738 lpmis->itemHeight = 16;
739
740 if (plResult)
741 *plResult = TRUE;
742 break;
743 }
744 case WM_DRAWITEM:
745 {
746 DRAWITEMSTRUCT* lpdis = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
747 if (!lpdis || lpdis->CtlType != ODT_MENU)
748 break;
749
750 DWORD id = lpdis->itemID;
751 HICON hIcon = NULL;
752 if (id == m_idCmdFolder)
753 {
755 }
756 else if (id == m_idCmdLink)
757 {
759 }
760 else
761 {
762 SHELLNEW_ITEM *pItem = FindItemFromIdOffset(id - m_idCmdFirst);
763 if (pItem)
764 hIcon = pItem->hIcon;
765 }
766
767 if (!hIcon)
768 break;
769
770 DrawIconEx(lpdis->hDC,
771 2,
772 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
773 hIcon,
774 16,
775 16,
776 0, NULL, DI_NORMAL);
777
778 if(plResult)
779 *plResult = TRUE;
780 }
781 }
782
783 return S_OK;
784}
SHELLNEW_ITEM * FindItemFromIdOffset(UINT IdOffset)
Definition: CNewMenu.cpp:404
static HICON
Definition: imagelist.c:80
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
LONG bottom
Definition: windef.h:109
LONG top
Definition: windef.h:107
#define DI_NORMAL
Definition: wingdi.h:72
#define SM_CXMENUCHECK
Definition: winuser.h:1042
#define WM_DRAWITEM
Definition: winuser.h:1673
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:2397
#define WM_MEASUREITEM
Definition: winuser.h:1674
#define ODT_MENU
Definition: winuser.h:2573
int WINAPI GetSystemMetrics(_In_ int)

Referenced by HandleMenuMsg().

◆ Initialize()

HRESULT WINAPI CNewMenu::Initialize ( PCIDLIST_ABSOLUTE  pidlFolder,
IDataObject pdtobj,
HKEY  hkeyProgID 
)
override

Implements IShellExtInit.

Definition at line 787 of file CNewMenu.cpp.

789{
791 WCHAR wszIconPath[MAX_PATH];
792 int icon_idx;
793
794 m_pidlFolder = ILClone(pidlFolder);
795
796 /* Load folder and shortcut icons */
797 if (HLM_GetIconW(IDI_SHELL_FOLDER - 1, wszIconPath, _countof(wszIconPath), &icon_idx))
798 {
799 ::ExtractIconExW(wszIconPath, icon_idx, &m_hIconFolder, NULL, 1);
801 }
802 else
803 {
805 }
806
807 if (HLM_GetIconW(IDI_SHELL_SHORTCUT - 1, wszIconPath, _countof(wszIconPath), &icon_idx))
808 {
809 ::ExtractIconExW(wszIconPath, icon_idx, &m_hIconLink, NULL, 1);
811 }
812 else
813 {
815 }
816
817 return S_OK;
818}
#define IDI_SHELL_FOLDER
Definition: treeview.c:21
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:855
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:238
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#define IDI_SHELL_SHORTCUT
Definition: shresdef.h:623
int32_t INT
Definition: typedefs.h:58
#define IMAGE_ICON
Definition: winuser.h:212
#define SM_CYSMICON
Definition: winuser.h:1024
#define SM_CXSMICON
Definition: winuser.h:1023
#define LR_SHARED
Definition: winuser.h:1111
#define LoadImage
Definition: winuser.h:5926

◆ InsertShellNewItems()

UINT CNewMenu::InsertShellNewItems ( HMENU  hMenu,
UINT  idFirst,
UINT  idMenu 
)
private

Definition at line 336 of file CNewMenu.cpp.

337{
338 MENUITEMINFOW mii;
339 UINT idCmd = idCmdFirst;
340 WCHAR wszBuf[256];
341
342 if (m_pItems == NULL)
343 {
344 if (!LoadAllItems())
345 return 0;
346 }
347
348 ZeroMemory(&mii, sizeof(mii));
349 mii.cbSize = sizeof(mii);
350
351 m_idCmdFirst = idCmd;
352
353 /* Insert the new folder action */
355 wszBuf[0] = 0;
357 mii.dwTypeData = wszBuf;
358 mii.cch = wcslen(mii.dwTypeData);
359 mii.wID = idCmd;
360 mii.hbmpItem = HBMMENU_CALLBACK;
361 if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
362 m_idCmdFolder = idCmd++;
363
364 /* Insert the new shortcut action */
365 if (m_pLinkItem)
366 {
368 wszBuf[0] = 0;
369 mii.dwTypeData = wszBuf;
370 mii.cch = wcslen(mii.dwTypeData);
371 mii.wID = idCmd;
372 if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
373 m_idCmdLink = idCmd++;
374 }
375
376 /* Insert a seperator for the custom new action */
377 mii.fMask = MIIM_TYPE | MIIM_ID;
378 mii.fType = MFT_SEPARATOR;
379 mii.wID = -1;
380 InsertMenuItemW(hMenu, Pos++, TRUE, &mii);
381
382 /* Insert the rest of the items */
384 mii.fType = 0;
385
386 for (SHELLNEW_ITEM *pCurItem = m_pItems; pCurItem; pCurItem = pCurItem->pNext)
387 {
388 /* Skip shortcut item */
389 if (pCurItem == m_pLinkItem)
390 continue;
391
392 TRACE("szDesc %s\n", debugstr_w(pCurItem->pwszDesc));
393 mii.dwItemData = (ULONG_PTR)pCurItem;
394 mii.dwTypeData = pCurItem->pwszDesc;
395 mii.cch = wcslen(mii.dwTypeData);
396 mii.wID = idCmd;
397 if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
398 ++idCmd;
399 }
400
401 return idCmd - idCmdFirst;
402}
BOOL LoadAllItems()
Definition: CNewMenu.cpp:319
ush Pos
Definition: deflate.h:92
#define ULONG_PTR
Definition: config.h:101
#define debugstr_w
Definition: kernel32.h:32
#define FCIDM_SHVIEW_NEWFOLDER
Definition: shresdef.h:893
#define FCIDM_SHVIEW_NEWLINK
Definition: shresdef.h:892
#define TRACE(s)
Definition: solgame.cpp:4
LPWSTR dwTypeData
Definition: winuser.h:3371
#define MIIM_STRING
Definition: winuser.h:738
#define MIIM_ID
Definition: winuser.h:733
#define MFT_SEPARATOR
Definition: winuser.h:755
#define MIIM_BITMAP
Definition: winuser.h:739
#define HBMMENU_CALLBACK
Definition: winuser.h:2672
#define MIIM_TYPE
Definition: winuser.h:736
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)

Referenced by QueryContextMenu().

◆ InvokeCommand()

HRESULT WINAPI CNewMenu::InvokeCommand ( LPCMINVOKECOMMANDINFO  lpcmi)
override

Implements IContextMenu.

Definition at line 683 of file CNewMenu.cpp.

684{
685 HRESULT hr = E_FAIL;
686
687 if (m_idCmdFirst + LOWORD(lpici->lpVerb) == m_idCmdFolder)
688 {
689 hr = CreateNewFolder(lpici);
690 }
691 else
692 {
693 SHELLNEW_ITEM *pItem = FindItemFromIdOffset(LOWORD(lpici->lpVerb));
694 if (pItem)
695 hr = CreateNewItem(pItem, lpici);
696 }
697
698 TRACE("CNewMenu::InvokeCommand %x\n", hr);
699 return hr;
700}
HRESULT CreateNewItem(SHELLNEW_ITEM *pItem, LPCMINVOKECOMMANDINFO lpcmi)
Definition: CNewMenu.cpp:593
HRESULT CreateNewFolder(LPCMINVOKECOMMANDINFO lpici)
Definition: CNewMenu.cpp:465
#define LOWORD(l)
Definition: pedump.c:82

◆ LoadAllItems()

BOOL CNewMenu::LoadAllItems ( )
private

Definition at line 319 of file CNewMenu.cpp.

320{
321 // TODO: We need to find a way to refresh the cache from time to time, when
322 // e.g. new extensions with ShellNew handlers have been added or removed.
323
324 /* If there are any unload them */
326
327 if (!LoadCachedItems())
328 {
329 CacheItems();
330 }
331
332 return (m_pItems != NULL);
333}
BOOL LoadCachedItems()
Definition: CNewMenu.cpp:261
BOOL CacheItems()
Definition: CNewMenu.cpp:189

Referenced by InsertShellNewItems().

◆ LoadCachedItems()

BOOL CNewMenu::LoadCachedItems ( )
private

Definition at line 261 of file CNewMenu.cpp.

262{
263 LPWSTR wszName;
264 LPWSTR lpValues;
266 HKEY hKey;
267 SHELLNEW_ITEM *pNewItem;
268 SHELLNEW_ITEM *pCurItem = NULL;
269
271 return FALSE;
272
273 if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, NULL, &dwSize) != ERROR_SUCCESS)
274 return FALSE;
275
276 lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwSize);
277 if (!lpValues)
278 return FALSE;
279
280 if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, (LPBYTE)lpValues, &dwSize) != ERROR_SUCCESS)
281 {
282 HeapFree(GetProcessHeap(), 0, lpValues);
283 return FALSE;
284 }
285
286 wszName = lpValues;
287
288 for (; *wszName != '\0'; wszName += wcslen(wszName) + 1)
289 {
290 pNewItem = LoadItem(wszName);
291 if (pNewItem)
292 {
293 if (!m_pLinkItem && _wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
294 {
295 /* The unique link handler */
296 m_pLinkItem = pNewItem;
297 }
298
299 /* Add at the end of the list */
300 if (pCurItem)
301 {
302 pCurItem->pNext = pNewItem;
303 pCurItem = pNewItem;
304 }
305 else
306 {
307 pCurItem = m_pItems = pNewItem;
308 }
309 }
310 }
311
312 HeapFree(GetProcessHeap(), 0, lpValues);
314
315 return TRUE;
316}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define KEY_READ
Definition: nt_native.h:1026

Referenced by LoadAllItems().

◆ LoadItem()

CNewMenu::SHELLNEW_ITEM * CNewMenu::LoadItem ( LPCWSTR  pwszExt)
private

Definition at line 83 of file CNewMenu.cpp.

84{
85 HKEY hKey;
86 WCHAR wszBuf[MAX_PATH];
89
90 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s\\ShellNew", pwszExt);
91
92 TRACE("LoadItem Keyname %s Name %s\n", debugstr_w(pwszExt), debugstr_w(wszBuf));
93
95 {
96 WCHAR wszValue[MAX_PATH];
97 cbData = sizeof(wszValue);
98 if (RegGetValueW(HKEY_CLASSES_ROOT, pwszExt, NULL, RRF_RT_REG_SZ, NULL, wszValue,
99 &cbData) != ERROR_SUCCESS || !wszValue[0])
100 {
101 TRACE("Failed to open key\n");
102 return NULL;
103 }
104 wszValue[_countof(wszValue) - 1] = UNICODE_NULL; // Avoid buffer overrun
105 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s\\%s\\ShellNew", pwszExt, wszValue);
107 {
108 TRACE("Failed to open key\n");
109 return NULL;
110 }
111 }
112
113 /* Find first valid value */
114 struct
115 {
116 LPCWSTR pszName;
118 BOOL bNeedData;
119 BOOL bStr;
120 } Types[] = {
121 {L"FileName", SHELLNEW_TYPE_FILENAME, TRUE, TRUE},
122 {L"Command", SHELLNEW_TYPE_COMMAND, TRUE, TRUE},
123 {L"Data", SHELLNEW_TYPE_DATA, TRUE, FALSE},
124 {L"NullFile", SHELLNEW_TYPE_NULLFILE, FALSE},
125 {NULL}
126 };
127 UINT i;
128
129 for (i = 0; Types[i].pszName; ++i)
130 {
131 /* Note: We are using ANSI function because strings can be treated as data */
132 cbData = 0;
134 DWORD dwType;
136 {
137 if (Types[i].bNeedData && cbData > 0)
138 {
140 RegGetValueW(hKey, NULL, Types[i].pszName, dwFlags, &dwType, pData, &cbData);
141 if (!Types[i].bStr && (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
142 {
143 PBYTE pData2 = (PBYTE)malloc(cbData);
145 free(pData);
146 pData = pData2;
147 }
148 }
149 break;
150 }
151 }
153
154 /* Was any key found? */
155 if (!Types[i].pszName)
156 {
157 free(pData);
158 return NULL;
159 }
160
161 SHFILEINFOW fi;
163 {
164 free(pData);
165 return NULL;
166 }
167
168 /* Create new item */
169 SHELLNEW_ITEM *pNewItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM)));
170 if (!pNewItem)
171 {
172 free(pData);
173 return NULL;
174 }
175
176 TRACE("new item %ls\n", fi.szTypeName);
177 pNewItem->Type = Types[i].Type;
178 pNewItem->pData = pData;
179 pNewItem->cbData = pData ? cbData : 0;
180 pNewItem->pwszExt = _wcsdup(pwszExt);
181 pNewItem->pwszDesc = _wcsdup(fi.szTypeName);
182 if (fi.hIcon)
183 pNewItem->hIcon = fi.hIcon;
184
185 return pNewItem;
186}
Type
Definition: Type.h:7
char ACPI_OBJECT_TYPE * Types
Definition: acdebug.h:354
SHELLNEW_TYPE
Definition: CNewMenu.h:37
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
#define CP_ACP
Definition: compat.h:109
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define WideCharToMultiByte
Definition: compat.h:111
_ACRTIMP wchar_t *__cdecl _wcsdup(const wchar_t *) __WINE_DEALLOC(free) __WINE_MALLOC
Definition: wcs.c:81
#define RRF_RT_REG_SZ
Definition: driver.c:575
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define REG_SZ
Definition: layer.c:22
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define REG_EXPAND_SZ
Definition: nt_native.h:1497
#define UNICODE_NULL
BYTE * PBYTE
Definition: pedump.c:66
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:430
#define SHGFI_ICON
Definition: shellapi.h:164
#define SHGFI_TYPENAME
Definition: shellapi.h:167
#define SHGFI_USEFILEATTRIBUTES
Definition: shellapi.h:181
#define SHGFI_SMALLICON
Definition: shellapi.h:176
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
WCHAR szTypeName[80]
Definition: shellapi.h:388
HICON hIcon
Definition: shellapi.h:384
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
#define RRF_RT_ANY
Definition: winreg.h:66
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
char * LPSTR
Definition: xmlstorage.h:182

Referenced by CacheItems(), and LoadCachedItems().

◆ NewItemByCommand()

HRESULT CNewMenu::NewItemByCommand ( SHELLNEW_ITEM pItem,
LPCWSTR  wszPath 
)
private

Definition at line 494 of file CNewMenu.cpp.

495{
496 WCHAR wszBuf[MAX_PATH];
497 LPWSTR Ptr, pwszCmd;
498 WCHAR wszTemp[MAX_PATH];
501
502 if (!ExpandEnvironmentStringsW((LPWSTR)pItem->pData, wszBuf, _countof(wszBuf)))
503 {
504 TRACE("ExpandEnvironmentStrings failed\n");
505 return E_FAIL;
506 }
507
508 /* Expand command parameter, FIXME: there can be more modifiers */
509 Ptr = wcsstr(wszBuf, L"%1");
510 if (Ptr)
511 {
512 Ptr[1] = L's';
513 StringCbPrintfW(wszTemp, sizeof(wszTemp), wszBuf, wszPath);
514 pwszCmd = wszTemp;
515 }
516 else
517 {
518 pwszCmd = wszBuf;
519 }
520
521 /* Create process */
522 ZeroMemory(&si, sizeof(si));
523 si.cb = sizeof(si);
524 if (CreateProcessW(NULL, pwszCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
525 {
528 return S_OK;
529 }
530 else
531 {
532 ERR("Failed to create process\n");
533 return E_FAIL;
534 }
535}
#define CloseHandle
Definition: compat.h:739
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:520
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4442
_ACRTIMP wchar_t *__cdecl wcsstr(const wchar_t *, const wchar_t *)
Definition: wcs.c:2993
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
static PROCESS_INFORMATION pi
Definition: debugger.c:2303
static SYSTEM_INFO si
Definition: virtual.c:39

Referenced by CreateNewItem().

◆ NewItemByNonCommand()

HRESULT CNewMenu::NewItemByNonCommand ( SHELLNEW_ITEM pItem,
LPWSTR  wszName,
DWORD  cchNameMax,
LPCWSTR  wszPath 
)
private

Definition at line 537 of file CNewMenu.cpp.

539{
540 BOOL bSuccess = TRUE;
541
542 CStringW strNewItem;
543 strNewItem.Format(IDS_NEWITEMFORMAT, pItem->pwszDesc);
544 strNewItem += pItem->pwszExt;
545
546 /* Create the name of the new file */
547 if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, strNewItem))
548 return E_FAIL;
549
550 /* Create new file */
553 {
554 if (pItem->Type == SHELLNEW_TYPE_DATA)
555 {
556 /* Write a content */
557 DWORD cbWritten;
558 WriteFile(hFile, pItem->pData, pItem->cbData, &cbWritten, NULL);
559 }
560
561 /* Close file now */
563 }
564 else
565 {
566 bSuccess = FALSE;
567 }
568
569 if (pItem->Type == SHELLNEW_TYPE_FILENAME)
570 {
571 /* Copy file */
572 if (!CopyFileW((LPWSTR)pItem->pData, wszName, FALSE))
573 ERR("Copy file failed: %ls\n", (LPWSTR)pItem->pData);
574 }
575
576 /* Show message if we failed */
577 if (bSuccess)
578 {
579 TRACE("Notifying fs %s\n", debugstr_w(wszName));
581 }
582 else
583 {
586 Message.FormatMessage(Message.GetString(), wszName);
588 }
589
590 return S_OK;
591}
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:365
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static const WCHAR Message[]
Definition: register.c:74
#define CREATE_NEW
Definition: disk.h:69
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
#define SHCNE_CREATE
Definition: shlobj.h:1898
#define IDS_NEWITEMFORMAT
Definition: shresdef.h:141
#define IDS_CREATEFILE_DENIED
Definition: shresdef.h:119
#define IDS_CREATEFILE_CAPTION
Definition: shresdef.h:118
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONEXCLAMATION
Definition: winuser.h:796
#define MB_OK
Definition: winuser.h:801
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by CreateNewItem().

◆ QueryContextMenu()

HRESULT WINAPI CNewMenu::QueryContextMenu ( HMENU  hMenu,
UINT  indexMenu,
UINT  idCmdFirst,
UINT  idCmdLast,
UINT  uFlags 
)
override

Implements IContextMenu.

Definition at line 643 of file CNewMenu.cpp.

648{
649 MENUITEMINFOW mii;
650 UINT cItems = 0;
651 WCHAR wszNew[200];
652
653 TRACE("%p %p %u %u %u %u\n", this,
654 hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
655
657 return E_FAIL;
658
660 if (!m_hSubMenu)
661 return E_FAIL;
662
663 cItems = InsertShellNewItems(m_hSubMenu, idCmdFirst, 0);
664
665 ZeroMemory(&mii, sizeof(mii));
666 mii.cbSize = sizeof(mii);
668 mii.fType = MFT_STRING;
669 mii.wID = -1;
670 mii.dwTypeData = wszNew;
671 mii.cch = wcslen(mii.dwTypeData);
672 mii.fState = MFS_ENABLED;
673 mii.hSubMenu = m_hSubMenu;
674
675 if (!InsertMenuItemW(hMenu, indexMenu, TRUE, &mii))
676 return E_FAIL;
677
678 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, cItems);
679}
UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu)
Definition: CNewMenu.cpp:336
UINT uFlags
Definition: api.c:59
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:29
#define FCIDM_SHVIEW_NEW
Definition: shresdef.h:138
#define SEVERITY_SUCCESS
Definition: winerror.h:177
HMENU WINAPI CreateMenu(void)
Definition: menu.c:829
#define MIIM_STATE
Definition: winuser.h:732
#define MIIM_SUBMENU
Definition: winuser.h:734
#define MFS_ENABLED
Definition: winuser.h:761
#define MFT_STRING
Definition: winuser.h:757

◆ SelectNewItem()

HRESULT CNewMenu::SelectNewItem ( LONG  wEventId,
UINT  uFlags,
LPWSTR  pszName,
BOOL  bRename 
)
private

Definition at line 426 of file CNewMenu.cpp.

427{
430 HRESULT hr = E_FAIL;
431 LPITEMIDLIST pidl;
432 PITEMID_CHILD pidlNewItem;
433 DWORD dwSelectFlags;
434
435 dwSelectFlags = SVSI_DESELECTOTHERS | SVSI_ENSUREVISIBLE | SVSI_FOCUSED | SVSI_SELECT;
436 if (bRename)
437 dwSelectFlags |= SVSI_EDIT;
438
439 /* Notify the view object about the new item */
440 SHChangeNotify(wEventId, uFlags | SHCNF_FLUSH, (LPCVOID)pszName, NULL);
441
442 if (!m_pSite)
443 return S_OK;
444
445 /* Get a pointer to the shell view */
446 hr = IUnknown_QueryService(m_pSite, SID_SFolderView, IID_PPV_ARG(IShellView, &lpSV));
448 return S_OK;
449
450 /* Attempt to get the pidl of the new item */
451 hr = SHILCreateFromPathW(pszName, &pidl, NULL);
453 return hr;
454
455 pidlNewItem = ILFindLastID(pidl);
456
457 hr = lpSV->SelectItem(pidlNewItem, dwSelectFlags);
458
459 SHFree(pidl);
460
461 return hr;
462}
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:370
HRESULT WINAPI IUnknown_QueryService(IUnknown *, REFGUID, REFIID, LPVOID *)
Definition: ordinal.c:1501
CONST void * LPCVOID
Definition: minwindef.h:164
HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST *ppidl, DWORD *attributes)
Definition: pidl.c:404
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:199
#define SHCNF_FLUSH
Definition: shlobj.h:1936
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define IID_PPV_ARG(Itype, ppType)

Referenced by CreateNewFolder(), and NewItemByNonCommand().

◆ SetSite()

HRESULT STDMETHODCALLTYPE CNewMenu::SetSite ( IUnknown pUnkSite)
override

Implements IObjectWithSite.

Definition at line 630 of file CNewMenu.cpp.

631{
632 m_pSite = pUnkSite;
633 return S_OK;
634}

◆ UnloadAllItems()

void CNewMenu::UnloadAllItems ( )
private

Definition at line 68 of file CNewMenu.cpp.

69{
70 SHELLNEW_ITEM *pCurItem;
71
72 /* Unload the handler items, including the link item */
73 while (m_pItems)
74 {
75 pCurItem = m_pItems;
77 UnloadItem(pCurItem);
78 }
79 m_pItems = NULL;
81}
void UnloadItem(SHELLNEW_ITEM *pItem)
Definition: CNewMenu.cpp:55

Referenced by LoadAllItems(), and ~CNewMenu().

◆ UnloadItem()

void CNewMenu::UnloadItem ( SHELLNEW_ITEM pItem)
private

Definition at line 55 of file CNewMenu.cpp.

56{
57 /* Note: free allows NULL as argument */
58 free(pItem->pData);
59 free(pItem->pwszDesc);
60 free(pItem->pwszExt);
61
62 if (pItem->hIcon)
63 DestroyIcon(pItem->hIcon);
64
65 HeapFree(GetProcessHeap(), 0, pItem);
66}

Referenced by UnloadAllItems().

Member Data Documentation

◆ m_bCustomIconFolder

BOOL CNewMenu::m_bCustomIconFolder
private

Definition at line 62 of file CNewMenu.h.

Referenced by Initialize(), and ~CNewMenu().

◆ m_bCustomIconLink

BOOL CNewMenu::m_bCustomIconLink
private

Definition at line 62 of file CNewMenu.h.

Referenced by Initialize(), and ~CNewMenu().

◆ m_hIconFolder

HICON CNewMenu::m_hIconFolder
private

Definition at line 63 of file CNewMenu.h.

Referenced by HandleMenuMsg2(), Initialize(), and ~CNewMenu().

◆ m_hIconLink

HICON CNewMenu::m_hIconLink
private

Definition at line 63 of file CNewMenu.h.

Referenced by HandleMenuMsg2(), Initialize(), and ~CNewMenu().

◆ m_hSubMenu

HMENU CNewMenu::m_hSubMenu
private

Definition at line 60 of file CNewMenu.h.

Referenced by FindItemFromIdOffset(), and QueryContextMenu().

◆ m_idCmdFirst

UINT CNewMenu::m_idCmdFirst
private

◆ m_idCmdFolder

UINT CNewMenu::m_idCmdFolder
private

◆ m_idCmdLink

UINT CNewMenu::m_idCmdLink
private

Definition at line 61 of file CNewMenu.h.

Referenced by FindItemFromIdOffset(), HandleMenuMsg2(), and InsertShellNewItems().

◆ m_pidlFolder

LPITEMIDLIST CNewMenu::m_pidlFolder
private

Definition at line 56 of file CNewMenu.h.

Referenced by CreateNewFolder(), CreateNewItem(), Initialize(), and ~CNewMenu().

◆ m_pItems

SHELLNEW_ITEM* CNewMenu::m_pItems
private

◆ m_pLinkItem

◆ m_pSite

CComPtr<IUnknown> CNewMenu::m_pSite
private

Definition at line 59 of file CNewMenu.h.

Referenced by GetSite(), SelectNewItem(), and SetSite().


The documentation for this class was generated from the following files: