ReactOS  0.4.15-dev-3203-gacde1e0
COpenWithMenu Class Reference

#include <COpenWithMenu.h>

Inheritance diagram for COpenWithMenu:
Collaboration diagram for COpenWithMenu:

Public Member Functions

 COpenWithMenu ()
 
 ~COpenWithMenu ()
 
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 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 IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Private Member Functions

HBITMAP IconToBitmap (HICON hIcon)
 
VOID AddChooseProgramItem ()
 
VOID AddApp (PVOID pApp)
 

Private Attributes

UINT m_idCmdFirst
 
UINT m_idCmdLast
 
WCHAR m_wszPath [MAX_PATH]
 
HMENU m_hSubMenu
 
COpenWithListm_pAppList
 

Additional Inherited Members

- 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 IUnknown
typedef IUnknownLPUNKNOWN
 
- 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 COpenWithMenu.h.

Constructor & Destructor Documentation

◆ COpenWithMenu()

COpenWithMenu::COpenWithMenu ( )

Definition at line 1077 of file COpenWithMenu.cpp.

1078 {
1079  m_idCmdFirst = 0;
1080  m_idCmdLast = 0;
1081  m_pAppList = new COpenWithList;
1082 }
COpenWithList * m_pAppList
Definition: COpenWithMenu.h:38

◆ ~COpenWithMenu()

COpenWithMenu::~COpenWithMenu ( )

Definition at line 1084 of file COpenWithMenu.cpp.

1085 {
1086  TRACE("Destroying COpenWithMenu(%p)\n", this);
1087 
1088  if (m_hSubMenu)
1089  {
1090  INT Count, Index;
1091  MENUITEMINFOW mii;
1092 
1093  /* get item count */
1095  if (Count == -1)
1096  return;
1097 
1098  /* setup menuitem info */
1099  ZeroMemory(&mii, sizeof(mii));
1100  mii.cbSize = sizeof(mii);
1102 
1103  for(Index = 0; Index < Count; Index++)
1104  {
1105  if (GetMenuItemInfoW(m_hSubMenu, Index, TRUE, &mii))
1106  {
1107  if (mii.hbmpChecked)
1109  }
1110  }
1111  }
1112 
1113  if (m_pAppList)
1114  delete m_pAppList;
1115 }
#define MIIM_FTYPE
Definition: winuser.h:724
HBITMAP hbmpChecked
Definition: winuser.h:3242
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1664
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
int32_t INT
Definition: typedefs.h:58
int WINAPI GetMenuItemCount(_In_opt_ HMENU)
int Count
Definition: noreturn.cpp:7
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
#define TRACE(s)
Definition: solgame.cpp:4
_In_ WDFCOLLECTION _In_ ULONG Index
#define MIIM_CHECKMARKS
Definition: winuser.h:719
COpenWithList * m_pAppList
Definition: COpenWithMenu.h:38
#define MIIM_DATA
Definition: winuser.h:721

Member Function Documentation

◆ AddApp()

VOID COpenWithMenu::AddApp ( PVOID  pApp)
private

Definition at line 1168 of file COpenWithMenu.cpp.

1169 {
1170  MENUITEMINFOW mii;
1171  LPCWSTR pwszName = m_pAppList->GetName((COpenWithList::SApp*)pApp);
1172 
1173  ZeroMemory(&mii, sizeof(mii));
1174  mii.cbSize = sizeof(mii);
1176  mii.fType = MFT_STRING;
1177  mii.fState = MFS_ENABLED;
1178  mii.wID = m_idCmdLast;
1179  mii.dwTypeData = (LPWSTR)pwszName;
1180  mii.cch = wcslen(mii.dwTypeData);
1181  mii.dwItemData = (ULONG_PTR)pApp;
1182 
1184  if (hIcon)
1185  {
1186  mii.fMask |= MIIM_CHECKMARKS;
1188  }
1189 
1190  if (InsertMenuItemW(m_hSubMenu, -1, TRUE, &mii))
1191  m_idCmdLast++;
1192 }
static HICON
Definition: imagelist.c:84
#define MFT_STRING
Definition: winuser.h:741
HBITMAP hbmpChecked
Definition: winuser.h:3242
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
HBITMAP IconToBitmap(HICON hIcon)
#define ZeroMemory
Definition: winbase.h:1664
LPWSTR dwTypeData
Definition: winuser.h:3245
static HICON GetIcon(SApp *pApp)
#define MFS_ENABLED
Definition: winuser.h:745
#define MIIM_STATE
Definition: winuser.h:716
static LPCWSTR GetName(SApp *pApp)
#define MIIM_ID
Definition: winuser.h:717
#define MIIM_TYPE
Definition: winuser.h:720
#define MIIM_CHECKMARKS
Definition: winuser.h:719
HICON hIcon
Definition: msconfig.c:44
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
COpenWithList * m_pAppList
Definition: COpenWithMenu.h:38
#define ULONG_PTR
Definition: config.h:101
HBITMAP hbmpUnchecked
Definition: winuser.h:3243
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define MIIM_DATA
Definition: winuser.h:721
ULONG_PTR dwItemData
Definition: winuser.h:3244

Referenced by QueryContextMenu().

◆ AddChooseProgramItem()

VOID COpenWithMenu::AddChooseProgramItem ( )
private

Definition at line 1140 of file COpenWithMenu.cpp.

1141 {
1142  MENUITEMINFOW mii;
1143  WCHAR wszBuf[128];
1144 
1145  ZeroMemory(&mii, sizeof(mii));
1146  mii.cbSize = sizeof(mii);
1147  mii.fMask = MIIM_TYPE | MIIM_ID;
1148  mii.fType = MFT_SEPARATOR;
1149  mii.wID = -1;
1150  InsertMenuItemW(m_hSubMenu, -1, TRUE, &mii);
1151 
1153  {
1154  ERR("Failed to load string\n");
1155  return;
1156  }
1157 
1158  mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
1159  mii.fType = MFT_STRING;
1160  mii.fState = MFS_ENABLED;
1161  mii.wID = m_idCmdLast;
1162  mii.dwTypeData = (LPWSTR)wszBuf;
1163  mii.cch = wcslen(wszBuf);
1164 
1165  InsertMenuItemW(m_hSubMenu, -1, TRUE, &mii);
1166 }
#define MFT_STRING
Definition: winuser.h:741
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1664
LPWSTR dwTypeData
Definition: winuser.h:3245
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MFS_ENABLED
Definition: winuser.h:745
#define IDS_OPEN_WITH_CHOOSE
Definition: shresdef.h:135
#define MIIM_STATE
Definition: winuser.h:716
#define MIIM_ID
Definition: winuser.h:717
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MFT_SEPARATOR
Definition: winuser.h:739
#define MIIM_TYPE
Definition: winuser.h:720
#define ERR(fmt,...)
Definition: debug.h:110
#define shell32_hInstance
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by QueryContextMenu().

◆ GetCommandString()

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

Implements IContextMenu.

Definition at line 1311 of file COpenWithMenu.cpp.

1313 {
1314  FIXME("%p %lu %u %p %p %u\n", this,
1315  idCmd, uType, pwReserved, pszName, cchMax );
1316 
1317  return E_NOTIMPL;
1318 }
#define FIXME(fmt,...)
Definition: debug.h:111
UINT cchMax
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ HandleMenuMsg()

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

Implements IContextMenu2.

Definition at line 1320 of file COpenWithMenu.cpp.

1324 {
1325  TRACE("This %p uMsg %x\n", this, uMsg);
1326 
1327  return E_NOTIMPL;
1328 }
UINT uMsg
Definition: menu.cpp:213
#define TRACE(s)
Definition: solgame.cpp:4
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ IconToBitmap()

HBITMAP COpenWithMenu::IconToBitmap ( HICON  hIcon)
private

Definition at line 1117 of file COpenWithMenu.cpp.

1118 {
1119  HDC hdc, hdcScr;
1120  HBITMAP hbm, hbmOld;
1121  RECT rc;
1122 
1123  hdcScr = GetDC(NULL);
1124  hdc = CreateCompatibleDC(hdcScr);
1126  hbm = CreateCompatibleBitmap(hdcScr, rc.right, rc.bottom);
1127  ReleaseDC(NULL, hdcScr);
1128 
1129  hbmOld = (HBITMAP)SelectObject(hdc, hbm);
1130  FillRect(hdc, &rc, (HBRUSH)(COLOR_MENU + 1));
1131  if (!DrawIconEx(hdc, 0, 0, hIcon, rc.right, rc.bottom, 0, NULL, DI_NORMAL))
1132  ERR("DrawIcon failed: %x\n", GetLastError());
1133  SelectObject(hdc, hbmOld);
1134 
1135  DeleteDC(hdc);
1136 
1137  return hbm;
1138 }
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
static HDC
Definition: imagelist.c:92
#define SM_CXMENUCHECK
Definition: winuser.h:1021
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
LONG right
Definition: windef.h:308
#define SM_CYMENUCHECK
Definition: winuser.h:1022
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define COLOR_MENU
Definition: winuser.h:907
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)
HDC hdc
Definition: main.c:9
#define DI_NORMAL
Definition: wingdi.h:72
#define ERR(fmt,...)
Definition: debug.h:110
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI DeleteDC(_In_ HDC)
HICON hIcon
Definition: msconfig.c:44
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
#define NULL
Definition: types.h:112
LONG bottom
Definition: windef.h:309
static HBITMAP
Definition: button.c:44
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)

Referenced by AddApp().

◆ Initialize()

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

Implements IShellExtInit.

Definition at line 1331 of file COpenWithMenu.cpp.

1334 {
1335  STGMEDIUM medium;
1336  FORMATETC fmt;
1337  HRESULT hr;
1338  LPIDA pida;
1339  LPCITEMIDLIST pidlFolder2;
1340  LPCITEMIDLIST pidlChild;
1341  LPCITEMIDLIST pidl;
1342  LPCWSTR pwszExt;
1343 
1344  TRACE("This %p\n", this);
1345 
1346  if (pdtobj == NULL)
1347  return E_INVALIDARG;
1348 
1350  fmt.ptd = NULL;
1351  fmt.dwAspect = DVASPECT_CONTENT;
1352  fmt.lindex = -1;
1353  fmt.tymed = TYMED_HGLOBAL;
1354 
1355  hr = pdtobj->GetData(&fmt, &medium);
1356 
1357  if (FAILED(hr))
1358  {
1359  ERR("pdtobj->GetData failed with 0x%x\n", hr);
1360  return hr;
1361  }
1362 
1363  pida = (LPIDA)GlobalLock(medium.hGlobal);
1364  ASSERT(pida->cidl >= 1);
1365 
1366  pidlFolder2 = (LPCITEMIDLIST) ((LPBYTE)pida + pida->aoffset[0]);
1367  pidlChild = (LPCITEMIDLIST) ((LPBYTE)pida + pida->aoffset[1]);
1368 
1369  if (!_ILIsValue(pidlChild))
1370  {
1371  TRACE("pidl is not a file\n");
1372  GlobalUnlock(medium.hGlobal);
1373  ReleaseStgMedium(&medium);
1374  return E_FAIL;
1375  }
1376 
1377  pidl = ILCombine(pidlFolder2, pidlChild);
1378 
1379  GlobalUnlock(medium.hGlobal);
1380  ReleaseStgMedium(&medium);
1381 
1382  if (!pidl)
1383  {
1384  ERR("no mem\n");
1385  return E_OUTOFMEMORY;
1386  }
1387 
1388  if (!SHGetPathFromIDListW(pidl, m_wszPath))
1389  {
1390  SHFree((void*)pidl);
1391  ERR("SHGetPathFromIDListW failed\n");
1392  return E_FAIL;
1393  }
1394 
1395  SHFree((void*)pidl);
1396  TRACE("szPath %s\n", debugstr_w(m_wszPath));
1397 
1398  pwszExt = PathFindExtensionW(m_wszPath);
1399  if (PathIsExeW(pwszExt) || !_wcsicmp(pwszExt, L".lnk"))
1400  {
1401  TRACE("file is a executable or shortcut\n");
1402  return E_FAIL;
1403  }
1404 
1405  return S_OK;
1406 }
WCHAR m_wszPath[MAX_PATH]
Definition: COpenWithMenu.h:36
#define CFSTR_SHELLIDLIST
Definition: shlobj.h:477
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
const char * fmt
Definition: wsprintf.c:30
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
#define E_FAIL
Definition: ddrawi.h:102
unsigned char * LPBYTE
Definition: typedefs.h:53
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define debugstr_w
Definition: kernel32.h:32
#define E_INVALIDARG
Definition: ddrawi.h:101
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
LONG HRESULT
Definition: typedefs.h:79
struct CIDA * LPIDA
EXTERN_C BOOL PathIsExeW(LPCWSTR lpszPath)
Definition: shellpath.c:368
UINT cidl
Definition: shlobj.h:499
static const WCHAR L[]
Definition: oid.c:1250
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL _ILIsValue(LPCITEMIDLIST pidl)
Definition: pidl.c:1974
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:52
UINT aoffset[1]
Definition: shlobj.h:500
#define NULL
Definition: types.h:112
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331
Definition: dsound.c:943
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: shlobj.h:498

◆ InvokeCommand()

HRESULT WINAPI COpenWithMenu::InvokeCommand ( LPCMINVOKECOMMANDINFO  lpcmi)
virtual

Implements IContextMenu.

Definition at line 1269 of file COpenWithMenu.cpp.

1270 {
1271  HRESULT hr = E_FAIL;
1272 
1273  TRACE("This %p idFirst %u idLast %u idCmd %u\n", this, m_idCmdFirst, m_idCmdLast, m_idCmdFirst + LOWORD(lpici->lpVerb));
1274 
1275  if (HIWORD(lpici->lpVerb) == 0 && m_idCmdFirst + LOWORD(lpici->lpVerb) <= m_idCmdLast)
1276  {
1277  if (m_idCmdFirst + LOWORD(lpici->lpVerb) == m_idCmdLast)
1278  {
1279  OPENASINFO info;
1281 
1282  info.pcszFile = m_wszPath;
1283  info.oaifInFlags = OAIF_EXEC;
1284  if (pwszExt[0])
1286  info.pcszClass = NULL;
1287  hr = SHOpenWithDialog(lpici->hwnd, &info);
1288  }
1289  else
1290  {
1291  /* retrieve menu item info */
1292  MENUITEMINFOW mii;
1293  ZeroMemory(&mii, sizeof(mii));
1294  mii.cbSize = sizeof(mii);
1295  mii.fMask = MIIM_DATA | MIIM_FTYPE;
1296 
1297  if (GetMenuItemInfoW(m_hSubMenu, LOWORD(lpici->lpVerb), TRUE, &mii) && mii.dwItemData)
1298  {
1299  /* launch item with specified app */
1302  hr = S_OK;
1303  }
1304  }
1305  }
1306 
1307  return hr;
1308 }
WCHAR m_wszPath[MAX_PATH]
Definition: COpenWithMenu.h:36
#define MIIM_FTYPE
Definition: winuser.h:724
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1664
#define E_FAIL
Definition: ddrawi.h:102
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
LONG HRESULT
Definition: typedefs.h:79
struct _test_info info[]
Definition: SetCursorPos.c:19
#define S_OK
Definition: intsafe.h:52
#define NULL
Definition: types.h:112
#define HIWORD(l)
Definition: typedefs.h:247
#define MIIM_DATA
Definition: winuser.h:721
ULONG_PTR dwItemData
Definition: winuser.h:3244
#define LOWORD(l)
Definition: pedump.c:82
static BOOL Execute(SApp *pApp, LPCWSTR pwszFilePath)

◆ QueryContextMenu()

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

Implements IContextMenu.

Definition at line 1194 of file COpenWithMenu.cpp.

1200 {
1201  TRACE("hMenu %p indexMenu %u idFirst %u idLast %u uFlags %u\n", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
1202 
1203  INT DefaultPos = GetMenuDefaultItem(hMenu, TRUE, 0);
1204 
1205  WCHAR wszName[100];
1206  UINT NameId = (DefaultPos == -1 ? IDS_OPEN : IDS_OPEN_WITH);
1207  if (!LoadStringW(shell32_hInstance, NameId, wszName, _countof(wszName)))
1208  {
1209  ERR("Failed to load string\n");
1210  return E_FAIL;
1211  }
1212 
1213  /* Init first cmd id and submenu */
1214  m_idCmdFirst = m_idCmdLast = idCmdFirst;
1215  m_hSubMenu = NULL;
1216 
1217  /* If we are going to be default item, we shouldn't be submenu */
1218  if (DefaultPos != -1)
1219  {
1220  /* Load applications list */
1221  m_pAppList->Load();
1223 
1224  /* Create submenu only if there is more than one application and menu has a default item */
1225  if (m_pAppList->GetRecommendedCount() > 1)
1226  {
1228 
1229  for(UINT i = 0; i < m_pAppList->GetCount(); ++i)
1230  {
1231  COpenWithList::SApp *pApp = m_pAppList->GetList() + i;
1232  if (pApp->bRecommended)
1233  AddApp(pApp);
1234  }
1235 
1237  }
1238  }
1239 
1240  /* Insert menu item */
1241  MENUITEMINFOW mii;
1242  ZeroMemory(&mii, sizeof(mii));
1243  mii.cbSize = sizeof(mii);
1244  mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
1245  if (m_hSubMenu)
1246  {
1247  mii.fMask |= MIIM_SUBMENU;
1248  mii.hSubMenu = m_hSubMenu;
1249  mii.wID = -1;
1250  }
1251  else
1252  mii.wID = m_idCmdLast;
1253 
1254  mii.fType = MFT_STRING;
1255  mii.dwTypeData = (LPWSTR)wszName;
1256  mii.cch = wcslen(wszName);
1257 
1258  mii.fState = MFS_ENABLED;
1259  if (DefaultPos == -1)
1260  mii.fState |= MFS_DEFAULT;
1261 
1262  if (!InsertMenuItemW(hMenu, DefaultPos + 1, TRUE, &mii))
1263  return E_FAIL;
1264 
1266 }
WCHAR m_wszPath[MAX_PATH]
Definition: COpenWithMenu.h:36
#define MFT_STRING
Definition: winuser.h:741
SApp * GetList()
VOID AddApp(PVOID pApp)
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1664
LPWSTR dwTypeData
Definition: winuser.h:3245
UINT uFlags
Definition: api.c:59
#define MFS_DEFAULT
Definition: winuser.h:743
#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)
int32_t INT
Definition: typedefs.h:58
#define IDS_OPEN
Definition: resource.h:12
#define SEVERITY_SUCCESS
Definition: winerror.h:64
#define MIIM_SUBMENU
Definition: winuser.h:718
#define MFS_ENABLED
Definition: winuser.h:745
#define MIIM_STATE
Definition: winuser.h:716
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
#define MIIM_ID
Definition: winuser.h:717
BOOL LoadRecommended(LPCWSTR pwszFilePath)
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MIIM_TYPE
Definition: winuser.h:720
#define ERR(fmt,...)
Definition: debug.h:110
#define shell32_hInstance
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
VOID AddChooseProgramItem()
#define IDS_OPEN_WITH
Definition: shresdef.h:134
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:846
COpenWithList * m_pAppList
Definition: COpenWithMenu.h:38
UINT GetRecommendedCount()
UINT WINAPI GetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Member Data Documentation

◆ m_hSubMenu

HMENU COpenWithMenu::m_hSubMenu
private

◆ m_idCmdFirst

UINT COpenWithMenu::m_idCmdFirst
private

Definition at line 35 of file COpenWithMenu.h.

Referenced by COpenWithMenu(), InvokeCommand(), and QueryContextMenu().

◆ m_idCmdLast

UINT COpenWithMenu::m_idCmdLast
private

◆ m_pAppList

COpenWithList* COpenWithMenu::m_pAppList
private

Definition at line 38 of file COpenWithMenu.h.

Referenced by AddApp(), COpenWithMenu(), QueryContextMenu(), and ~COpenWithMenu().

◆ m_wszPath

WCHAR COpenWithMenu::m_wszPath[MAX_PATH]
private

Definition at line 36 of file COpenWithMenu.h.

Referenced by Initialize(), InvokeCommand(), and QueryContextMenu().


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