ReactOS  0.4.14-dev-1025-gd1ac13c
CNewMenu Class Reference

#include <CNewMenu.h>

Inheritance diagram for CNewMenu:
Collaboration diagram for CNewMenu:

Classes

struct  SHELLNEW_ITEM
 

Public Member Functions

 CNewMenu ()
 
 ~CNewMenu ()
 
virtual HRESULT STDMETHODCALLTYPE SetSite (IUnknown *pUnkSite)
 
virtual HRESULT STDMETHODCALLTYPE GetSite (REFIID riid, void **ppvSite)
 
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)
 
virtual HRESULT WINAPI HandleMenuMsg2 (UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
 
virtual HRESULT WINAPI HandleMenuMsg (UINT uMsg, WPARAM wParam, LPARAM lParam)
 
virtual HRESULT STDMETHODCALLTYPE Initialize (PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
 
- 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 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 ()
 

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
 
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 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
 
- Public Attributes inherited from IContextMenu
CMIC_MASK_NOZONECHECKS typedef IContextMenuLPCONTEXTMENU
 
- Static Public Attributes inherited from IContextMenu
static CMDSTR_VIEWDETAILSW(const WCHAR []) 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.

Constructor & Destructor Documentation

◆ CNewMenu()

CNewMenu::CNewMenu ( )

Definition at line 28 of file CNewMenu.cpp.

28  :
30  m_pItems(NULL),
32  m_pSite(NULL),
33  m_idCmdFirst(0),
34  m_idCmdFolder(-1),
35  m_idCmdLink(-1),
38 {
39 }
UINT m_idCmdLink
Definition: CNewMenu.h:61
HICON m_hIconLink
Definition: CNewMenu.h:62
UINT m_idCmdFolder
Definition: CNewMenu.h:61
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:57
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
smooth NULL
Definition: ftsmooth.c:416
HICON m_hIconFolder
Definition: CNewMenu.h:62
UINT m_idCmdFirst
Definition: CNewMenu.h:61
CComPtr< IUnknown > m_pSite
Definition: CNewMenu.h:59

◆ ~CNewMenu()

CNewMenu::~CNewMenu ( )

Definition at line 41 of file CNewMenu.cpp.

42 {
44 
45  if (m_pidlFolder)
47 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
void UnloadAllItems()
Definition: CNewMenu.cpp:62

Member Function Documentation

◆ CacheItems()

BOOL CNewMenu::CacheItems ( )
private

Definition at line 170 of file CNewMenu.cpp.

171 {
172  HKEY hKey;
173  DWORD dwSize = 0;
174  DWORD dwIndex = 0;
175  LPWSTR lpValue;
176  LPWSTR lpValues;
177  WCHAR wszName[MAX_PATH];
178  SHELLNEW_ITEM *pNewItem;
179  SHELLNEW_ITEM *pCurItem = NULL;
180 
181  /* Enumerate all extensions */
182  while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS)
183  {
184  if (wszName[0] != L'.')
185  continue;
186 
187  pNewItem = LoadItem(wszName);
188  if (pNewItem)
189  {
190  dwSize += wcslen(wszName) + 1;
191  if (!m_pLinkItem && wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
192  {
193  /* The unique link handler */
194  m_pLinkItem = pNewItem;
195  }
196 
197  /* Add at the end of the list */
198  if (pCurItem)
199  {
200  pCurItem->pNext = pNewItem;
201  pCurItem = pNewItem;
202  }
203  else
204  {
205  pCurItem = m_pItems = pNewItem;
206  }
207  }
208  }
209 
210  dwSize++;
211 
212  lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize * sizeof(WCHAR));
213  if (!lpValues)
214  return FALSE;
215 
216  for (pCurItem = m_pItems, lpValue = lpValues; pCurItem; pCurItem = pCurItem->pNext)
217  {
218  memcpy(lpValue, pCurItem->pwszExt, (wcslen(pCurItem->pwszExt) + 1) * sizeof(WCHAR));
219  lpValue += wcslen(pCurItem->pwszExt) + 1;
220  }
221 
223  {
224  HeapFree(GetProcessHeap(), 0, lpValues);
225  return FALSE;
226  }
227 
228  if (RegSetValueExW(hKey, L"Classes", NULL, REG_MULTI_SZ, (LPBYTE)lpValues, dwSize * sizeof(WCHAR)) != ERROR_SUCCESS)
229  {
230  HeapFree(GetProcessHeap(), 0, lpValues);
231  RegCloseKey(hKey);
232  return FALSE;
233  }
234 
235  HeapFree(GetProcessHeap(), 0, lpValues);
236  RegCloseKey(hKey);
237 
238  return TRUE;
239 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define _countof(array)
Definition: fontsub.cpp:30
#define HKEY_CURRENT_USER
Definition: winreg.h:11
SHELLNEW_ITEM * LoadItem(LPCWSTR pwszExt)
Definition: CNewMenu.cpp:77
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:57
#define REG_MULTI_SZ
Definition: nt_native.h:1501
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
smooth NULL
Definition: ftsmooth.c:416
const WCHAR ShellNewKey[]
Definition: CNewMenu.h:26
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
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:4895
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define wcsicmp
Definition: string.h:1152
LONG WINAPI RegEnumKeyW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cbName)
Definition: reg.c:2416
SHELLNEW_ITEM * pNext
Definition: CNewMenu.h:53
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define RegCreateKeyEx
Definition: winreg.h:501

Referenced by LoadAllItems().

◆ CreateNewFolder()

HRESULT CNewMenu::CreateNewFolder ( LPCMINVOKECOMMANDINFO  lpici)
private

Definition at line 446 of file CNewMenu.cpp.

447 {
448  WCHAR wszPath[MAX_PATH];
449  WCHAR wszName[MAX_PATH];
450  WCHAR wszNewFolder[25];
451  HRESULT hr;
452 
453  /* Get folder path */
455  if (FAILED_UNEXPECTEDLY(hr))
456  return hr;
457 
458  if (!LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, _countof(wszNewFolder)))
459  return E_FAIL;
460 
461  /* Create the name of the new directory */
462  if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, wszNewFolder))
463  return E_FAIL;
464 
465  /* Create the new directory and show the appropriate dialog in case of error */
466  if (SHCreateDirectory(lpici->hwnd, wszName) != ERROR_SUCCESS)
467  return E_FAIL;
468 
469  /* Show and select the new item in the def view */
471 
472  return S_OK;
473 }
#define SHCNE_MKDIR
Definition: shlobj.h:1731
#define IDS_NEWFOLDER
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: fontsub.cpp:30
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
#define E_FAIL
Definition: ddrawi.h:102
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
#define SHCNF_PATHW
Definition: shlobj.h:1763
int WINAPI SHCreateDirectory(HWND hWnd, LPCWSTR path)
Definition: shlfileop.cpp:788
#define S_OK
Definition: intsafe.h:59
BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname)
Definition: shellpath.c:368
HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
Definition: CNewMenu.cpp:407

Referenced by InvokeCommand().

◆ CreateNewItem()

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

Definition at line 575 of file CNewMenu.cpp.

576 {
577  HRESULT hr;
578  WCHAR wszPath[MAX_PATH], wszName[MAX_PATH];
579 
580  /* Get folder path */
582  if (FAILED_UNEXPECTEDLY(hr))
583  return hr;
584 
585  if (pItem == m_pLinkItem)
586  {
587  NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
588  NewItemByCommand(pItem, wszName);
589  return S_OK;
590  }
591 
592  switch (pItem->Type)
593  {
595  NewItemByCommand(pItem, wszPath);
596  break;
597 
598  case SHELLNEW_TYPE_DATA:
601  NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
602  break;
603 
605  ERR("Invalid type\n");
606  break;
607  }
608 
609  return S_OK;
610 }
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: fontsub.cpp:30
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
HRESULT NewItemByCommand(SHELLNEW_ITEM *pItem, LPCWSTR wszPath)
Definition: CNewMenu.cpp:475
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
HRESULT NewItemByNonCommand(SHELLNEW_ITEM *pItem, LPWSTR wszName, DWORD cchNameMax, LPCWSTR wszPath)
Definition: CNewMenu.cpp:518
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59

Referenced by InvokeCommand().

◆ FindItemFromIdOffset()

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

Definition at line 385 of file CNewMenu.cpp.

386 {
387  /* Folder */
388  if (m_idCmdFirst + IdOffset == m_idCmdFolder)
389  return NULL;
390 
391  /* Shortcut */
392  if (m_idCmdFirst + IdOffset == m_idCmdLink)
393  return m_pLinkItem;
394 
395  /* Find shell new item - Retrieve menu item info */
396  MENUITEMINFOW mii;
397  ZeroMemory(&mii, sizeof(mii));
398  mii.cbSize = sizeof(mii);
399  mii.fMask = MIIM_DATA;
400 
401  if (GetMenuItemInfoW(m_hSubMenu, m_idCmdFirst + IdOffset, FALSE, &mii) && mii.dwItemData)
402  return (SHELLNEW_ITEM *)mii.dwItemData;
403  else
404  return NULL;
405 }
UINT m_idCmdLink
Definition: CNewMenu.h:61
#define ZeroMemory
Definition: winbase.h:1642
UINT m_idCmdFolder
Definition: CNewMenu.h:61
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
UINT m_idCmdFirst
Definition: CNewMenu.h:61
HMENU m_hSubMenu
Definition: CNewMenu.h:60
#define MIIM_DATA
Definition: winuser.h:721
ULONG_PTR dwItemData
Definition: winuser.h:3243

Referenced by HandleMenuMsg2(), and InvokeCommand().

◆ GetCommandString()

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

Implements IContextMenu.

Definition at line 686 of file CNewMenu.cpp.

691 {
692  FIXME("%p %lu %u %p %p %u\n", this,
693  idCmd, uType, pwReserved, pszName, cchMax );
694 
695  return E_NOTIMPL;
696 }
#define FIXME(fmt,...)
Definition: debug.h:110
UINT cchMax
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ GetSite()

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

Definition at line 618 of file CNewMenu.cpp.

619 {
620  return m_pSite->QueryInterface(riid, ppvSite);
621 }
REFIID riid
Definition: precomp.h:44
CComPtr< IUnknown > m_pSite
Definition: CNewMenu.h:59

◆ HandleMenuMsg()

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

Implements IContextMenu2.

Definition at line 700 of file CNewMenu.cpp.

701 {
702  return S_OK;
703 }
#define S_OK
Definition: intsafe.h:59

◆ HandleMenuMsg2()

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

Implements IContextMenu3.

Definition at line 707 of file CNewMenu.cpp.

708 {
709  switch (uMsg)
710  {
711  case WM_MEASUREITEM:
712  {
713  MEASUREITEMSTRUCT* lpmis = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
714  if (!lpmis || lpmis->CtlType != ODT_MENU)
715  break;
716 
719  if (lpmis->itemHeight < 16)
720  lpmis->itemHeight = 16;
721 
722  if (plResult)
723  *plResult = TRUE;
724  break;
725  }
726  case WM_DRAWITEM:
727  {
728  DRAWITEMSTRUCT* lpdis = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
729  if (!lpdis || lpdis->CtlType != ODT_MENU)
730  break;
731 
732  DWORD id = LOWORD(lpdis->itemID);
733  HICON hIcon = NULL;
734  if (m_idCmdFirst + id == m_idCmdFolder)
735  {
737  }
738  else if (m_idCmdFirst + id == m_idCmdLink)
739  {
740  hIcon = m_hIconLink;
741  }
742  else
743  {
744  SHELLNEW_ITEM *pItem = FindItemFromIdOffset(id);
745  if (pItem)
746  hIcon = pItem->hIcon;
747  }
748 
749  if (!hIcon)
750  break;
751 
752  DrawIconEx(lpdis->hDC,
753  2,
754  lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
755  hIcon,
756  16,
757  16,
758  0, NULL, DI_NORMAL);
759 
760  if(plResult)
761  *plResult = TRUE;
762  }
763  }
764 
765  return S_OK;
766 }
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
UINT m_idCmdLink
Definition: CNewMenu.h:61
UINT uMsg
Definition: menu.cpp:213
HICON m_hIconLink
Definition: CNewMenu.h:62
#define ODT_MENU
Definition: winuser.h:2512
#define SM_CXMENUCHECK
Definition: winuser.h:1021
LONG top
Definition: windef.h:307
UINT m_idCmdFolder
Definition: CNewMenu.h:61
smooth NULL
Definition: ftsmooth.c:416
HICON m_hIconFolder
Definition: CNewMenu.h:62
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:1997
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT m_idCmdFirst
Definition: CNewMenu.h:61
#define WM_MEASUREITEM
Definition: winuser.h:1628
SHELLNEW_ITEM * FindItemFromIdOffset(UINT IdOffset)
Definition: CNewMenu.cpp:385
#define DI_NORMAL
Definition: wingdi.h:72
#define S_OK
Definition: intsafe.h:59
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define WM_DRAWITEM
Definition: winuser.h:1627
LONG bottom
Definition: windef.h:309
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82

◆ Initialize()

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

Implements IShellExtInit.

Definition at line 769 of file CNewMenu.cpp.

771 {
772  m_pidlFolder = ILClone(pidlFolder);
773 
774  /* Load folder and shortcut icons */
777  return S_OK;
778 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
#define LR_SHARED
Definition: winuser.h:1090
#define IMAGE_ICON
Definition: winuser.h:212
HICON m_hIconLink
Definition: CNewMenu.h:62
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
#define IDI_SHELL_SHORTCUT
Definition: shresdef.h:509
HICON m_hIconFolder
Definition: CNewMenu.h:62
#define IDI_SHELL_FOLDER
Definition: shresdef.h:483
#define S_OK
Definition: intsafe.h:59
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
#define LoadImage
Definition: winuser.h:5790

◆ InsertShellNewItems()

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

Definition at line 317 of file CNewMenu.cpp.

318 {
319  MENUITEMINFOW mii;
320  UINT idCmd = idCmdFirst;
321  WCHAR wszBuf[256];
322 
323  if (m_pItems == NULL)
324  {
325  if (!LoadAllItems())
326  return 0;
327  }
328 
329  ZeroMemory(&mii, sizeof(mii));
330  mii.cbSize = sizeof(mii);
331 
332  m_idCmdFirst = idCmd;
333 
334  /* Insert the new folder action */
336  wszBuf[0] = 0;
338  mii.dwTypeData = wszBuf;
339  mii.cch = wcslen(mii.dwTypeData);
340  mii.wID = idCmd;
341  mii.hbmpItem = HBMMENU_CALLBACK;
342  if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
343  m_idCmdFolder = idCmd++;
344 
345  /* Insert the new shortcut action */
346  if (m_pLinkItem)
347  {
349  wszBuf[0] = 0;
350  mii.dwTypeData = wszBuf;
351  mii.cch = wcslen(mii.dwTypeData);
352  mii.wID = idCmd;
353  if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
354  m_idCmdLink = idCmd++;
355  }
356 
357  /* Insert a seperator for the custom new action */
358  mii.fMask = MIIM_TYPE | MIIM_ID;
359  mii.fType = MFT_SEPARATOR;
360  mii.wID = -1;
361  InsertMenuItemW(hMenu, Pos++, TRUE, &mii);
362 
363  /* Insert the rest of the items */
365  mii.fType = 0;
366 
367  for (SHELLNEW_ITEM *pCurItem = m_pItems; pCurItem; pCurItem = pCurItem->pNext)
368  {
369  /* Skip shortcut item */
370  if (pCurItem == m_pLinkItem)
371  continue;
372 
373  TRACE("szDesc %s\n", debugstr_w(pCurItem->pwszDesc));
374  mii.dwItemData = (ULONG_PTR)pCurItem;
375  mii.dwTypeData = pCurItem->pwszDesc;
376  mii.cch = wcslen(mii.dwTypeData);
377  mii.wID = idCmd;
378  if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
379  ++idCmd;
380  }
381 
382  return idCmd - idCmdFirst;
383 }
#define TRUE
Definition: types.h:120
UINT m_idCmdLink
Definition: CNewMenu.h:61
#define _countof(array)
Definition: fontsub.cpp:30
ush Pos
Definition: deflate.h:92
#define ZeroMemory
Definition: winbase.h:1642
UINT m_idCmdFolder
Definition: CNewMenu.h:61
LPWSTR dwTypeData
Definition: winuser.h:3244
#define FCIDM_SHVIEW_NEWLINK
Definition: shresdef.h:772
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MIIM_BITMAP
Definition: winuser.h:723
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:57
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
#define debugstr_w
Definition: kernel32.h:32
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
smooth NULL
Definition: ftsmooth.c:416
#define FCIDM_SHVIEW_NEWFOLDER
Definition: shresdef.h:773
#define MIIM_ID
Definition: winuser.h:717
#define HBMMENU_CALLBACK
Definition: winuser.h:2605
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
UINT m_idCmdFirst
Definition: CNewMenu.h:61
#define MFT_SEPARATOR
Definition: winuser.h:739
#define MIIM_TYPE
Definition: winuser.h:720
#define MIIM_STRING
Definition: winuser.h:722
SHELLNEW_ITEM * pNext
Definition: CNewMenu.h:53
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
unsigned int UINT
Definition: ndis.h:50
BOOL LoadAllItems()
Definition: CNewMenu.cpp:300
#define ULONG_PTR
Definition: config.h:101
#define MIIM_DATA
Definition: winuser.h:721
ULONG_PTR dwItemData
Definition: winuser.h:3243
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by QueryContextMenu().

◆ InvokeCommand()

HRESULT WINAPI CNewMenu::InvokeCommand ( LPCMINVOKECOMMANDINFO  lpcmi)
virtual

Implements IContextMenu.

Definition at line 665 of file CNewMenu.cpp.

666 {
667  HRESULT hr = E_FAIL;
668 
669  if (m_idCmdFirst + LOWORD(lpici->lpVerb) == m_idCmdFolder)
670  {
671  hr = CreateNewFolder(lpici);
672  }
673  else
674  {
675  SHELLNEW_ITEM *pItem = FindItemFromIdOffset(LOWORD(lpici->lpVerb));
676  if (pItem)
677  hr = CreateNewItem(pItem, lpici);
678  }
679 
680  TRACE("CNewMenu::InvokeCommand %x\n", hr);
681  return hr;
682 }
HRESULT hr
Definition: shlfolder.c:183
UINT m_idCmdFolder
Definition: CNewMenu.h:61
#define E_FAIL
Definition: ddrawi.h:102
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:78
UINT m_idCmdFirst
Definition: CNewMenu.h:61
HRESULT CreateNewItem(SHELLNEW_ITEM *pItem, LPCMINVOKECOMMANDINFO lpcmi)
Definition: CNewMenu.cpp:575
SHELLNEW_ITEM * FindItemFromIdOffset(UINT IdOffset)
Definition: CNewMenu.cpp:385
HRESULT CreateNewFolder(LPCMINVOKECOMMANDINFO lpici)
Definition: CNewMenu.cpp:446
#define LOWORD(l)
Definition: pedump.c:82

◆ LoadAllItems()

BOOL CNewMenu::LoadAllItems ( )
private

Definition at line 300 of file CNewMenu.cpp.

301 {
302  // TODO: We need to find a way to refresh the cache from time to time, when
303  // e.g. new extensions with ShellNew handlers have been added or removed.
304 
305  /* If there are any unload them */
306  UnloadAllItems();
307 
308  if (!LoadCachedItems())
309  {
310  CacheItems();
311  }
312 
313  return (m_pItems != NULL);
314 }
BOOL LoadCachedItems()
Definition: CNewMenu.cpp:242
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:57
smooth NULL
Definition: ftsmooth.c:416
BOOL CacheItems()
Definition: CNewMenu.cpp:170
void UnloadAllItems()
Definition: CNewMenu.cpp:62

Referenced by InsertShellNewItems().

◆ LoadCachedItems()

BOOL CNewMenu::LoadCachedItems ( )
private

Definition at line 242 of file CNewMenu.cpp.

243 {
244  LPWSTR wszName;
245  LPWSTR lpValues;
246  DWORD dwSize;
247  HKEY hKey;
248  SHELLNEW_ITEM *pNewItem;
249  SHELLNEW_ITEM *pCurItem = NULL;
250 
252  return FALSE;
253 
254  if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, NULL, &dwSize) != ERROR_SUCCESS)
255  return FALSE;
256 
257  lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwSize);
258  if (!lpValues)
259  return FALSE;
260 
261  if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, (LPBYTE)lpValues, &dwSize) != ERROR_SUCCESS)
262  {
263  HeapFree(GetProcessHeap(), 0, lpValues);
264  return FALSE;
265  }
266 
267  wszName = lpValues;
268 
269  for (; *wszName != '\0'; wszName += wcslen(wszName) + 1)
270  {
271  pNewItem = LoadItem(wszName);
272  if (pNewItem)
273  {
274  if (!m_pLinkItem && wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
275  {
276  /* The unique link handler */
277  m_pLinkItem = pNewItem;
278  }
279 
280  /* Add at the end of the list */
281  if (pCurItem)
282  {
283  pCurItem->pNext = pNewItem;
284  pCurItem = pNewItem;
285  }
286  else
287  {
288  pCurItem = m_pItems = pNewItem;
289  }
290  }
291  }
292 
293  HeapFree(GetProcessHeap(), 0, lpValues);
294  RegCloseKey(hKey);
295 
296  return TRUE;
297 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
SHELLNEW_ITEM * LoadItem(LPCWSTR pwszExt)
Definition: CNewMenu.cpp:77
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:57
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
smooth NULL
Definition: ftsmooth.c:416
const WCHAR ShellNewKey[]
Definition: CNewMenu.h:26
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define wcsicmp
Definition: string.h:1152
SHELLNEW_ITEM * pNext
Definition: CNewMenu.h:53
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by LoadAllItems().

◆ LoadItem()

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

Definition at line 77 of file CNewMenu.cpp.

78 {
79  HKEY hKey;
80  WCHAR wszBuf[MAX_PATH];
81  PBYTE pData = NULL;
82  DWORD cbData;
83 
84  StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s\\ShellNew", pwszExt);
85 
86  TRACE("LoadItem Keyname %s Name %s\n", debugstr_w(pwszExt), debugstr_w(wszBuf));
87 
88  if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
89  {
90  TRACE("Failed to open key\n");
91  return NULL;
92  }
93 
94  /* Find first valid value */
95  struct
96  {
97  LPCWSTR pszName;
99  BOOL bNeedData;
100  BOOL bStr;
101  } Types[] = {
102  {L"FileName", SHELLNEW_TYPE_FILENAME, TRUE, TRUE},
103  {L"Command", SHELLNEW_TYPE_COMMAND, TRUE, TRUE},
104  {L"Data", SHELLNEW_TYPE_DATA, TRUE, FALSE},
105  {L"NullFile", SHELLNEW_TYPE_NULLFILE, FALSE},
106  {NULL}
107  };
108  UINT i;
109 
110  for (i = 0; Types[i].pszName; ++i)
111  {
112  /* Note: We are using ANSI function because strings can be treated as data */
113  cbData = 0;
115  DWORD dwType;
116  if (RegGetValueW(hKey, NULL, Types[i].pszName, dwFlags, NULL, NULL, &cbData) == ERROR_SUCCESS)
117  {
118  if (Types[i].bNeedData && cbData > 0)
119  {
120  pData = (PBYTE)malloc(cbData);
121  RegGetValueW(hKey, NULL, Types[i].pszName, dwFlags, &dwType, pData, &cbData);
122  if (!Types[i].bStr && (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
123  {
124  PBYTE pData2 = (PBYTE)malloc(cbData);
125  cbData = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)pData, -1, (LPSTR)pData2, cbData, NULL, NULL);
126  free(pData);
127  pData = pData2;
128  }
129  }
130  break;
131  }
132  }
133  RegCloseKey(hKey);
134 
135  /* Was any key found? */
136  if (!Types[i].pszName)
137  {
138  free(pData);
139  return NULL;
140  }
141 
142  SHFILEINFOW fi;
144  {
145  free(pData);
146  return NULL;
147  }
148 
149  /* Create new item */
150  SHELLNEW_ITEM *pNewItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM)));
151  if (!pNewItem)
152  {
153  free(pData);
154  return NULL;
155  }
156 
157  TRACE("new item %ls\n", fi.szTypeName);
158  pNewItem->Type = Types[i].Type;
159  pNewItem->pData = pData;
160  pNewItem->cbData = pData ? cbData : 0;
161  pNewItem->pwszExt = _wcsdup(pwszExt);
162  pNewItem->pwszDesc = _wcsdup(fi.szTypeName);
163  if (fi.hIcon)
164  pNewItem->hIcon = fi.hIcon;
165 
166  return pNewItem;
167 }
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1965
#define TRUE
Definition: types.h:120
#define SHGFI_TYPENAME
Definition: shellapi.h:165
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define KEY_READ
Definition: nt_native.h:1023
#define CP_ACP
Definition: compat.h:99
#define free
Definition: debug_ros.c:5
SHELLNEW_TYPE
Definition: CNewMenu.h:36
#define RRF_RT_REG_SZ
Definition: driver.c:575
char * LPSTR
Definition: xmlstorage.h:182
WCHAR szTypeName[80]
Definition: shellapi.h:374
#define SHGFI_SMALLICON
Definition: shellapi.h:174
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:413
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SHGFI_USEFILEATTRIBUTES
Definition: shellapi.h:179
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
HICON hIcon
Definition: shellapi.h:370
char ACPI_OBJECT_TYPE * Types
Definition: acdebug.h:347
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
unsigned int UINT
Definition: ndis.h:50
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define malloc
Definition: debug_ros.c:4
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define RRF_RT_ANY
Definition: winreg.h:64
WCHAR * LPWSTR
Definition: xmlstorage.h:184
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
#define SHGFI_ICON
Definition: shellapi.h:162
BYTE * PBYTE
Definition: pedump.c:66
#define REG_SZ
Definition: layer.c:22

Referenced by CacheItems(), and LoadCachedItems().

◆ NewItemByCommand()

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

Definition at line 475 of file CNewMenu.cpp.

476 {
477  WCHAR wszBuf[MAX_PATH];
478  LPWSTR Ptr, pwszCmd;
479  WCHAR wszTemp[MAX_PATH];
480  STARTUPINFOW si;
482 
483  if (!ExpandEnvironmentStringsW((LPWSTR)pItem->pData, wszBuf, _countof(wszBuf)))
484  {
485  TRACE("ExpandEnvironmentStrings failed\n");
486  return E_FAIL;
487  }
488 
489  /* Expand command parameter, FIXME: there can be more modifiers */
490  Ptr = wcsstr(wszBuf, L"%1");
491  if (Ptr)
492  {
493  Ptr[1] = L's';
494  StringCbPrintfW(wszTemp, sizeof(wszTemp), wszBuf, wszPath);
495  pwszCmd = wszTemp;
496  }
497  else
498  {
499  pwszCmd = wszBuf;
500  }
501 
502  /* Create process */
503  ZeroMemory(&si, sizeof(si));
504  si.cb = sizeof(si);
505  if (CreateProcessW(NULL, pwszCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
506  {
507  CloseHandle(pi.hProcess);
508  CloseHandle(pi.hThread);
509  return S_OK;
510  }
511  else
512  {
513  ERR("Failed to create process\n");
514  return E_FAIL;
515  }
516 }
#define CloseHandle
Definition: compat.h:406
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define _countof(array)
Definition: fontsub.cpp:30
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define ZeroMemory
Definition: winbase.h:1642
#define E_FAIL
Definition: ddrawi.h:102
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
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:4593
#define TRACE(s)
Definition: solgame.cpp:4
DWORD cb
Definition: winbase.h:824
__wchar_t WCHAR
Definition: xmlstorage.h:180
static refpint_t pi[]
Definition: server.c:96
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by CreateNewItem().

◆ NewItemByNonCommand()

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

Definition at line 518 of file CNewMenu.cpp.

520 {
521  WCHAR wszBuf[MAX_PATH];
522  WCHAR wszNewFile[MAX_PATH];
523  BOOL bSuccess = TRUE;
524 
525  if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEW, wszBuf, _countof(wszBuf)))
526  return E_FAIL;
527 
528  StringCchPrintfW(wszNewFile, _countof(wszNewFile), L"%s %s%s", wszBuf, pItem->pwszDesc, pItem->pwszExt);
529 
530  /* Create the name of the new file */
531  if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, wszNewFile))
532  return E_FAIL;
533 
534  /* Create new file */
537  {
538  if (pItem->Type == SHELLNEW_TYPE_DATA)
539  {
540  /* Write a content */
541  DWORD cbWritten;
542  WriteFile(hFile, pItem->pData, pItem->cbData, &cbWritten, NULL);
543  }
544 
545  /* Close file now */
547  }
548  else
549  {
550  bSuccess = FALSE;
551  }
552 
553  if (pItem->Type == SHELLNEW_TYPE_FILENAME)
554  {
555  /* Copy file */
556  if (!CopyFileW((LPWSTR)pItem->pData, wszName, FALSE))
557  ERR("Copy file failed: %ls\n", (LPWSTR)pItem->pData);
558  }
559 
560  /* Show message if we failed */
561  if (bSuccess)
562  {
563  TRACE("Notifying fs %s\n", debugstr_w(wszName));
564  SelectNewItem(SHCNE_CREATE, SHCNF_PATHW, wszName, pItem != m_pLinkItem);
565  }
566  else
567  {
568  StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Cannot create file: %s", wszName);
569  MessageBoxW(NULL, wszBuf, L"Cannot create file", MB_OK | MB_ICONERROR); // FIXME load localized error msg
570  }
571 
572  return S_OK;
573 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define _countof(array)
Definition: fontsub.cpp:30
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define E_FAIL
Definition: ddrawi.h:102
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
static BOOLEAN bSuccess
Definition: drive.cpp:419
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define debugstr_w
Definition: kernel32.h:32
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
#define FCIDM_SHVIEW_NEW
Definition: shresdef.h:130
#define TRACE(s)
Definition: solgame.cpp:4
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define MB_ICONERROR
Definition: winuser.h:781
_In_ HANDLE hFile
Definition: mswsock.h:90
#define SHCNF_PATHW
Definition: shlobj.h:1763
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define MB_OK
Definition: winuser.h:784
#define CreateFileW
Definition: compat.h:408
#define CREATE_NEW
Definition: disk.h:69
BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname)
Definition: shellpath.c:368
#define SHCNE_CREATE
Definition: shlobj.h:1729
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
Definition: CNewMenu.cpp:407

Referenced by CreateNewItem().

◆ QueryContextMenu()

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

Implements IContextMenu.

Definition at line 625 of file CNewMenu.cpp.

630 {
631  MENUITEMINFOW mii;
632  UINT cItems = 0;
633  WCHAR wszNew[200];
634 
635  TRACE("%p %p %u %u %u %u\n", this,
636  hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
637 
638  if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEW, wszNew, _countof(wszNew)))
639  return E_FAIL;
640 
642  if (!m_hSubMenu)
643  return E_FAIL;
644 
645  cItems = InsertShellNewItems(m_hSubMenu, idCmdFirst, 0);
646 
647  ZeroMemory(&mii, sizeof(mii));
648  mii.cbSize = sizeof(mii);
650  mii.fType = MFT_STRING;
651  mii.wID = -1;
652  mii.dwTypeData = wszNew;
653  mii.cch = wcslen(mii.dwTypeData);
654  mii.fState = MFS_ENABLED;
655  mii.hSubMenu = m_hSubMenu;
656 
657  if (!InsertMenuItemW(hMenu, indexMenu, TRUE, &mii))
658  return E_FAIL;
659 
660  return MAKE_HRESULT(SEVERITY_SUCCESS, 0, cItems);
661 }
HMENU WINAPI CreateMenu(void)
Definition: menu.c:837
#define MFT_STRING
Definition: winuser.h:741
#define TRUE
Definition: types.h:120
#define _countof(array)
Definition: fontsub.cpp:30
#define ZeroMemory
Definition: winbase.h:1642
LPWSTR dwTypeData
Definition: winuser.h:3244
UINT uFlags
Definition: api.c:59
#define E_FAIL
Definition: ddrawi.h:102
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define SEVERITY_SUCCESS
Definition: winerror.h:64
#define MIIM_SUBMENU
Definition: winuser.h:718
#define MFS_ENABLED
Definition: winuser.h:745
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
#define MIIM_STATE
Definition: winuser.h:716
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
#define MIIM_ID
Definition: winuser.h:717
#define FCIDM_SHVIEW_NEW
Definition: shresdef.h:130
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MIIM_TYPE
Definition: winuser.h:720
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
unsigned int UINT
Definition: ndis.h:50
HMENU m_hSubMenu
Definition: CNewMenu.h:60
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu)
Definition: CNewMenu.cpp:317

◆ SelectNewItem()

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

Definition at line 407 of file CNewMenu.cpp.

408 {
410  CComPtr<IShellView> lpSV;
411  HRESULT hr = E_FAIL;
412  LPITEMIDLIST pidl;
413  PITEMID_CHILD pidlNewItem;
414  DWORD dwSelectFlags;
415 
416  dwSelectFlags = SVSI_DESELECTOTHERS | SVSI_ENSUREVISIBLE | SVSI_FOCUSED | SVSI_SELECT;
417  if (bRename)
418  dwSelectFlags |= SVSI_EDIT;
419 
420  /* Notify the view object about the new item */
421  SHChangeNotify(wEventId, uFlags, (LPCVOID) pszName, NULL);
422 
423  if (!m_pSite)
424  return S_OK;
425 
426  /* Get a pointer to the shell view */
428  if (FAILED_UNEXPECTEDLY(hr))
429  return S_OK;
430 
431  /* Attempt to get the pidl of the new item */
432  hr = SHILCreateFromPathW(pszName, &pidl, NULL);
433  if (FAILED_UNEXPECTEDLY(hr))
434  return hr;
435 
436  pidlNewItem = ILFindLastID(pidl);
437 
438  hr = lpSV->SelectItem(pidlNewItem, dwSelectFlags);
439 
440  SHFree(pidl);
441 
442  return hr;
443 }
HRESULT hr
Definition: shlfolder.c:183
UINT uFlags
Definition: api.c:59
#define SID_IFolderView
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
HRESULT WINAPI IUnknown_QueryService(IUnknown *, REFGUID, REFIID, LPVOID *)
Definition: ordinal.c:1448
smooth NULL
Definition: ftsmooth.c:416
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:189
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
Definition: changenotify.c:340
#define S_OK
Definition: intsafe.h:59
HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST *ppidl, DWORD *attributes)
Definition: pidl.c:392
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331
CONST void * LPCVOID
Definition: windef.h:191
CComPtr< IUnknown > m_pSite
Definition: CNewMenu.h:59
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

Referenced by CreateNewFolder(), and NewItemByNonCommand().

◆ SetSite()

HRESULT STDMETHODCALLTYPE CNewMenu::SetSite ( IUnknown pUnkSite)
virtual

Implements IObjectWithSite.

Definition at line 612 of file CNewMenu.cpp.

613 {
614  m_pSite = pUnkSite;
615  return S_OK;
616 }
#define S_OK
Definition: intsafe.h:59
CComPtr< IUnknown > m_pSite
Definition: CNewMenu.h:59

◆ UnloadAllItems()

void CNewMenu::UnloadAllItems ( )
private

Definition at line 62 of file CNewMenu.cpp.

63 {
64  SHELLNEW_ITEM *pCurItem;
65 
66  /* Unload the handler items, including the link item */
67  while (m_pItems)
68  {
69  pCurItem = m_pItems;
71  UnloadItem(pCurItem);
72  }
73  m_pItems = NULL;
74  m_pLinkItem = NULL;
75 }
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:57
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:58
smooth NULL
Definition: ftsmooth.c:416
SHELLNEW_ITEM * pNext
Definition: CNewMenu.h:53
void UnloadItem(SHELLNEW_ITEM *pItem)
Definition: CNewMenu.cpp:49

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

◆ UnloadItem()

void CNewMenu::UnloadItem ( SHELLNEW_ITEM pItem)
private

Definition at line 49 of file CNewMenu.cpp.

50 {
51  /* Note: free allows NULL as argument */
52  free(pItem->pData);
53  free(pItem->pwszDesc);
54  free(pItem->pwszExt);
55 
56  if (pItem->hIcon)
57  DestroyIcon(pItem->hIcon);
58 
59  HeapFree(GetProcessHeap(), 0, pItem);
60 }
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define free
Definition: debug_ros.c:5
#define GetProcessHeap()
Definition: compat.h:403
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by UnloadAllItems().

Member Data Documentation

◆ m_hIconFolder

HICON CNewMenu::m_hIconFolder
private

Definition at line 62 of file CNewMenu.h.

Referenced by HandleMenuMsg2(), and Initialize().

◆ m_hIconLink

HICON CNewMenu::m_hIconLink
private

Definition at line 62 of file CNewMenu.h.

Referenced by HandleMenuMsg2(), and Initialize().

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