ReactOS  0.4.14-dev-358-gbef841c
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
 
LPWSTR m_wszPath
 
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_wszPath(NULL),
31  m_pItems(NULL),
33  m_pSite(NULL),
34  m_idCmdFirst(0),
35  m_idCmdFolder(-1),
36  m_idCmdLink(-1),
39 {
40 }
UINT m_idCmdLink
Definition: CNewMenu.h:62
HICON m_hIconLink
Definition: CNewMenu.h:63
UINT m_idCmdFolder
Definition: CNewMenu.h:62
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:58
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:59
smooth NULL
Definition: ftsmooth.c:416
HICON m_hIconFolder
Definition: CNewMenu.h:63
UINT m_idCmdFirst
Definition: CNewMenu.h:62
LPWSTR m_wszPath
Definition: CNewMenu.h:57
CComPtr< IUnknown > m_pSite
Definition: CNewMenu.h:60

◆ ~CNewMenu()

CNewMenu::~CNewMenu ( )

Definition at line 42 of file CNewMenu.cpp.

43 {
45 
46  if (m_pidlFolder)
48 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
void UnloadAllItems()
Definition: CNewMenu.cpp:63

Member Function Documentation

◆ CacheItems()

BOOL CNewMenu::CacheItems ( )
private

Definition at line 171 of file CNewMenu.cpp.

172 {
173  HKEY hKey;
174  DWORD dwSize = 0;
175  DWORD dwIndex = 0;
176  LPWSTR lpValue;
177  LPWSTR lpValues;
178  WCHAR wszName[MAX_PATH];
179  SHELLNEW_ITEM *pNewItem;
180  SHELLNEW_ITEM *pCurItem = NULL;
181 
182  /* Enumerate all extensions */
183  while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS)
184  {
185  if (wszName[0] != L'.')
186  continue;
187 
188  pNewItem = LoadItem(wszName);
189  if (pNewItem)
190  {
191  dwSize += wcslen(wszName) + 1;
192  if (!m_pLinkItem && wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
193  {
194  /* The unique link handler */
195  m_pLinkItem = pNewItem;
196  }
197 
198  /* Add at the end of the list */
199  if (pCurItem)
200  {
201  pCurItem->pNext = pNewItem;
202  pCurItem = pNewItem;
203  }
204  else
205  {
206  pCurItem = m_pItems = pNewItem;
207  }
208  }
209  }
210 
211  dwSize++;
212 
213  lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize * sizeof(WCHAR));
214  if (!lpValues)
215  return FALSE;
216 
217  for (pCurItem = m_pItems, lpValue = lpValues; pCurItem; pCurItem = pCurItem->pNext)
218  {
219  memcpy(lpValue, pCurItem->pwszExt, (wcslen(pCurItem->pwszExt) + 1) * sizeof(WCHAR));
220  lpValue += wcslen(pCurItem->pwszExt) + 1;
221  }
222 
224  {
225  HeapFree(GetProcessHeap(), 0, lpValues);
226  return FALSE;
227  }
228 
229  if (RegSetValueExW(hKey, L"Classes", NULL, REG_MULTI_SZ, (LPBYTE)lpValues, dwSize * sizeof(WCHAR)) != ERROR_SUCCESS)
230  {
231  HeapFree(GetProcessHeap(), 0, lpValues);
232  RegCloseKey(hKey);
233  return FALSE;
234  }
235 
236  HeapFree(GetProcessHeap(), 0, lpValues);
237  RegCloseKey(hKey);
238 
239  return TRUE;
240 }
#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:78
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:58
#define REG_MULTI_SZ
Definition: nt_native.h:1501
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:59
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 447 of file CNewMenu.cpp.

448 {
449  WCHAR wszPath[MAX_PATH];
450  WCHAR wszName[MAX_PATH];
451  WCHAR wszNewFolder[25];
452  HRESULT hr;
453 
454  /* Get folder path */
456  if (FAILED_UNEXPECTEDLY(hr))
457  return hr;
458 
459  if (!LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, _countof(wszNewFolder)))
460  return E_FAIL;
461 
462  /* Create the name of the new directory */
463  if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, wszNewFolder))
464  return E_FAIL;
465 
466  /* Create the new directory and show the appropriate dialog in case of error */
467  if (SHCreateDirectory(lpici->hwnd, wszName) != ERROR_SUCCESS)
468  return E_FAIL;
469 
470  /* Show and select the new item in the def view */
472 
473  return S_OK;
474 }
#define SHCNE_MKDIR
Definition: shlobj.h:1723
#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:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
#define SHCNF_PATHW
Definition: shlobj.h:1755
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:320
HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
Definition: CNewMenu.cpp:408

Referenced by InvokeCommand().

◆ CreateNewItem()

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

Definition at line 576 of file CNewMenu.cpp.

577 {
578  HRESULT hr;
579  WCHAR wszPath[MAX_PATH], wszName[MAX_PATH];
580 
581  /* Get folder path */
583  if (FAILED_UNEXPECTEDLY(hr))
584  return hr;
585 
586  if (pItem == m_pLinkItem)
587  {
588  NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
589  NewItemByCommand(pItem, wszName);
590  return S_OK;
591  }
592 
593  switch (pItem->Type)
594  {
596  NewItemByCommand(pItem, wszPath);
597  break;
598 
599  case SHELLNEW_TYPE_DATA:
602  NewItemByNonCommand(pItem, wszName, _countof(wszName), wszPath);
603  break;
604 
606  ERR("Invalid type\n");
607  break;
608  }
609 
610  return S_OK;
611 }
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:476
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#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:519
#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 386 of file CNewMenu.cpp.

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

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

692 {
693  FIXME("%p %lu %u %p %p %u\n", this,
694  idCmd, uType, pwReserved, pszName, cchMax );
695 
696  return E_NOTIMPL;
697 }
#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 619 of file CNewMenu.cpp.

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

◆ HandleMenuMsg()

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

Implements IContextMenu2.

Definition at line 701 of file CNewMenu.cpp.

702 {
703  return S_OK;
704 }
#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 708 of file CNewMenu.cpp.

709 {
710  switch (uMsg)
711  {
712  case WM_MEASUREITEM:
713  {
714  MEASUREITEMSTRUCT* lpmis = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
715  if (!lpmis || lpmis->CtlType != ODT_MENU)
716  break;
717 
720  if (lpmis->itemHeight < 16)
721  lpmis->itemHeight = 16;
722 
723  if (plResult)
724  *plResult = TRUE;
725  break;
726  }
727  case WM_DRAWITEM:
728  {
729  DRAWITEMSTRUCT* lpdis = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
730  if (!lpdis || lpdis->CtlType != ODT_MENU)
731  break;
732 
733  DWORD id = LOWORD(lpdis->itemID);
734  HICON hIcon = NULL;
735  if (m_idCmdFirst + id == m_idCmdFolder)
736  {
738  }
739  else if (m_idCmdFirst + id == m_idCmdLink)
740  {
741  hIcon = m_hIconLink;
742  }
743  else
744  {
745  SHELLNEW_ITEM *pItem = FindItemFromIdOffset(id);
746  if (pItem)
747  hIcon = pItem->hIcon;
748  }
749 
750  if (!hIcon)
751  break;
752 
753  DrawIconEx(lpdis->hDC,
754  2,
755  lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
756  hIcon,
757  16,
758  16,
759  0, NULL, DI_NORMAL);
760 
761  if(plResult)
762  *plResult = TRUE;
763  }
764  }
765 
766  return S_OK;
767 }
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
UINT m_idCmdLink
Definition: CNewMenu.h:62
UINT uMsg
Definition: menu.cpp:213
HICON m_hIconLink
Definition: CNewMenu.h:63
#define ODT_MENU
Definition: winuser.h:2512
#define SM_CXMENUCHECK
Definition: winuser.h:1021
LONG top
Definition: windef.h:292
UINT m_idCmdFolder
Definition: CNewMenu.h:62
smooth NULL
Definition: ftsmooth.c:416
HICON m_hIconFolder
Definition: CNewMenu.h:63
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:62
#define WM_MEASUREITEM
Definition: winuser.h:1628
SHELLNEW_ITEM * FindItemFromIdOffset(UINT IdOffset)
Definition: CNewMenu.cpp:386
#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:294
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 770 of file CNewMenu.cpp.

772 {
773  m_pidlFolder = ILClone(pidlFolder);
774 
775  /* Load folder and shortcut icons */
778  return S_OK;
779 }
#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:63
LPITEMIDLIST m_pidlFolder
Definition: CNewMenu.h:56
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
#define IDI_SHELL_SHORTCUT
Definition: shresdef.h:497
HICON m_hIconFolder
Definition: CNewMenu.h:63
#define IDI_SHELL_FOLDER
Definition: shresdef.h:471
#define S_OK
Definition: intsafe.h:59
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
#define LoadImage
Definition: winuser.h:5716

◆ InsertShellNewItems()

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

Definition at line 318 of file CNewMenu.cpp.

319 {
320  MENUITEMINFOW mii;
321  UINT idCmd = idCmdFirst;
322  WCHAR wszBuf[256];
323 
324  if (m_pItems == NULL)
325  {
326  if (!LoadAllItems())
327  return 0;
328  }
329 
330  ZeroMemory(&mii, sizeof(mii));
331  mii.cbSize = sizeof(mii);
332 
333  m_idCmdFirst = idCmd;
334 
335  /* Insert the new folder action */
337  wszBuf[0] = 0;
339  mii.dwTypeData = wszBuf;
340  mii.cch = wcslen(mii.dwTypeData);
341  mii.wID = idCmd;
342  mii.hbmpItem = HBMMENU_CALLBACK;
343  if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
344  m_idCmdFolder = idCmd++;
345 
346  /* Insert the new shortcut action */
347  if (m_pLinkItem)
348  {
350  wszBuf[0] = 0;
351  mii.dwTypeData = wszBuf;
352  mii.cch = wcslen(mii.dwTypeData);
353  mii.wID = idCmd;
354  if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
355  m_idCmdLink = idCmd++;
356  }
357 
358  /* Insert a seperator for the custom new action */
359  mii.fMask = MIIM_TYPE | MIIM_ID;
360  mii.fType = MFT_SEPARATOR;
361  mii.wID = -1;
362  InsertMenuItemW(hMenu, Pos++, TRUE, &mii);
363 
364  /* Insert the rest of the items */
366  mii.fType = 0;
367 
368  for (SHELLNEW_ITEM *pCurItem = m_pItems; pCurItem; pCurItem = pCurItem->pNext)
369  {
370  /* Skip shortcut item */
371  if (pCurItem == m_pLinkItem)
372  continue;
373 
374  TRACE("szDesc %s\n", debugstr_w(pCurItem->pwszDesc));
375  mii.dwItemData = (ULONG_PTR)pCurItem;
376  mii.dwTypeData = pCurItem->pwszDesc;
377  mii.cch = wcslen(mii.dwTypeData);
378  mii.wID = idCmd;
379  if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
380  ++idCmd;
381  }
382 
383  return idCmd - idCmdFirst;
384 }
#define TRUE
Definition: types.h:120
UINT m_idCmdLink
Definition: CNewMenu.h:62
#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:62
LPWSTR dwTypeData
Definition: winuser.h:3243
#define FCIDM_SHVIEW_NEWLINK
Definition: shresdef.h:760
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:58
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
#define debugstr_w
Definition: kernel32.h:32
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:59
smooth NULL
Definition: ftsmooth.c:416
#define FCIDM_SHVIEW_NEWFOLDER
Definition: shresdef.h:761
#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:62
#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:301
#define ULONG_PTR
Definition: config.h:101
#define MIIM_DATA
Definition: winuser.h:721
ULONG_PTR dwItemData
Definition: winuser.h:3242
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 666 of file CNewMenu.cpp.

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

◆ LoadAllItems()

BOOL CNewMenu::LoadAllItems ( )
private

Definition at line 301 of file CNewMenu.cpp.

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

Referenced by InsertShellNewItems().

◆ LoadCachedItems()

BOOL CNewMenu::LoadCachedItems ( )
private

Definition at line 243 of file CNewMenu.cpp.

244 {
245  LPWSTR wszName;
246  LPWSTR lpValues;
247  DWORD dwSize;
248  HKEY hKey;
249  SHELLNEW_ITEM *pNewItem;
250  SHELLNEW_ITEM *pCurItem = NULL;
251 
253  return FALSE;
254 
255  if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, NULL, &dwSize) != ERROR_SUCCESS)
256  return FALSE;
257 
258  lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwSize);
259  if (!lpValues)
260  return FALSE;
261 
262  if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, (LPBYTE)lpValues, &dwSize) != ERROR_SUCCESS)
263  {
264  HeapFree(GetProcessHeap(), 0, lpValues);
265  return FALSE;
266  }
267 
268  wszName = lpValues;
269 
270  for (; *wszName != '\0'; wszName += wcslen(wszName) + 1)
271  {
272  pNewItem = LoadItem(wszName);
273  if (pNewItem)
274  {
275  if (!m_pLinkItem && wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
276  {
277  /* The unique link handler */
278  m_pLinkItem = pNewItem;
279  }
280 
281  /* Add at the end of the list */
282  if (pCurItem)
283  {
284  pCurItem->pNext = pNewItem;
285  pCurItem = pNewItem;
286  }
287  else
288  {
289  pCurItem = m_pItems = pNewItem;
290  }
291  }
292  }
293 
294  HeapFree(GetProcessHeap(), 0, lpValues);
295  RegCloseKey(hKey);
296 
297  return TRUE;
298 }
#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:78
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
SHELLNEW_ITEM * m_pItems
Definition: CNewMenu.h:58
SHELLNEW_ITEM * m_pLinkItem
Definition: CNewMenu.h:59
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 78 of file CNewMenu.cpp.

79 {
80  HKEY hKey;
81  WCHAR wszBuf[MAX_PATH];
82  PBYTE pData = NULL;
83  DWORD cbData;
84 
85  StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s\\ShellNew", pwszExt);
86 
87  TRACE("LoadItem Keyname %s Name %s\n", debugstr_w(pwszExt), debugstr_w(wszBuf));
88 
89  if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
90  {
91  TRACE("Failed to open key\n");
92  return NULL;
93  }
94 
95  /* Find first valid value */
96  struct
97  {
98  LPCWSTR pszName;
100  BOOL bNeedData;
101  BOOL bStr;
102  } Types[] = {
103  {L"FileName", SHELLNEW_TYPE_FILENAME, TRUE, TRUE},
104  {L"Command", SHELLNEW_TYPE_COMMAND, TRUE, TRUE},
105  {L"Data", SHELLNEW_TYPE_DATA, TRUE, FALSE},
106  {L"NullFile", SHELLNEW_TYPE_NULLFILE, FALSE},
107  {NULL}
108  };
109  UINT i;
110 
111  for (i = 0; Types[i].pszName; ++i)
112  {
113  /* Note: We are using ANSI function because strings can be treated as data */
114  cbData = 0;
116  DWORD dwType;
117  if (RegGetValueW(hKey, NULL, Types[i].pszName, dwFlags, NULL, NULL, &cbData) == ERROR_SUCCESS)
118  {
119  if (Types[i].bNeedData && cbData > 0)
120  {
121  pData = (PBYTE)malloc(cbData);
122  RegGetValueW(hKey, NULL, Types[i].pszName, dwFlags, &dwType, pData, &cbData);
123  if (!Types[i].bStr && (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
124  {
125  PBYTE pData2 = (PBYTE)malloc(cbData);
126  cbData = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)pData, -1, (LPSTR)pData2, cbData, NULL, NULL);
127  free(pData);
128  pData = pData2;
129  }
130  }
131  break;
132  }
133  }
134  RegCloseKey(hKey);
135 
136  /* Was any key found? */
137  if (!Types[i].pszName)
138  {
139  free(pData);
140  return NULL;
141  }
142 
143  SHFILEINFOW fi;
145  {
146  free(pData);
147  return NULL;
148  }
149 
150  /* Create new item */
151  SHELLNEW_ITEM *pNewItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM)));
152  if (!pNewItem)
153  {
154  free(pData);
155  return NULL;
156  }
157 
158  TRACE("new item %ls\n", fi.szTypeName);
159  pNewItem->Type = Types[i].Type;
160  pNewItem->pData = pData;
161  pNewItem->cbData = pData ? cbData : 0;
162  pNewItem->pwszExt = _wcsdup(pwszExt);
163  pNewItem->pwszDesc = _wcsdup(fi.szTypeName);
164  if (fi.hIcon)
165  pNewItem->hIcon = fi.hIcon;
166 
167  return pNewItem;
168 }
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:410
#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 476 of file CNewMenu.cpp.

477 {
478  WCHAR wszBuf[MAX_PATH];
479  LPWSTR Ptr, pwszCmd;
480  WCHAR wszTemp[MAX_PATH];
481  STARTUPINFOW si;
483 
484  if (!ExpandEnvironmentStringsW((LPWSTR)pItem->pData, wszBuf, _countof(wszBuf)))
485  {
486  TRACE("ExpandEnvironmentStrings failed\n");
487  return E_FAIL;
488  }
489 
490  /* Expand command parameter, FIXME: there can be more modifiers */
491  Ptr = wcsstr(wszBuf, L"%1");
492  if (Ptr)
493  {
494  Ptr[1] = L's';
495  StringCbPrintfW(wszTemp, sizeof(wszTemp), wszBuf, wszPath);
496  pwszCmd = wszTemp;
497  }
498  else
499  {
500  pwszCmd = wszBuf;
501  }
502 
503  /* Create process */
504  ZeroMemory(&si, sizeof(si));
505  si.cb = sizeof(si);
506  if (CreateProcessW(NULL, pwszCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
507  {
508  CloseHandle(pi.hProcess);
509  CloseHandle(pi.hThread);
510  return S_OK;
511  }
512  else
513  {
514  ERR("Failed to create process\n");
515  return E_FAIL;
516  }
517 }
#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
#define MAX_PATH
Definition: compat.h:26
static DWORD pi
Definition: protocol.c:150
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 519 of file CNewMenu.cpp.

521 {
522  WCHAR wszBuf[MAX_PATH];
523  WCHAR wszNewFile[MAX_PATH];
524  BOOL bSuccess = TRUE;
525 
526  if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEW, wszBuf, _countof(wszBuf)))
527  return E_FAIL;
528 
529  StringCchPrintfW(wszNewFile, _countof(wszNewFile), L"%s %s%s", wszBuf, pItem->pwszDesc, pItem->pwszExt);
530 
531  /* Create the name of the new file */
532  if (!PathYetAnotherMakeUniqueName(wszName, wszPath, NULL, wszNewFile))
533  return E_FAIL;
534 
535  /* Create new file */
538  {
539  if (pItem->Type == SHELLNEW_TYPE_DATA)
540  {
541  /* Write a content */
542  DWORD cbWritten;
543  WriteFile(hFile, pItem->pData, pItem->cbData, &cbWritten, NULL);
544  }
545 
546  /* Close file now */
548  }
549  else
550  {
551  bSuccess = FALSE;
552  }
553 
554  if (pItem->Type == SHELLNEW_TYPE_FILENAME)
555  {
556  /* Copy file */
557  if (!CopyFileW((LPWSTR)pItem->pData, wszName, FALSE))
558  ERR("Copy file failed: %ls\n", (LPWSTR)pItem->pData);
559  }
560 
561  /* Show message if we failed */
562  if (bSuccess)
563  {
564  TRACE("Notifying fs %s\n", debugstr_w(wszName));
565  SelectNewItem(SHCNE_CREATE, SHCNF_PATHW, wszName, pItem != m_pLinkItem);
566  }
567  else
568  {
569  StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Cannot create file: %s", wszName);
570  MessageBoxW(NULL, wszBuf, L"Cannot create file", MB_OK | MB_ICONERROR); // FIXME load localized error msg
571  }
572 
573  return S_OK;
574 }
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:417
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:59
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:1755
#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:320
#define SHCNE_CREATE
Definition: shlobj.h:1721
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HRESULT SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
Definition: CNewMenu.cpp:408

Referenced by CreateNewItem().

◆ QueryContextMenu()

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

Implements IContextMenu.

Definition at line 626 of file CNewMenu.cpp.

631 {
632  MENUITEMINFOW mii;
633  UINT cItems = 0;
634  WCHAR wszNew[200];
635 
636  TRACE("%p %p %u %u %u %u\n", this,
637  hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
638 
639  if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEW, wszNew, _countof(wszNew)))
640  return E_FAIL;
641 
643  if (!m_hSubMenu)
644  return E_FAIL;
645 
646  cItems = InsertShellNewItems(m_hSubMenu, idCmdFirst, 0);
647 
648  ZeroMemory(&mii, sizeof(mii));
649  mii.cbSize = sizeof(mii);
651  mii.fType = MFT_STRING;
652  mii.wID = -1;
653  mii.dwTypeData = wszNew;
654  mii.cch = wcslen(mii.dwTypeData);
655  mii.fState = MFS_ENABLED;
656  mii.hSubMenu = m_hSubMenu;
657 
658  if (!InsertMenuItemW(hMenu, indexMenu, TRUE, &mii))
659  return E_FAIL;
660 
661  return MAKE_HRESULT(SEVERITY_SUCCESS, 0, cItems);
662 }
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:3243
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:61
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu)
Definition: CNewMenu.cpp:318

◆ SelectNewItem()

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

Definition at line 408 of file CNewMenu.cpp.

409 {
411  CComPtr<IShellView> lpSV;
412  HRESULT hr = E_FAIL;
413  LPITEMIDLIST pidl;
414  PITEMID_CHILD pidlNewItem;
415  DWORD dwSelectFlags;
416 
417  dwSelectFlags = SVSI_DESELECTOTHERS | SVSI_ENSUREVISIBLE | SVSI_FOCUSED | SVSI_SELECT;
418  if (bRename)
419  dwSelectFlags |= SVSI_EDIT;
420 
421  /* Notify the view object about the new item */
422  SHChangeNotify(wEventId, uFlags, (LPCVOID) pszName, NULL);
423 
424  if (!m_pSite)
425  return S_OK;
426 
427  /* Get a pointer to the shell view */
429  if (FAILED_UNEXPECTEDLY(hr))
430  return S_OK;
431 
432  /* Attempt to get the pidl of the new item */
433  hr = SHILCreateFromPathW(pszName, &pidl, NULL);
434  if (FAILED_UNEXPECTEDLY(hr))
435  return hr;
436 
437  pidlNewItem = ILFindLastID(pidl);
438 
439  hr = lpSV->SelectItem(pidlNewItem, dwSelectFlags);
440 
441  SHFree(pidl);
442 
443  return hr;
444 }
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:77
#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:60
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 613 of file CNewMenu.cpp.

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

◆ UnloadAllItems()

void CNewMenu::UnloadAllItems ( )
private

Definition at line 63 of file CNewMenu.cpp.

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

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

◆ UnloadItem()

void CNewMenu::UnloadItem ( SHELLNEW_ITEM pItem)
private

Definition at line 50 of file CNewMenu.cpp.

51 {
52  /* Note: free allows NULL as argument */
53  free(pItem->pData);
54  free(pItem->pwszDesc);
55  free(pItem->pwszExt);
56 
57  if (pItem->hIcon)
58  DestroyIcon(pItem->hIcon);
59 
60  HeapFree(GetProcessHeap(), 0, pItem);
61 }
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 63 of file CNewMenu.h.

Referenced by HandleMenuMsg2(), and Initialize().

◆ m_hIconLink

HICON CNewMenu::m_hIconLink
private

Definition at line 63 of file CNewMenu.h.

Referenced by HandleMenuMsg2(), and Initialize().

◆ m_hSubMenu

HMENU CNewMenu::m_hSubMenu
private

Definition at line 61 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 62 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 60 of file CNewMenu.h.

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

◆ m_wszPath

LPWSTR CNewMenu::m_wszPath
private

Definition at line 57 of file CNewMenu.h.


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