void CDirstatDoc::OpenItem(const CItem *item)
{
	ASSERT(item != NULL);

	CWaitCursor wc;

	try
	{
		CString path;

		switch (item->GetType())
		{
		case IT_MYCOMPUTER:
			{
				SHELLEXECUTEINFO sei;
				ZeroMemory(&sei, sizeof(sei));
				sei.cbSize= sizeof(sei);
				sei.hwnd= *AfxGetMainWnd();
				sei.lpVerb= _T("open");
				//sei.fMask= SEE_MASK_INVOKEIDLIST;
				sei.nShow= SW_SHOWNORMAL;
				CCoTaskMem<LPITEMIDLIST> pidl;
			
				GetPidlOfMyComputer(&pidl);
				sei.lpIDList= pidl;
				sei.fMask|= SEE_MASK_IDLIST;

				ShellExecuteEx(&sei);
				// ShellExecuteEx seems to display its own Messagebox, if failed.

				return;
			}
			break;

		case IT_DRIVE:
		case IT_DIRECTORY:
			path= item->GetFolderPath();
			break;

		case IT_FILE:
			path= item->GetPath();
			break;

		default:
			ASSERT(0);
		}

		ShellExecuteWithAssocDialog(*AfxGetMainWnd(), path);
	}
	catch (CException *pe)
	{
		pe->ReportError();
		pe->Delete();
	}
}
void CDirstatDoc::OnCleanupProperties()
{
	try
	{
		SHELLEXECUTEINFO sei;
		ZeroMemory(&sei, sizeof(sei));
		sei.cbSize= sizeof(sei);
		sei.hwnd= *AfxGetMainWnd();
		sei.lpVerb= _T("properties");
		sei.fMask= SEE_MASK_INVOKEIDLIST;

		CCoTaskMem<LPITEMIDLIST> pidl;
		CString path;

		const CItem *item= GetSelection();
		ASSERT(item != NULL);

		switch (item->GetType())
		{
		case IT_MYCOMPUTER:
			GetPidlOfMyComputer(&pidl);
			sei.lpIDList= pidl;
			sei.fMask|= SEE_MASK_IDLIST;
			break;

		case IT_DRIVE:
		case IT_DIRECTORY:
			path= item->GetFolderPath();
			sei.lpFile= path; // Must not be a temporary variable
			break;

		case IT_FILE:
			path= item->GetPath();
			sei.lpFile= path; // Must not be temporary variable
			break;

		default:
			ASSERT(0);
		}

		ShellExecuteEx(&sei);
		// ShellExecuteEx seems to display its own Messagebox on error.
	}
	catch (CException *pe)
	{
		pe->ReportError();
		pe->Delete();
	}
}
Beispiel #3
0
void CDirstatDoc::OnExplorerHere()
{
    try
    {
        // FIXME: Multi-select
        const CItem *item = GetSelection(0);
        ASSERT(item != NULL);

        if(IT_MYCOMPUTER == item->GetType())
        {
            SHELLEXECUTEINFO sei;
            ZeroMemory(&sei, sizeof(sei));
            sei.cbSize = sizeof(sei);
            sei.hwnd = *AfxGetMainWnd();
            sei.lpVerb = _T("explore");
            sei.nShow = SW_SHOWNORMAL;

            CCoTaskMem<LPITEMIDLIST> pidl;
            GetPidlOfMyComputer(&pidl);

            sei.lpIDList = pidl;
            sei.fMask |= SEE_MASK_IDLIST;

            ShellExecuteEx(&sei);
            // ShellExecuteEx seems to display its own MessageBox on error.
        }
        else
        {
            ShellExecuteThrow(*AfxGetMainWnd(), _T("explore"), item->GetFolderPath(), NULL, NULL, SW_SHOWNORMAL);
        }
    }
    catch (CException *pe)
    {
        pe->ReportError();
        pe->Delete();
    }
}