1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
   | STDMETHODIMP CMenuExt::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/)
{
	// check options
	HRESULT hResult = IsShellExtEnabled(m_piShellExtControl);
	if(FAILED(hResult) || hResult == S_FALSE)
		return hResult;
 
	// find ch window
	HWND hWnd;
	hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler"));
	if(!hWnd)
		return S_OK;
 
/*	OTF("CMenuExt::QueryContextMenu - idCmdFirst=%lu, uFlags=%lu (", idCmdFirst, uFlags);
	if (uFlags & CMF_CANRENAME)
		OTF("CMF_CANRENAME ");
	if (uFlags & CMF_DEFAULTONLY)
		OTF("CMF_DEFAULTONLY ");
	if (uFlags & CMF_EXPLORE)
		OTF("CMF_EXPLORE ");
	if (uFlags & CMF_EXTENDEDVERBS)
		OTF("CMF_EXTENDEDVERBS ");
	if (uFlags & CMF_INCLUDESTATIC)
		OTF("CMF_INCLUDESTATIC ");
	if (uFlags & CMF_NODEFAULT)
		OTF("CMF_NODEFAULT ");
	if (uFlags & CMF_NORMAL)
		OTF("CMF_NORMAL ");
	if (uFlags & CMF_NOVERBS)
		OTF("CMF_NOVERBS ");
	if (uFlags & CMF_VERBSONLY)
		OTF("CMF_VERBSONLY ");
	OTF(")\r\n");
*/
	// remember ID of the first command
	m_uiFirstID=idCmdFirst;
 
	// current commands count in menu
	TCHAR szText[_MAX_PATH];
	int iCount=::GetMenuItemCount(hmenu);
 
	MENUITEMINFO mii;
	mii.cbSize=sizeof(mii);
	mii.fMask=MIIM_TYPE;
	mii.dwTypeData=szText;
	mii.cch=_MAX_PATH;
 
	// find a place where the commands should be inserted
	for (int i=0;i<iCount;i++)
	{
		::GetMenuString(hmenu, i, szText, _MAX_PATH, MF_BYPOSITION);
 
		// get rid of &
		CutAmpersands(szText);
		_tcslwr(szText);
 
		// check for texts Wytnij/Wklej/Kopiuj/Cut/Paste/Copy
		if (_tcsstr(szText, _T("wytnij")) != NULL || _tcsstr(szText, _T("wklej")) != NULL ||
			_tcsstr(szText, _T("kopiuj")) != NULL || _tcsstr(szText, _T("cut")) != NULL ||
			_tcsstr(szText, _T("paste")) != NULL || _tcsstr(szText, _T("copy")) != NULL)
		{
			// found - find the nearest bar and insert above
			for (int j=i+1;j<iCount;j++)
			{
				// find bar
				::GetMenuItemInfo(hmenu, j, TRUE, &mii);
 
				if (mii.fType == MFT_SEPARATOR)
				{
					indexMenu=j;
					j=iCount;
					i=iCount;
				}
			}
		}
	}
 
//	OTF("after placement\r\n");
 
	// main command adding
	_COMMAND* pCommand=g_pscsShared->GetCommandsPtr();
 
	// data about commands
	int iCommandCount=0;
 
	if (!m_bGroupFiles)
	{
		// paste
		if (g_pscsShared->uiFlags & EC_PASTE_FLAG)
		{
			::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING | (IsClipboardFormatAvailable(CF_HDROP) ? MF_ENABLED : MF_GRAYED), 
				idCmdFirst+0, pCommand[0].szCommand);
			iCommandCount++;
		}
 
		if (g_pscsShared->uiFlags & EC_PASTESPECIAL_FLAG)
		{
			::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING | (IsClipboardFormatAvailable(CF_HDROP) ? MF_ENABLED : MF_GRAYED), 
				idCmdFirst+1, pCommand[1].szCommand);
			iCommandCount++;
		}
	}
 
//	OTF("After group files\r\n");
 
	if (!m_bBackground)
	{
		CreateShortcutsMenu(idCmdFirst+5, g_pscsShared->bShowShortcutIcons);
//		OTF("after creating shortcuts menu\r\n");
 
		// copy to >
		if (g_pscsShared->uiFlags & EC_COPYTO_FLAG)
		{
			mii.cbSize=sizeof(MENUITEMINFO);
			mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
			mii.fType=MFT_STRING;
			mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED;
			mii.wID=idCmdFirst+2;
			mii.hSubMenu=m_mMenus.hShortcuts[0];
			mii.dwTypeData=pCommand[2].szCommand;
			mii.cch=_tcslen(pCommand[2].szCommand);
 
			::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii);
//			::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED),
//				(UINT)m_mMenus.hShortcuts[0], pCommand[2].szCommand);
			iCommandCount++;
//			OTF("added menu item\r\n");
		}
 
		// move to >
		if (g_pscsShared->uiFlags & EC_MOVETO_FLAG)
		{
			mii.cbSize=sizeof(MENUITEMINFO);
			mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
			mii.fType=MFT_STRING;
			mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED;
			mii.wID=idCmdFirst+3;
			mii.hSubMenu=m_mMenus.hShortcuts[1];
			mii.dwTypeData=pCommand[3].szCommand;
			mii.cch=_tcslen(pCommand[3].szCommand);
 
			::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii);
//			::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED),
//				(UINT)m_mMenus.hShortcuts[1], pCommand[3].szCommand);
			iCommandCount++;
		}
 
		// copy/move to special... >
		if (g_pscsShared->uiFlags & EC_COPYMOVETOSPECIAL_FLAG)
		{
			mii.cbSize=sizeof(MENUITEMINFO);
			mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
			mii.fType=MFT_STRING;
			mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED;
			mii.wID=idCmdFirst+4;
			mii.hSubMenu=m_mMenus.hShortcuts[2];
			mii.dwTypeData=pCommand[4].szCommand;
			mii.cch=_tcslen(pCommand[4].szCommand);
 
			::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii);
//			::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED),
//				(UINT)m_mMenus.hShortcuts[2], pCommand[4].szCommand);
			iCommandCount++;
		}
	}
 
//	OTF("before return\r\n");
	return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, g_pscsShared->iCommandCount+(m_bBackground ? 0 : 3*g_pscsShared->iShortcutsCount));
} | 
Partager