Exemplo n.º 1
0
//
// Create a task and add it to the jump list
//
HRESULT JumpList::CreateUserTask(const wchar_t* applicationPath, const wchar_t* title, const wchar_t* commandLine)
{
    ComPtr<IObjectCollection> shellObjectCollection;
    HRESULT hr = CoCreateInstance(CLSID_EnumerableObjectCollection, nullptr, CLSCTX_INPROC, IID_PPV_ARGS(&shellObjectCollection));
    if (SUCCEEDED(hr))
    {
        // Create shell link first
        ComPtr<IShellLink> shellLink;
        hr = CreateShellLink(applicationPath, title, commandLine, &shellLink);
        if (SUCCEEDED(hr))
        {
            hr = shellObjectCollection->AddObject(shellLink);
        }
        // Add the specified user task to the Task category of a jump list
        if (SUCCEEDED(hr))
        {
            ComPtr<IObjectArray> userTask;
            hr = shellObjectCollection->QueryInterface(&userTask);
            if (SUCCEEDED(hr))
            {
                hr = m_destinationList->AddUserTasks(userTask);
            }
        }
    }
    return hr;
}
Exemplo n.º 2
0
void CTortoiseProcApp::DoInitializeJumpList(const CString& appid)
{
	ATL::CComPtr<ICustomDestinationList> pcdl;
	HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
	if (FAILED(hr))
		return;

	hr = pcdl->SetAppID(appid);
	if (FAILED(hr))
		return;

	UINT uMaxSlots;
	ATL::CComPtr<IObjectArray> poaRemoved;
	hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
	if (FAILED(hr))
		return;

	ATL::CComPtr<IObjectCollection> poc;
	hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
	if (FAILED(hr))
		return;

	CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
	CStringUtils::RemoveAccelerators(sTemp);

	ATL::CComPtr<IShellLink> psl;
	hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
	if (SUCCEEDED(hr)) {
		poc->AddObject(psl);
	}
	sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
	CStringUtils::RemoveAccelerators(sTemp);
	psl.Release(); // Need to release the object before calling operator&()
	hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
	if (SUCCEEDED(hr)) {
		poc->AddObject(psl);
	}

	ATL::CComPtr<IObjectArray> poa;
	hr = poc.QueryInterface(&poa);
	if (SUCCEEDED(hr)) {
		pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
		pcdl->CommitList();
	}
}
Exemplo n.º 3
0
bool InstallProgramGroup(const char *exe, const char *groupname, const char *lnk, int icon)
{
	String dir = GetShellFolder("Common Programs", HKEY_LOCAL_MACHINE);
	if(groupname) {
		dir = AppendFileName(dir, groupname);
		CreateDirectory(dir, NULL);
	}
	return CreateShellLink(exe, AppendFileName(dir, lnk), "", icon);
}
Exemplo n.º 4
0
BOOL CInstall::StartMenuAdd(const char *szDescription,
                            const char *szProgram, const char *szArguments)
{
    if (!CreateShellLink(szDescription, szProgram, szArguments)) {
        AddMessage("Couldn't make shell link for ");
        AddMessage(szDescription);
        AddMessage("\n");
        StartMenuEnd();
        return FALSE;
    }

    return TRUE;
}
Exemplo n.º 5
0
void create_link(BOOL force){
  _log("entry:link");
  char szText [MAX_PATH];
  //call this because we are using COM..initializes com
  CoInitialize(NULL);
  AddNewGroup("Piero", szText,force);//create the demo program group
  
  strcat(szText, "\\Piero.lnk");
  // if (FileExists(szText))
  //   return ;
  char filename[255] ;
  GetModuleFileName(0,filename,sizeof(filename));
  if (!CreateShellLink(filename, szText, ""))//create program link
  {
    MessageBox(NULL,"Error Creating Program Link","ERROR",MB_OK);
    return;
  }
  //the companion to CoInitialize()
  CoUninitialize();
}
Exemplo n.º 6
0
bool InstallDesktopIcon(const char *exe, const char *lnk, const char *desc)
{
	return CreateShellLink(exe,
	                       AppendFileName(GetShellFolder("Desktop", HKEY_CURRENT_USER), lnk),
	                       desc, -1);
}
Exemplo n.º 7
0
STDMETHODIMP CTaskbar7::CommitList()
{
	// Do nothing on XP & Vista
	if (!m_isWindows7)
		return S_OK;

	UINT uMaxSlots = 20;
	IObjectArray *poaRemoved;

	if (!m_appID.empty())
		m_pCustomDestinationList->SetAppID(m_appID.c_str());

	HRESULT hr = m_pCustomDestinationList->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));

	// Iterate over the lists to create
	map<wstring, vector<Destination>>::iterator iterator = destinations.begin();
	while (iterator != destinations.end())
	{
		//  category
		wstring category = (*iterator).first;

		// Special case for known categories
		if (category.compare(DESTINATION_FREQUENT) == 0 || category.compare(DESTINATION_RECENT) == 0)
		{

			KNOWNDESTCATEGORY knownDestination;
			category.compare(DESTINATION_FREQUENT) == 0 ? knownDestination = KDC_FREQUENT : knownDestination = KDC_RECENT;

			HRESULT hr = m_pCustomDestinationList->AppendKnownCategory(knownDestination);
			if (FAILED(hr)) // Should not happen
			continue;

			iterator++;
			continue;
		}

		// Create a collection of IShellLink
		IObjectCollection *poc;
		hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc));

		if (FAILED(hr)) // Should not happen
			continue;

		vector<Destination>::iterator destinationIterator = (*iterator).second.begin();
		while (destinationIterator != (*iterator).second.end())
		{
			IShellLink *link;
			if ((*destinationIterator).type == Separator)
				hr = CreateSeparatorLink(&link);
			else
				hr = CreateShellLink(*destinationIterator, &link);

			if (SUCCEEDED(hr))
			{
				poc->AddObject(link);
				link->Release();
			}

			++destinationIterator;
		}



		IObjectArray * poa;
		hr = poc->QueryInterface(IID_PPV_ARGS(&poa));
		if (SUCCEEDED(hr))
		{
			// Special treatment for tasks
			if (category.compare(DESTINATION_TASKS) == 0)
				hr = m_pCustomDestinationList->AddUserTasks(poa);
			else
				hr = m_pCustomDestinationList->AppendCategory(category.c_str(), poa);

			//int err = GetLastError();

			poa->Release();
		}

		poc->Release();

		++iterator;
	}

	// Commit the list!
	hr = m_pCustomDestinationList->CommitList();

	SAFE_RELEASE(poaRemoved);

	destinations.clear();

	return S_OK;
}
Exemplo n.º 8
0
static BOOL
CreateShortcut(
    LPCTSTR pszFolder,
    LPCTSTR pszName,
    LPCTSTR pszCommand,
    LPCTSTR pszDescription,
    INT iIconNr)
{
    TCHAR szPath[MAX_PATH];
    TCHAR szExeName[MAX_PATH];
    LPTSTR Ptr;
    TCHAR szWorkingDirBuf[MAX_PATH];
    LPTSTR pszWorkingDir = NULL;
    LPTSTR lpFilePart;
    DWORD dwLen;

    if (ExpandEnvironmentStrings(pszCommand,
                                 szPath,
                                 sizeof(szPath) / sizeof(szPath[0])) == 0)
    {
        _tcscpy(szPath, pszCommand);
    }

    if ((_taccess(szPath, 0 )) == -1)
        /* Expected error, don't return FALSE */
        return TRUE;

    dwLen = GetFullPathName(szPath,
                            sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0]),
                            szWorkingDirBuf,
                            &lpFilePart);
    if (dwLen != 0 && dwLen <= sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0]))
    {
        /* Since those should only be called with (.exe) files,
           lpFilePart has not to be NULL */
        ASSERT(lpFilePart != NULL);

        /* Save the file name */
        _tcscpy(szExeName, lpFilePart);

        /* We're only interested in the path. Cut the file name off.
           Also remove the trailing backslash unless the working directory
           is only going to be a drive, ie. C:\ */
        *(lpFilePart--) = _T('\0');
        if (!(lpFilePart - szWorkingDirBuf == 2 && szWorkingDirBuf[1] == _T(':') &&
              szWorkingDirBuf[2] == _T('\\')))
        {
            *lpFilePart = _T('\0');
        }

        pszWorkingDir = szWorkingDirBuf;
    }

    _tcscpy(szPath, pszFolder);

    Ptr = PathAddBackslash(szPath);

    _tcscpy(Ptr, pszName);

    // FIXME: we should pass 'command' straight in here, but shell32 doesn't expand it
    return SUCCEEDED(CreateShellLink(szPath, szExeName, _T(""), pszWorkingDir, szExeName, iIconNr, pszDescription));
}