Beispiel #1
0
// *** IContextMenu methods ***
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) {
	UINT idCmd = idCmdFirst;

	FORMATETC fmte = {
		CF_HDROP,
		(DVTARGETDEVICE FAR *)NULL,
		DVASPECT_CONTENT,
		-1,
		TYMED_HGLOBAL
	};

	HRESULT hres = m_pDataObj->GetData(&fmte, &m_stgMedium);

	if (SUCCEEDED(hres)) {
		if (m_stgMedium.hGlobal)
			m_cbFiles = DragQueryFile((HDROP)m_stgMedium.hGlobal, (UINT)-1, 0, 0);
	}

	UINT nIndex = indexMenu++;

	InsertMenu(hMenu, nIndex, MF_STRING|MF_BYPOSITION, idCmd++, m_szMenuTitle);

	HBITMAP icon = NULL;
	if (m_showIcon) {/*
		if (m_supportARGB32) {
			icon = NULL;
			HICON hicon;
			DWORD menuIconWidth = GetSystemMetrics(SM_CXMENUCHECK);
			DWORD menuIconHeight = GetSystemMetrics(SM_CYMENUCHECK);
			HRESULT hr = LoadShellIcon(menuIconWidth, menuIconHeight, &hicon);
			if (SUCCEEDED(hr)) {
				HBITMAP hbitmap;
				LoadARGBBitmap(hicon, menuIconWidth, menuIconHeight, &hbitmap);
				if (SUCCEEDED(hr)) {
					icon = hbitmap;
				}
			}
		} else {
			icon = HBMMENU_CALLBACK;
		}*/
		DWORD menuIconWidth = GetSystemMetrics(SM_CXMENUCHECK);
		DWORD menuIconHeight = GetSystemMetrics(SM_CYMENUCHECK);
		HRESULT hr = LoadShellBitmap(menuIconWidth, menuIconHeight, &icon);
		if (FAILED(hr))
			MsgBoxError(TEXT("Help"));
	}

	MENUITEMINFO mii;
	ZeroMemory(&mii, sizeof(mii));
	mii.cbSize = sizeof(mii);
	mii.fMask = MIIM_BITMAP;
	mii.hbmpItem = icon;
	//SetMenuItemInfo(hMenu, nIndex, MF_BYPOSITION, &mii);
	SetMenuItemBitmaps(hMenu, nIndex, MF_BYPOSITION, icon, icon);

	m_hMenu = hMenu;
	m_menuID = idCmd;

	return ResultFromShort(idCmd-idCmdFirst);
}
Beispiel #2
0
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) {
  UINT idCmd = idCmdFirst;
  BOOL bAppendItems=TRUE;
  TCHAR szItemNpp[] = TEXT("Edit with &Notepad++");

  FORMATETC fmte = {
    CF_HDROP,
    (DVTARGETDEVICE FAR *)NULL,
    DVASPECT_CONTENT,
    -1,
    TYMED_HGLOBAL
  };

  HRESULT hres = m_pDataObj->GetData(&fmte, &m_stgMedium);

  if (SUCCEEDED(hres)) {
    if (m_stgMedium.hGlobal)
      m_cbFiles = DragQueryFile((HDROP)m_stgMedium.hGlobal, (UINT)-1, 0, 0);
  }

  UINT nIndex = indexMenu++;
  InsertMenu(hMenu, nIndex, MF_STRING|MF_BYPOSITION, idCmd++, szItemNpp);

  if (m_hNppBmp) {
    SetMenuItemBitmaps (hMenu, nIndex, MF_BYPOSITION, m_hNppBmp, m_hNppBmp);
  }

  return ResultFromShort(idCmd-idCmdFirst);
}
Beispiel #3
0
//
//  FUNCTION: CShellExt::QueryContextMenu(HMENU, UINT, UINT, UINT, UINT)
//
//  PURPOSE: Called by the shell just before the context menu is displayed.
//           This is where you add your specific menu items.
//
//  PARAMETERS:
//    hMenu      - Handle to the context menu
//    indexMenu  - Index of where to begin inserting menu items
//    idCmdFirst - Lowest value for new menu ID's
//    idCmtLast  - Highest value for new menu ID's
//    uFlags     - Specifies the context of the menu event
//
//  RETURN VALUE:
//
//
//  COMMENTS:
//
// The menu text
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,UINT indexMenu,UINT idCmdFirst,UINT idCmdLast,UINT uFlags)
{
	
	UINT			idCmd = idCmdFirst;
	HRESULT		hr = E_INVALIDARG;
	
	// Seperator
	::InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
	::InsertMenu(hMenu, indexMenu++, MF_STRING|MF_BYPOSITION, idCmd++, _T("Scan For Viruses With ClamWin"));
	// Seperator
	::InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
	
	return ResultFromShort(idCmd-idCmdFirst);	//Must return number of menu
	//items we added.
}
Beispiel #4
0
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
    UINT idCmd = idCmdFirst;
    BOOL bAppendItems=TRUE;
    TCHAR szFileUserClickedOn[MAX_PATH];

    FORMATETC fmte = {
        CF_HDROP,
        (DVTARGETDEVICE FAR *)NULL,
        DVASPECT_CONTENT,
        -1,
        TYMED_HGLOBAL
    };

    HRESULT hres = m_pDataObj->GetData(&fmte, &m_stgMedium);

    if (SUCCEEDED(hres)) {
        if (m_stgMedium.hGlobal)
            m_cbFiles = DragQueryFile((HDROP)m_stgMedium.hGlobal, (UINT)-1, 0, 0);
            qDebug() << "number of files:" << m_cbFiles;
            for (unsigned i = 0; i < m_cbFiles; i++) {
                DragQueryFile((HDROP)m_stgMedium.hGlobal, i, szFileUserClickedOn, MAX_PATH);
                qDebug() << "file to open:" << lptstr2QString(szFileUserClickedOn);
            }
    }
    QString path = lptstr2QString(szFileUserClickedOn);

    UINT nIndex = indexMenu++;
    
    KMimeType::Ptr ptr = KMimeType::findByPath(path);

    KService::List lst = KMimeTypeTrader::self()->query(ptr->name(), "Application");
    
    if(lst.size() > 0)
    {
        TCHAR str[256];
        wsprintf(str, TEXT("Open with %s"), (LPTSTR)lst.at(0)->name().utf16());
        InsertMenu(hMenu, nIndex, MF_STRING|MF_BYPOSITION, idCmd++, str );

        if (m_hKdeLogoBmp) {
            SetMenuItemBitmaps(hMenu, nIndex, MF_BYPOSITION, m_hKdeLogoBmp, m_hKdeLogoBmp);
        }
    }

    return ResultFromShort(idCmd-idCmdFirst);
}
Beispiel #5
0
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
					 UINT indexMenu,
					 UINT idCmdFirst,
					 UINT  /* idCmdLast */,
					 UINT  /* uFlags */)
{
    UINT idCmd = idCmdFirst;

    hres = m_pDataObj->GetData(&fmte, &medium);
    if (medium.hGlobal)
	cbFiles = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, 0, 0);

    // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

    // Initialize m_cntOfHWnd to 0
    m_cntOfHWnd = 0;

    HKEY keyhandle;
    bool showExisting = true;
    bool showIcons = true;

    // Check whether "Edit with existing Vim" entries are disabled.
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
				       KEY_READ, &keyhandle) == ERROR_SUCCESS)
    {
	if (RegQueryValueEx(keyhandle, "DisableEditWithExisting", 0, NULL,
						 NULL, NULL) == ERROR_SUCCESS)
	    showExisting = false;
	if (RegQueryValueEx(keyhandle, "DisableContextMenuIcons", 0, NULL,
						 NULL, NULL) == ERROR_SUCCESS)
	    showIcons = false;
	RegCloseKey(keyhandle);
    }

    // Retrieve all the vim instances, unless disabled.
    if (showExisting)
	EnumWindows(EnumWindowsProc, (LPARAM)this);

    MENUITEMINFO mii = { sizeof(MENUITEMINFO) };
    mii.fMask = MIIM_STRING | MIIM_ID;
    if (showIcons)
    {
	mii.fMask |= MIIM_BITMAP;
	mii.hbmpItem = m_hVimIconBitmap;
    }

    if (cbFiles > 1)
    {
	mii.wID = idCmd++;
	mii.dwTypeData = _("Edit with &multiple Vims");
	mii.cch = lstrlen(mii.dwTypeData);
	InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);

	mii.wID = idCmd++;
	mii.dwTypeData = _("Edit with single &Vim");
	mii.cch = lstrlen(mii.dwTypeData);
	InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);

	if (cbFiles <= 4)
	{
	    // Can edit up to 4 files in diff mode
	    mii.wID = idCmd++;
	    mii.dwTypeData = _("Diff with Vim");
	    mii.cch = lstrlen(mii.dwTypeData);
	    InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
	    m_edit_existing_off = 3;
	}
	else
	    m_edit_existing_off = 2;

    }
    else
    {
	mii.wID = idCmd++;
	mii.dwTypeData = _("Edit with &Vim");
	mii.cch = lstrlen(mii.dwTypeData);
	InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
	m_edit_existing_off = 1;
    }

    HMENU hSubMenu = NULL;
    if (m_cntOfHWnd > 1)
    {
	hSubMenu = CreatePopupMenu();
	mii.fMask |= MIIM_SUBMENU;
	mii.wID = idCmd;
	mii.dwTypeData = _("Edit with existing Vim");
	mii.cch = lstrlen(mii.dwTypeData);
	mii.hSubMenu = hSubMenu;
	InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
	mii.fMask = mii.fMask & ~MIIM_SUBMENU;
	mii.hSubMenu = NULL;
    }
    // Now display all the vim instances
    for (int i = 0; i < m_cntOfHWnd; i++)
    {
	char title[BUFSIZE];
	char temp[BUFSIZE];
	int index;
	HMENU hmenu;

	// Obtain window title, continue if can not
	if (GetWindowText(m_hWnd[i], title, BUFSIZE - 1) == 0)
	    continue;
	// Truncate the title before the path, keep the file name
	char *pos = strchr(title, '(');
	if (pos != NULL)
	{
	    if (pos > title && pos[-1] == ' ')
		--pos;
	    *pos = 0;
	}
	// Now concatenate
	if (m_cntOfHWnd > 1)
	    temp[0] = '\0';
	else
	{
	    strncpy(temp, _("Edit with existing Vim - "), BUFSIZE - 1);
	    temp[BUFSIZE - 1] = '\0';
	}
	strncat(temp, title, BUFSIZE - 1 - strlen(temp));
	temp[BUFSIZE - 1] = '\0';

	mii.wID = idCmd++;
	mii.dwTypeData = temp;
	mii.cch = lstrlen(mii.dwTypeData);
	if (m_cntOfHWnd > 1)
	{
	    hmenu = hSubMenu;
	    index = i;
	}
	else
	{
	    hmenu = hMenu;
	    index = indexMenu++;
	}
	InsertMenuItem(hmenu, index, TRUE, &mii);
    }
    // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

    // Must return number of menu items we added.
    return ResultFromShort(idCmd-idCmdFirst);
}
Beispiel #6
0
STDMETHODIMP 
CShellExt::QueryContextMenu(
	HMENU	hMenu, 
	UINT	indexMenu, 
	UINT	idCmdFirst, 					
	UINT	idCmdLast, 
	UINT	uFlags)
{
	DualErr		derr;
	PGPBoolean	hasTimedOut, success;
	PGPUInt32	itemPosition, menuId, subMenuPosition;
	
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	menuId = idCmdFirst;
	itemPosition = 0;

	hasTimedOut = FALSE;

	// Shift key down?
	mShiftKeyDown = (::GetAsyncKeyState(VK_SHIFT) & 0x8000 ? TRUE : FALSE);

	// Beta or demo timed out?
	#if PGPDISK_BETAVERSION
		hasTimedOut = HasBetaTimedOut();
	#elif PGPDISK_DEMOVERSION
		hasTimedOut = HasDemoTimedOut();
	#endif // PGPDISK_BETAVERSION

	// Only show a menu if we found PGPdisks.
	if (mNumTotalPGPdisks == 0)
		derr = DualErr(kPGDMinorError_FailSilently);

	// There are also other special cases in which we don't show the menu.
	if (derr.IsntError())
	{
		if (((uFlags & 0x000F) != CMF_NORMAL) && 
			!(uFlags & CMF_EXPLORE) && !(uFlags & CMF_VERBSONLY))
		{
			derr = DualErr(kPGDMinorError_FailSilently);
		}
	}

	// Save parent menu handle for later.
	if (derr.IsntError())
	{
		if (!mParentMenu.Attach(hMenu))
			derr = DualErr(kPGDMinorError_AttachMenuFailed);
	}

	// Create the submenu.
	if (derr.IsntError())
	{
		if (!mSubMenu.CreatePopupMenu())
			derr = DualErr(kPGDMinorError_CreatePopupMenuFailed);
	}

	// Add items to the menu.
	if (derr.IsntError())
	{
		PGPUInt32 flags, sendToPosition;

		flags = MF_BYPOSITION;

		// Insert open/mount/unmount item.
		if (mNumTotalPGPdisks > 1)
		{
			mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
				GetCommonString(kPGPdiskShellExtOpenMenuString));

		}
		else if (mNumMountedPGPdisks == 1)
		{
			mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
				GetCommonString(kPGPdiskShellExtUnmountMenuString));
		}
		else
		{
			mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
				GetCommonString(kPGPdiskShellExtMountMenuString));
		}

		// Insert separator.
		mSubMenu.InsertMenu(itemPosition++, flags | MF_SEPARATOR, 0);

		// Insert passphrase items.
		flags = MF_BYPOSITION | (mNumMountedPGPdisks > 0 ? MF_GRAYED : NULL);

		mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
			GetCommonString(kPGPdiskShellExtAddPassMenuString));

		mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
			GetCommonString(kPGPdiskShellExtChangePassMenuString));

		if (mShiftKeyDown)
		{
			mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
				GetCommonString(kPGPdiskShellExtRemoveAltsMenuString));
		}
		else
		{
			mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
				GetCommonString(kPGPdiskShellExtRemovePassMenuString));
		}

		mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
			GetCommonString(kPGPdiskShellExtPubKeysMenuString));

		// Insert separator.
		flags = MF_BYPOSITION | MF_SEPARATOR;
		mSubMenu.InsertMenu(itemPosition++, flags | MF_SEPARATOR, 0);

		// Insert help item.
		flags = MF_BYPOSITION;
		mSubMenu.InsertMenu(itemPosition++, flags, menuId++, 
			GetCommonString(kPGPdiskShellExtHelpMenuString));

		// Find position of "Send To".
		if (IsWin95CompatibleMachine())
		{
			sendToPosition = FindMenuItemPosition(&mParentMenu, 
				kPGPdiskShellExtSendToStringWin95);
		}
		else
		{
			sendToPosition = FindMenuItemPosition(&mParentMenu, 
				kPGPdiskShellExtSendToStringNT);
		}

		if (sendToPosition == -1)
			subMenuPosition = indexMenu;
		else
			subMenuPosition = sendToPosition + 1;

		// Insert another separator.
		mParentMenu.InsertMenu(subMenuPosition++, 
			MF_BYPOSITION | MF_SEPARATOR, 0);

		// Insert the submenu menu.
		success = mParentMenu.InsertMenu(subMenuPosition, 
			MF_BYPOSITION | MF_POPUP, (PGPUInt32) mSubMenu.m_hMenu, 
			"&PGPdisk");

		if (!success)
			derr = DualErr(kPGDMinorError_InsertMenuFailed);
	}

	return ResultFromShort(itemPosition);
}
STDMETHODIMP CLocateShellExtension::QueryContextMenu(HMENU hMenu,
                                         UINT indexMenu,
                                         UINT idCmdFirst,
                                         UINT idCmdLast,
                                         UINT uFlags)
{
#ifdef _LOGGING
	char szTemp[100];
    
	sprintf_s(szTemp, 100,"CShellExt::QueryContextMenu(), uFlags==>%d", uFlags);
    ODS(szTemp);
#endif    
	
	if (uFlags & CMF_DEFAULTONLY)
	{
		ODS("CMF_DEFAULTONLY...");
			return NOERROR;
	}
    
	HMODULE hLanDll=GetLanguageResource();
	if (hLanDll==NULL)
		return NOERROR;

	DWORD dwSettings=ReadSettingsFromRegistry();

	if (dwSettings&fSubMenu)
	{
		HMENU hSubMenu=CreatePopupMenu();
		UINT uHighestId=0;
		if (InsertMenuItems(hSubMenu,0,idCmdFirst,uHighestId))
		{
			MENUITEMINFO mii;
			char szTitle[200];
			LoadString(hLanDll,IDS_EXTLOCATEMENU,szTitle,200);

			mii.cbSize=sizeof(MENUITEMINFO);
			mii.fMask=MIIM_SUBMENU|MIIM_TYPE;
			mii.fType=MFT_STRING;
			mii.dwTypeData=szTitle;
			mii.hSubMenu=hSubMenu;
			InsertMenuItem(hMenu,indexMenu,TRUE,&mii);

			FreeLibrary(hLanDll);
			return ResultFromShort(uHighestId+1-idCmdFirst);
		}
		
		DestroyMenu(hSubMenu);
		FreeLibrary(hLanDll);
		return NOERROR;	
	}
	else
	{
		UINT uHighestId=0;
		if (InsertMenuItems(hMenu,indexMenu,idCmdFirst,uHighestId))
		{
			FreeLibrary(hLanDll);
			return ResultFromShort(uHighestId+1-idCmdFirst);
		}
		FreeLibrary(hLanDll);
		return NOERROR;
	}
}
Beispiel #8
0
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
                                         UINT indexMenu,
                                         UINT idCmdFirst,
                                         UINT idCmdLast,
                                         UINT uFlags)
{

	if( m_bPathOverflow )
	{
		// if too much path, do not show the menu
        
		// NO_ERROR and FALSE are both zero, but the meaning is not the same
		return FALSE; 
	}

    UINT idCmd = idCmdFirst;
    TCHAR szEncryptMenu[MAX_PATH];
    TCHAR szDecryptMenu[MAX_PATH];
    
	m_bAppendEncryptMenu = FALSE;
	m_bAppendDecryptMenu = FALSE;

    if ((uFlags & 0x000F) == CMF_NORMAL)  //Check == here, since CMF_NORMAL=0
    {
        LoadString(g_hmodThisDll,IDS_ENCRYPT_MENU,szEncryptMenu,MAX_PATH);
        LoadString(g_hmodThisDll,IDS_DECRYPT_MENU,szDecryptMenu,MAX_PATH);
    }
    else if (uFlags & CMF_VERBSONLY)
	{
        LoadString(g_hmodThisDll,IDS_ENCRYPT_MENU,szEncryptMenu,MAX_PATH);
        LoadString(g_hmodThisDll,IDS_DECRYPT_MENU,szDecryptMenu,MAX_PATH);
	}
	else if (uFlags & CMF_EXPLORE)
	{
        LoadString(g_hmodThisDll,IDS_ENCRYPT_MENU,szEncryptMenu,MAX_PATH);
        LoadString(g_hmodThisDll,IDS_DECRYPT_MENU,szDecryptMenu,MAX_PATH);
	}
	else if (uFlags & CMF_DEFAULTONLY)
	{
		return FALSE;
	}
	else
	{
		return FALSE;
	}

	// 2004.04.28 added begin

	TCHAR szFileName[MAX_PATH];
	memset(szFileName,0,sizeof(szFileName));
	_tcsncpy(szFileName,m_szCommand,MAX_PATH - 1);

	TCHAR *pChar;
	pChar = _tcsstr(szFileName,_T("*"));
	if( NULL == pChar)
	{
		// Can not find a asterisk in the command line
        return FALSE;
	}
	else
	{
		(*pChar) = _T('\0');
	}

	TCHAR *pNextAsterisk;
	pNextAsterisk = _tcsstr(pChar + 1,_T("*"));
	
	if( NULL != pNextAsterisk )
	{
		// find another asterisk
	    // this program will not support multi selection
		return FALSE;
	}

	pChar = pChar - _tcslen(FILE_ENCRYPT_EXTENSION); // ".chy"

	if( 0 == _tcsnicmp(pChar,FILE_ENCRYPT_EXTENSION,_tcslen(FILE_ENCRYPT_EXTENSION) ) )
	{
		m_bAppendEncryptMenu = FALSE;
		m_bAppendDecryptMenu = TRUE;

		DWORD dwFileAttribute;
		dwFileAttribute = GetFileAttributes(szFileName);
		if( -1 == dwFileAttribute )
		{
			return FALSE;
		}
		if( dwFileAttribute & FILE_ATTRIBUTE_DIRECTORY )
		{
			// this is a directory
			return FALSE;
		}
	}
	else
	{
		m_bAppendEncryptMenu = TRUE;
		m_bAppendDecryptMenu = FALSE;
	}

	// 2004.04.28 added end

    if ( m_bAppendEncryptMenu || m_bAppendDecryptMenu )
    {
        InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

		if( m_bAppendEncryptMenu)
		{
			InsertMenu(hMenu,
					   indexMenu++,
					   MF_STRING|MF_BYPOSITION,
					   idCmd++,
					   szEncryptMenu);
		}
		
		if( m_bAppendDecryptMenu )
		{
			InsertMenu(hMenu,
					   indexMenu++,
					   MF_STRING|MF_BYPOSITION,
					   idCmd++,
					   szDecryptMenu);
		}

        InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

        return ResultFromShort(idCmd-idCmdFirst); //Must return number of menu
   }
   return NOERROR;
}
Beispiel #9
0
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
					 UINT indexMenu,
					 UINT idCmdFirst,
					 UINT  /* idCmdLast */,
					 UINT  /* uFlags */)
{
    UINT idCmd = idCmdFirst;

    hres = m_pDataObj->GetData(&fmte, &medium);
    if (medium.hGlobal)
	cbFiles = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, 0, 0);

    // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

    // Initialize m_cntOfHWnd to 0
    m_cntOfHWnd = 0;
    // Retrieve all the vim instances
    EnumWindows(EnumWindowsProc, (LPARAM)this);

    if (cbFiles > 1)
    {
	InsertMenu(hMenu,
		indexMenu++,
		MF_STRING|MF_BYPOSITION,
		idCmd++,
		_("Edit with &multiple Vims"));

	InsertMenu(hMenu,
		indexMenu++,
		MF_STRING|MF_BYPOSITION,
		idCmd++,
		_("Edit with single &Vim"));

	if (cbFiles <= 4)
	{
	    // Can edit up to 4 files in diff mode
	    InsertMenu(hMenu,
		    indexMenu++,
		    MF_STRING|MF_BYPOSITION,
		    idCmd++,
		    _("Diff with Vim"));
	    m_edit_existing_off = 3;
	}
	else
	    m_edit_existing_off = 2;

    }
    else
    {
	InsertMenu(hMenu,
		indexMenu++,
		MF_STRING|MF_BYPOSITION,
		idCmd++,
		_("Edit with &Vim"));
	m_edit_existing_off = 1;
    }

    // Now display all the vim instances
    for (int i = 0; i < m_cntOfHWnd; i++)
    {
	char title[BUFSIZE];
	char temp[BUFSIZE];

	// Obtain window title, continue if can not
	if (GetWindowText(m_hWnd[i], title, BUFSIZE - 1) == 0)
	    continue;
	// Truncate the title before the path, keep the file name
	char *pos = strchr(title, '(');
	if (pos != NULL)
	{
	    if (pos > title && pos[-1] == ' ')
		--pos;
	    *pos = 0;
	}
	// Now concatenate
	strncpy(temp, _("Edit with existing Vim - "), BUFSIZE - 1);
	temp[BUFSIZE - 1] = '\0';
	strncat(temp, title, BUFSIZE - 1 - strlen(temp));
	temp[BUFSIZE - 1] = '\0';
	InsertMenu(hMenu,
		indexMenu++,
		MF_STRING|MF_BYPOSITION,
		idCmd++,
		temp);
    }
    // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

    // Must return number of menu items we added.
    return ResultFromShort(idCmd-idCmdFirst);
}
Beispiel #10
0
// *** IContextMenu methods ***
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/) {
	UINT idCmd = idCmdFirst;

	FORMATETC fmte = {
		CF_HDROP,
		(DVTARGETDEVICE FAR *)NULL,
		DVASPECT_CONTENT,
		-1,
		TYMED_HGLOBAL
	};

	HRESULT hres = m_pDataObj->GetData(&fmte, &m_stgMedium);

	if (SUCCEEDED(hres)) {
		if (m_stgMedium.hGlobal)
			m_cbFiles = DragQueryFile((HDROP)m_stgMedium.hGlobal, (UINT)-1, 0, 0);
	}

	UINT nIndex = indexMenu++;

	InsertMenu(hMenu, nIndex, MF_STRING|MF_BYPOSITION, idCmd++, m_szMenuTitle);

	if (m_showIcon) {
		HBITMAP icon = NULL;
		if (m_winVer >= WINVER_VISTA) {
			icon = NULL;
			HICON hicon;
			DWORD menuIconWidth = GetSystemMetrics(SM_CXMENUCHECK);
			DWORD menuIconHeight = GetSystemMetrics(SM_CYMENUCHECK);
			HRESULT hr = LoadShellIcon(menuIconWidth, menuIconHeight, &hicon);
			if (SUCCEEDED(hr)) {
				icon = IconToBitmapPARGB32(hicon, menuIconWidth, menuIconHeight);
				DestroyIcon(hicon);
			}
		} else {
			icon = HBMMENU_CALLBACK;
		}

		if (icon != NULL) {
			MENUITEMINFO mii;
			ZeroMemory(&mii, sizeof(mii));
			mii.cbSize = sizeof(mii);
			mii.fMask = MIIM_BITMAP;
			mii.hbmpItem = icon;
			//mii.hbmpChecked = icon;
			//mii.hbmpUnchecked = icon;

			SetMenuItemInfo(hMenu, nIndex, MF_BYPOSITION, &mii);

			if (m_winVer >= WINVER_VISTA) {
				MENUINFO MenuInfo;
				MenuInfo.cbSize = sizeof(MenuInfo);
				MenuInfo.fMask = MIM_STYLE;
				MenuInfo.dwStyle = MNS_CHECKORBMP;

				SetMenuInfo(hMenu, &MenuInfo);
			}

		}
	}

	m_hMenu = hMenu;
	m_menuID = idCmd;

	return ResultFromShort(idCmd-idCmdFirst);
}
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
					 UINT indexMenu,
					 UINT idCmdFirst,
					 UINT idCmdLast,
					 UINT uFlags)
{
    UINT idCmd = idCmdFirst;

    hres = m_pDataObj->GetData(&fmte, &medium);
    if (medium.hGlobal)
	cbFiles = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, 0, 0);

    // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

    // Initialize m_cntOfHWnd to 0
    m_cntOfHWnd = 0;
    // Initialize m_bUseTab to 0
    m_bUseTab = 0;
    // Check registry for UseTab setting
    HKEY	keyhandle;
    DWORD	hlen;
    char    keyValue[BUFSIZE];
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
				       KEY_READ, &keyhandle) == ERROR_SUCCESS)
    {
	hlen = BUFSIZE;
	if (RegQueryValueEx(keyhandle, "UseTab", 0, NULL, (BYTE *)keyValue, &hlen)
							     != ERROR_SUCCESS)
	    keyValue[0] = 0;
	else
	    keyValue[hlen] = 0;
	RegCloseKey(keyhandle);
        if(_strnicmp(keyValue, "1", 1) == 0)
        {
            m_bUseTab = 1;
        }
    }
    // Check Shift key status as an opposite indicator to the existing UseTab status
    if(KEY_DOWN(VK_SHIFT))
    {
        if(m_bUseTab)
        {
            m_bUseTab = 0;
        }
        else
        {
            m_bUseTab = 1;
        }
    }
    // Retieve all the vim instances
    EnumWindows(EnumWindowsProc, (LPARAM)this);

    if (cbFiles > 1)
    {
	InsertMenu(hMenu,
		indexMenu++,
		MF_STRING|MF_BYPOSITION,
		idCmd++,
		_("Edit with &multiple Vims"));

        if(m_bUseTab)
        {
            InsertMenu(hMenu,
                    indexMenu++,
                    MF_STRING|MF_BYPOSITION,
                    idCmd++,
                    _("Edit with single &Vim using tabs"));
        }
        else
        {
            InsertMenu(hMenu,
                    indexMenu++,
                    MF_STRING|MF_BYPOSITION,
                    idCmd++,
                    _("Edit with single &Vim"));
        }

	if (cbFiles <= 4)
	{
	    // Can edit up to 4 files in diff mode
	    InsertMenu(hMenu,
		    indexMenu++,
		    MF_STRING|MF_BYPOSITION,
		    idCmd++,
		    _("Diff with Vim"));
	    m_edit_existing_off = 3;
	}
	else
	    m_edit_existing_off = 2;

    }
    else
    {
	InsertMenu(hMenu,
		indexMenu++,
		MF_STRING|MF_BYPOSITION,
		idCmd++,
		_("Edit with &Vim"));
	m_edit_existing_off = 1;
    }

    // Now display all the vim instances
    for (int i = 0; i < m_cntOfHWnd; i++)
    {
	char title[BUFSIZE];
	char temp[BUFSIZE];

	// Obtain window title, continue if can not
	if (GetWindowText(m_hWnd[i], title, BUFSIZE - 1) == 0)
	    continue;
	// Truncate the title before the path, keep the file name
	char *pos = strchr(title, '(');
	if (pos != NULL)
	{
	    if (pos > title && pos[-1] == ' ')
		--pos;
	    *pos = 0;
	}
	// Now concatenate
        if(m_bUseTab)
        {
	    strncpy(temp, _("Edit with existing Vim using tabs - "), BUFSIZE - 1);
        }
        else
        {
	    strncpy(temp, _("Edit with existing Vim - "), BUFSIZE - 1);
        }
	strncat(temp, title, BUFSIZE - 1);
	InsertMenu(hMenu,
		indexMenu++,
		MF_STRING|MF_BYPOSITION,
		idCmd++,
		temp);
    }
    // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);

    // Must return number of menu items we added.
    return ResultFromShort(idCmd-idCmdFirst);
}