ReactOS 0.4.15-dev-7961-gdcf9eb0
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:938
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2053

Member Function Documentation

◆ CacheItems()

BOOL CNewMenu::CacheItems ( )
private

Definition at line 176 of file CNewMenu.cpp.

177{
178 HKEY hKey;
179 DWORD dwSize = 0;
180 DWORD dwIndex = 0;
181 LPWSTR lpValue;
182 LPWSTR lpValues;
183 WCHAR wszName[MAX_PATH];
184 SHELLNEW_ITEM *pNewItem;
185 SHELLNEW_ITEM *pCurItem = NULL;
186
187 /* Enumerate all extensions */
188 while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS)
189 {
190 if (wszName[0] != L'.')
191 continue;
192
193 pNewItem = LoadItem(wszName);
194 if (pNewItem)
195 {
196 dwSize += wcslen(wszName) + 1;
197 if (!m_pLinkItem && wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
198 {
199 /* The unique link handler */
200 m_pLinkItem = pNewItem;
201 }
202
203 /* Add at the end of the list */
204 if (pCurItem)
205 {
206 pCurItem->pNext = pNewItem;
207 pCurItem = pNewItem;
208 }
209 else
210 {
211 pCurItem = m_pItems = pNewItem;
212 }
213 }
214 }
215
216 dwSize++;
217
218 lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize * sizeof(WCHAR));
219 if (!lpValues)
220 return FALSE;
221
222 for (pCurItem = m_pItems, lpValue = lpValues; pCurItem; pCurItem = pCurItem->pNext)
223 {
224 memcpy(lpValue, pCurItem->pwszExt, (wcslen(pCurItem->pwszExt) + 1) * sizeof(WCHAR));
225 lpValue += wcslen(pCurItem->pwszExt) + 1;
226 }
227
229 {
230 HeapFree(GetProcessHeap(), 0, lpValues);
231 return FALSE;
232 }
233
234 if (RegSetValueExW(hKey, L"Classes", NULL, REG_MULTI_SZ, (LPBYTE)lpValues, dwSize * sizeof(WCHAR)) != ERROR_SUCCESS)
235 {
236 HeapFree(GetProcessHeap(), 0, lpValues);
238 return FALSE;
239 }
240
241 HeapFree(GetProcessHeap(), 0, lpValues);
243
244 return TRUE;
245}
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
#define wcsicmp
Definition: compat.h:15
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#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:1057
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define KEY_WRITE
Definition: nt_native.h:1031
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:68
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:501
#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 452 of file CNewMenu.cpp.

453{
454 WCHAR wszPath[MAX_PATH];
455 WCHAR wszName[MAX_PATH];
456 WCHAR wszNewFolder[25];
457 HRESULT hr;
458
459 /* Get folder path */
462 return hr;
463
464 if (!LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, _countof(wszNewFolder)))
465 return E_FAIL;
466
467 /* Create the name of the new directory */
468 if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, wszNewFolder))
469 return E_FAIL;
470
471 /* Create the new directory and show the appropriate dialog in case of error */
472 if (SHCreateDirectory(lpici->hwnd, wszName) != ERROR_SUCCESS)
473 return E_FAIL;
474
475 /* Show and select the new item in the def view */
477
478 return S_OK;
479}
#define shell32_hInstance
HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
Definition: CNewMenu.cpp:413
#define E_FAIL
Definition: ddrawi.h:102
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname)
Definition: shellpath.c:699
#define IDS_NEWFOLDER
#define S_OK
Definition: intsafe.h:52
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1353
int WINAPI SHCreateDirectory(HWND hWnd, LPCWSTR path)
Definition: shlfileop.cpp:847
HRESULT hr
Definition: shlfolder.c:183
#define SHCNE_MKDIR
Definition: shlobj.h:1878
#define SHCNF_PATHW
Definition: shlobj.h:1910
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)

Referenced by InvokeCommand().

◆ CreateNewItem()

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

Definition at line 580 of file CNewMenu.cpp.

581{
582 HRESULT hr;
583 WCHAR wszPath[MAX_PATH], wszName[MAX_PATH];
584
585 /* Get folder path */
588 return hr;
589
590 if (pItem == m_pLinkItem)
591 {
592 NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
593 NewItemByCommand(pItem, wszName);
594 return S_OK;
595 }
596
597 switch (pItem->Type)
598 {
600 NewItemByCommand(pItem, wszPath);
601 break;
602
606 NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
607 break;
608
610 ERR("Invalid type\n");
611 break;
612 }
613
614 return S_OK;
615}
#define ERR(fmt,...)
Definition: debug.h:110
HRESULT NewItemByNonCommand(SHELLNEW_ITEM *pItem, LPWSTR wszName, DWORD cchNameMax, LPCWSTR wszPath)
Definition: CNewMenu.cpp:524
HRESULT NewItemByCommand(SHELLNEW_ITEM *pItem, LPCWSTR wszPath)
Definition: CNewMenu.cpp:481

Referenced by InvokeCommand().

◆ FindItemFromIdOffset()

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

Definition at line 391 of file CNewMenu.cpp.

392{
393 /* Folder */
394 if (m_idCmdFirst + IdOffset == m_idCmdFolder)
395 return NULL;
396
397 /* Shortcut */
398 if (m_idCmdFirst + IdOffset == m_idCmdLink)
399 return m_pLinkItem;
400
401 /* Find shell new item - Retrieve menu item info */
402 MENUITEMINFOW mii;
403 ZeroMemory(&mii, sizeof(mii));
404 mii.cbSize = sizeof(mii);
405 mii.fMask = MIIM_DATA;
406
407 if (GetMenuItemInfoW(m_hSubMenu, m_idCmdFirst + IdOffset, FALSE, &mii) && mii.dwItemData)
408 return (SHELLNEW_ITEM *)mii.dwItemData;
409 else
410 return NULL;
411}
HMENU m_hSubMenu
Definition: CNewMenu.h:60
ULONG_PTR dwItemData
Definition: winuser.h:3268
#define ZeroMemory
Definition: winbase.h:1712
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
#define MIIM_DATA
Definition: winuser.h:726

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 691 of file CNewMenu.cpp.

696{
697 FIXME("%p %lu %u %p %p %u\n", this,
698 idCmd, uType, pwReserved, pszName, cchMax );
699
700 return E_NOTIMPL;
701}
UINT cchMax
#define FIXME(fmt,...)
Definition: debug.h:111
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ GetSite()

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

Definition at line 623 of file CNewMenu.cpp.

624{
625 return m_pSite->QueryInterface(riid, ppvSite);
626}
REFIID riid
Definition: atlbase.h:39

◆ HandleMenuMsg()

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

Implements IContextMenu2.

Definition at line 705 of file CNewMenu.cpp.

706{
707 return S_OK;
708}

◆ HandleMenuMsg2()

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

Implements IContextMenu3.

Definition at line 712 of file CNewMenu.cpp.

713{
714 switch (uMsg)
715 {
716 case WM_MEASUREITEM:
717 {
718 MEASUREITEMSTRUCT* lpmis = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
719 if (!lpmis || lpmis->CtlType != ODT_MENU)
720 break;
721
724 if (lpmis->itemHeight < 16)
725 lpmis->itemHeight = 16;
726
727 if (plResult)
728 *plResult = TRUE;
729 break;
730 }
731 case WM_DRAWITEM:
732 {
733 DRAWITEMSTRUCT* lpdis = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
734 if (!lpdis || lpdis->CtlType != ODT_MENU)
735 break;
736
737 DWORD id = LOWORD(lpdis->itemID);
738 HICON hIcon = NULL;
739 if (m_idCmdFirst + id == m_idCmdFolder)
740 {
742 }
743 else if (m_idCmdFirst + id == m_idCmdLink)
744 {
746 }
747 else
748 {
749 SHELLNEW_ITEM *pItem = FindItemFromIdOffset(id);
750 if (pItem)
751 hIcon = pItem->hIcon;
752 }
753
754 if (!hIcon)
755 break;
756
757 DrawIconEx(lpdis->hDC,
758 2,
759 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
760 hIcon,
761 16,
762 16,
763 0, NULL, DI_NORMAL);
764
765 if(plResult)
766 *plResult = TRUE;
767 }
768 }
769
770 return S_OK;
771}
SHELLNEW_ITEM * FindItemFromIdOffset(UINT IdOffset)
Definition: CNewMenu.cpp:391
LPARAM lParam
Definition: combotst.c:139
static HICON
Definition: imagelist.c:84
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
#define DI_NORMAL
Definition: wingdi.h:72
#define SM_CXMENUCHECK
Definition: winuser.h:1031
#define WM_DRAWITEM
Definition: winuser.h:1645
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:2028
#define WM_MEASUREITEM
Definition: winuser.h:1646
#define ODT_MENU
Definition: winuser.h:2537
int WINAPI GetSystemMetrics(_In_ int)

◆ Initialize()

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

Implements IShellExtInit.

Definition at line 774 of file CNewMenu.cpp.

776{
778 WCHAR wszIconPath[MAX_PATH];
779 int icon_idx;
780
781 m_pidlFolder = ILClone(pidlFolder);
782
783 /* Load folder and shortcut icons */
784 if (HLM_GetIconW(IDI_SHELL_FOLDER - 1, wszIconPath, _countof(wszIconPath), &icon_idx))
785 {
786 ::ExtractIconExW(wszIconPath, icon_idx, &m_hIconFolder, NULL, 1);
788 }
789 else
790 {
792 }
793
794 if (HLM_GetIconW(IDI_SHELL_SHORTCUT - 1, wszIconPath, _countof(wszIconPath), &icon_idx))
795 {
796 ::ExtractIconExW(wszIconPath, icon_idx, &m_hIconLink, NULL, 1);
798 }
799 else
800 {
802 }
803
804 return S_OK;
805}
#define IDI_SHELL_FOLDER
Definition: treeview.c:36
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:849
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:237
_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:580
int32_t INT
Definition: typedefs.h:58
#define IMAGE_ICON
Definition: winuser.h:212
#define SM_CYSMICON
Definition: winuser.h:1013
#define SM_CXSMICON
Definition: winuser.h:1012
#define LR_SHARED
Definition: winuser.h:1100
#define LoadImage
Definition: winuser.h:5815
#define MAKEINTRESOURCE
Definition: winuser.h:591

◆ InsertShellNewItems()

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

Definition at line 323 of file CNewMenu.cpp.

324{
325 MENUITEMINFOW mii;
326 UINT idCmd = idCmdFirst;
327 WCHAR wszBuf[256];
328
329 if (m_pItems == NULL)
330 {
331 if (!LoadAllItems())
332 return 0;
333 }
334
335 ZeroMemory(&mii, sizeof(mii));
336 mii.cbSize = sizeof(mii);
337
338 m_idCmdFirst = idCmd;
339
340 /* Insert the new folder action */
342 wszBuf[0] = 0;
344 mii.dwTypeData = wszBuf;
345 mii.cch = wcslen(mii.dwTypeData);
346 mii.wID = idCmd;
347 mii.hbmpItem = HBMMENU_CALLBACK;
348 if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
349 m_idCmdFolder = idCmd++;
350
351 /* Insert the new shortcut action */
352 if (m_pLinkItem)
353 {
355 wszBuf[0] = 0;
356 mii.dwTypeData = wszBuf;
357 mii.cch = wcslen(mii.dwTypeData);
358 mii.wID = idCmd;
359 if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
360 m_idCmdLink = idCmd++;
361 }
362
363 /* Insert a seperator for the custom new action */
364 mii.fMask = MIIM_TYPE | MIIM_ID;
365 mii.fType = MFT_SEPARATOR;
366 mii.wID = -1;
367 InsertMenuItemW(hMenu, Pos++, TRUE, &mii);
368
369 /* Insert the rest of the items */
371 mii.fType = 0;
372
373 for (SHELLNEW_ITEM *pCurItem = m_pItems; pCurItem; pCurItem = pCurItem->pNext)
374 {
375 /* Skip shortcut item */
376 if (pCurItem == m_pLinkItem)
377 continue;
378
379 TRACE("szDesc %s\n", debugstr_w(pCurItem->pwszDesc));
380 mii.dwItemData = (ULONG_PTR)pCurItem;
381 mii.dwTypeData = pCurItem->pwszDesc;
382 mii.cch = wcslen(mii.dwTypeData);
383 mii.wID = idCmd;
384 if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
385 ++idCmd;
386 }
387
388 return idCmd - idCmdFirst;
389}
BOOL LoadAllItems()
Definition: CNewMenu.cpp:306
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:849
#define FCIDM_SHVIEW_NEWLINK
Definition: shresdef.h:848
#define TRACE(s)
Definition: solgame.cpp:4
LPWSTR dwTypeData
Definition: winuser.h:3269
#define MIIM_STRING
Definition: winuser.h:727
#define MIIM_ID
Definition: winuser.h:722
#define MFT_SEPARATOR
Definition: winuser.h:744
#define MIIM_BITMAP
Definition: winuser.h:728
#define HBMMENU_CALLBACK
Definition: winuser.h:2630
#define MIIM_TYPE
Definition: winuser.h:725
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 670 of file CNewMenu.cpp.

671{
672 HRESULT hr = E_FAIL;
673
674 if (m_idCmdFirst + LOWORD(lpici->lpVerb) == m_idCmdFolder)
675 {
676 hr = CreateNewFolder(lpici);
677 }
678 else
679 {
680 SHELLNEW_ITEM *pItem = FindItemFromIdOffset(LOWORD(lpici->lpVerb));
681 if (pItem)
682 hr = CreateNewItem(pItem, lpici);
683 }
684
685 TRACE("CNewMenu::InvokeCommand %x\n", hr);
686 return hr;
687}
HRESULT CreateNewItem(SHELLNEW_ITEM *pItem, LPCMINVOKECOMMANDINFO lpcmi)
Definition: CNewMenu.cpp:580
HRESULT CreateNewFolder(LPCMINVOKECOMMANDINFO lpici)
Definition: CNewMenu.cpp:452

◆ LoadAllItems()

BOOL CNewMenu::LoadAllItems ( )
private

Definition at line 306 of file CNewMenu.cpp.

307{
308 // TODO: We need to find a way to refresh the cache from time to time, when
309 // e.g. new extensions with ShellNew handlers have been added or removed.
310
311 /* If there are any unload them */
313
314 if (!LoadCachedItems())
315 {
316 CacheItems();
317 }
318
319 return (m_pItems != NULL);
320}
BOOL LoadCachedItems()
Definition: CNewMenu.cpp:248
BOOL CacheItems()
Definition: CNewMenu.cpp:176

Referenced by InsertShellNewItems().

◆ LoadCachedItems()

BOOL CNewMenu::LoadCachedItems ( )
private

Definition at line 248 of file CNewMenu.cpp.

249{
250 LPWSTR wszName;
251 LPWSTR lpValues;
253 HKEY hKey;
254 SHELLNEW_ITEM *pNewItem;
255 SHELLNEW_ITEM *pCurItem = NULL;
256
258 return FALSE;
259
260 if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, NULL, &dwSize) != ERROR_SUCCESS)
261 return FALSE;
262
263 lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwSize);
264 if (!lpValues)
265 return FALSE;
266
267 if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, (LPBYTE)lpValues, &dwSize) != ERROR_SUCCESS)
268 {
269 HeapFree(GetProcessHeap(), 0, lpValues);
270 return FALSE;
271 }
272
273 wszName = lpValues;
274
275 for (; *wszName != '\0'; wszName += wcslen(wszName) + 1)
276 {
277 pNewItem = LoadItem(wszName);
278 if (pNewItem)
279 {
280 if (!m_pLinkItem && wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
281 {
282 /* The unique link handler */
283 m_pLinkItem = pNewItem;
284 }
285
286 /* Add at the end of the list */
287 if (pCurItem)
288 {
289 pCurItem->pNext = pNewItem;
290 pCurItem = pNewItem;
291 }
292 else
293 {
294 pCurItem = m_pItems = pNewItem;
295 }
296 }
297 }
298
299 HeapFree(GetProcessHeap(), 0, lpValues);
301
302 return TRUE;
303}
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:1023

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];
88 DWORD cbData;
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 TRACE("Failed to open key\n");
97 return NULL;
98 }
99
100 /* Find first valid value */
101 struct
102 {
103 LPCWSTR pszName;
105 BOOL bNeedData;
106 BOOL bStr;
107 } Types[] = {
108 {L"FileName", SHELLNEW_TYPE_FILENAME, TRUE, TRUE},
109 {L"Command", SHELLNEW_TYPE_COMMAND, TRUE, TRUE},
110 {L"Data", SHELLNEW_TYPE_DATA, TRUE, FALSE},
111 {L"NullFile", SHELLNEW_TYPE_NULLFILE, FALSE},
112 {NULL}
113 };
114 UINT i;
115
116 for (i = 0; Types[i].pszName; ++i)
117 {
118 /* Note: We are using ANSI function because strings can be treated as data */
119 cbData = 0;
121 DWORD dwType;
122 if (RegGetValueW(hKey, NULL, Types[i].pszName, dwFlags, NULL, NULL, &cbData) == ERROR_SUCCESS)
123 {
124 if (Types[i].bNeedData && cbData > 0)
125 {
126 pData = (PBYTE)malloc(cbData);
127 RegGetValueW(hKey, NULL, Types[i].pszName, dwFlags, &dwType, pData, &cbData);
128 if (!Types[i].bStr && (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
129 {
130 PBYTE pData2 = (PBYTE)malloc(cbData);
131 cbData = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)pData, -1, (LPSTR)pData2, cbData, NULL, NULL);
132 free(pData);
133 pData = pData2;
134 }
135 }
136 break;
137 }
138 }
140
141 /* Was any key found? */
142 if (!Types[i].pszName)
143 {
144 free(pData);
145 return NULL;
146 }
147
148 SHFILEINFOW fi;
150 {
151 free(pData);
152 return NULL;
153 }
154
155 /* Create new item */
156 SHELLNEW_ITEM *pNewItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM)));
157 if (!pNewItem)
158 {
159 free(pData);
160 return NULL;
161 }
162
163 TRACE("new item %ls\n", fi.szTypeName);
164 pNewItem->Type = Types[i].Type;
165 pNewItem->pData = pData;
166 pNewItem->cbData = pData ? cbData : 0;
167 pNewItem->pwszExt = _wcsdup(pwszExt);
168 pNewItem->pwszDesc = _wcsdup(fi.szTypeName);
169 if (fi.hIcon)
170 pNewItem->hIcon = fi.hIcon;
171
172 return pNewItem;
173}
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
#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
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
BYTE * PBYTE
Definition: pedump.c:66
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:415
#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:376
HICON hIcon
Definition: shellapi.h:372
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define RRF_RT_ANY
Definition: winreg.h:64
char * LPSTR
Definition: xmlstorage.h:182
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by CacheItems(), and LoadCachedItems().

◆ NewItemByCommand()

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

Definition at line 481 of file CNewMenu.cpp.

482{
483 WCHAR wszBuf[MAX_PATH];
484 LPWSTR Ptr, pwszCmd;
485 WCHAR wszTemp[MAX_PATH];
486 STARTUPINFOW si;
488
489 if (!ExpandEnvironmentStringsW((LPWSTR)pItem->pData, wszBuf, _countof(wszBuf)))
490 {
491 TRACE("ExpandEnvironmentStrings failed\n");
492 return E_FAIL;
493 }
494
495 /* Expand command parameter, FIXME: there can be more modifiers */
496 Ptr = wcsstr(wszBuf, L"%1");
497 if (Ptr)
498 {
499 Ptr[1] = L's';
500 StringCbPrintfW(wszTemp, sizeof(wszTemp), wszBuf, wszPath);
501 pwszCmd = wszTemp;
502 }
503 else
504 {
505 pwszCmd = wszBuf;
506 }
507
508 /* Create process */
509 ZeroMemory(&si, sizeof(si));
510 si.cb = sizeof(si);
511 if (CreateProcessW(NULL, pwszCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
512 {
513 CloseHandle(pi.hProcess);
514 CloseHandle(pi.hThread);
515 return S_OK;
516 }
517 else
518 {
519 ERR("Failed to create process\n");
520 return E_FAIL;
521 }
522}
#define CloseHandle
Definition: compat.h:739
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
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:4592
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
static refpint_t pi[]
Definition: server.c:96
DWORD cb
Definition: winbase.h:852

Referenced by CreateNewItem().

◆ NewItemByNonCommand()

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

Definition at line 524 of file CNewMenu.cpp.

526{
528
529 CStringW strNewItem;
530 strNewItem.Format(IDS_NEWITEMFORMAT, pItem->pwszDesc);
531 strNewItem += pItem->pwszExt;
532
533 /* Create the name of the new file */
534 if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, strNewItem))
535 return E_FAIL;
536
537 /* Create new file */
540 {
541 if (pItem->Type == SHELLNEW_TYPE_DATA)
542 {
543 /* Write a content */
544 DWORD cbWritten;
545 WriteFile(hFile, pItem->pData, pItem->cbData, &cbWritten, NULL);
546 }
547
548 /* Close file now */
550 }
551 else
552 {
553 bSuccess = FALSE;
554 }
555
556 if (pItem->Type == SHELLNEW_TYPE_FILENAME)
557 {
558 /* Copy file */
559 if (!CopyFileW((LPWSTR)pItem->pData, wszName, FALSE))
560 ERR("Copy file failed: %ls\n", (LPWSTR)pItem->pData);
561 }
562
563 /* Show message if we failed */
564 if (bSuccess)
565 {
566 TRACE("Notifying fs %s\n", debugstr_w(wszName));
568 }
569 else
570 {
573 Message.FormatMessage(Message.GetString(), wszName);
575 }
576
577 return S_OK;
578}
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:439
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
static BOOLEAN bSuccess
Definition: drive.cpp:433
#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:1876
#define IDS_NEWITEMFORMAT
Definition: shresdef.h:143
#define IDS_CREATEFILE_DENIED
Definition: shresdef.h:121
#define IDS_CREATEFILE_CAPTION
Definition: shresdef.h:120
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONEXCLAMATION
Definition: winuser.h:785
#define MB_OK
Definition: winuser.h:790
#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 630 of file CNewMenu.cpp.

635{
636 MENUITEMINFOW mii;
637 UINT cItems = 0;
638 WCHAR wszNew[200];
639
640 TRACE("%p %p %u %u %u %u\n", this,
641 hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
642
644 return E_FAIL;
645
647 if (!m_hSubMenu)
648 return E_FAIL;
649
650 cItems = InsertShellNewItems(m_hSubMenu, idCmdFirst, 0);
651
652 ZeroMemory(&mii, sizeof(mii));
653 mii.cbSize = sizeof(mii);
655 mii.fType = MFT_STRING;
656 mii.wID = -1;
657 mii.dwTypeData = wszNew;
658 mii.cch = wcslen(mii.dwTypeData);
659 mii.fState = MFS_ENABLED;
660 mii.hSubMenu = m_hSubMenu;
661
662 if (!InsertMenuItemW(hMenu, indexMenu, TRUE, &mii))
663 return E_FAIL;
664
665 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, cItems);
666}
UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu)
Definition: CNewMenu.cpp:323
UINT uFlags
Definition: api.c:59
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
#define FCIDM_SHVIEW_NEW
Definition: shresdef.h:140
#define SEVERITY_SUCCESS
Definition: winerror.h:64
HMENU WINAPI CreateMenu(void)
Definition: menu.c:829
#define MIIM_STATE
Definition: winuser.h:721
#define MIIM_SUBMENU
Definition: winuser.h:723
#define MFS_ENABLED
Definition: winuser.h:750
#define MFT_STRING
Definition: winuser.h:746

◆ SelectNewItem()

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

Definition at line 413 of file CNewMenu.cpp.

414{
417 HRESULT hr = E_FAIL;
418 LPITEMIDLIST pidl;
419 PITEMID_CHILD pidlNewItem;
420 DWORD dwSelectFlags;
421
422 dwSelectFlags = SVSI_DESELECTOTHERS | SVSI_ENSUREVISIBLE | SVSI_FOCUSED | SVSI_SELECT;
423 if (bRename)
424 dwSelectFlags |= SVSI_EDIT;
425
426 /* Notify the view object about the new item */
427 SHChangeNotify(wEventId, uFlags | SHCNF_FLUSH, (LPCVOID)pszName, NULL);
428
429 if (!m_pSite)
430 return S_OK;
431
432 /* Get a pointer to the shell view */
435 return S_OK;
436
437 /* Attempt to get the pidl of the new item */
438 hr = SHILCreateFromPathW(pszName, &pidl, NULL);
440 return hr;
441
442 pidlNewItem = ILFindLastID(pidl);
443
444 hr = lpSV->SelectItem(pidlNewItem, dwSelectFlags);
445
446 SHFree(pidl);
447
448 return hr;
449}
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:326
HRESULT WINAPI IUnknown_QueryService(IUnknown *, REFGUID, REFIID, LPVOID *)
Definition: ordinal.c:1497
HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST *ppidl, DWORD *attributes)
Definition: pidl.c:401
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:198
#define SID_IFolderView
#define SHCNF_FLUSH
Definition: shlobj.h:1913
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
CONST void * LPCVOID
Definition: windef.h:191
#define IID_PPV_ARG(Itype, ppType)

Referenced by CreateNewFolder(), and NewItemByNonCommand().

◆ SetSite()

HRESULT STDMETHODCALLTYPE CNewMenu::SetSite ( IUnknown pUnkSite)
override

Implements IObjectWithSite.

Definition at line 617 of file CNewMenu.cpp.

618{
619 m_pSite = pUnkSite;
620 return S_OK;
621}

◆ 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: