2、差岩誉其次打开外部工具界面虚段,点‘+'号进入添加外部枣尺工具界面。
3、最后在‘Name'处输入工具名称,这个名称可以随便取,只要自己清楚就行即可。
是在打开的文件夹中自动选中某文件吧?不需要用鼠标。
试试看这一段:
bool OpenFolderAndSelectFile(const char *filePath)
{
#ifdef Q_OS_WIN
LPITEMIDLIST pidl
LPCITEMIDLIST cpidl
LPSHELLFOLDER pDesktopFolder
ULONG chEaten
HRESULT hr
WCHAR wfilePath[MAX_PATH+1] = { 0 }
::CoInitialize( NULL )
if ( SUCCEEDED( SHGetDesktopFolder( &pDesktopFolder ) ) )
{
// IShellFolder::ParseDisplayName要传入宽字节
LPWSTR lpWStr = NULL
//#ifdef _UNICODE
// _tcscpy( wfilePath, strFilePath )
// lpWStr = wfilePath
//#else 孝乎岩
MultiByteToWideChar( CP_ACP, 0, (LPCSTR)filePath, -1, wfilePath, MAX_PATH )
lpWStr = wfilePath
//#endif
hr = pDesktopFolder->ParseDisplayName( NULL, 0, lpWStr, &chEaten, &pidl, NULL )
if ( FAILED( hr ) )
{
pDesktopFolder->Release()
::CoUninitialize()
return FALSE
}
cpidl = pidl
顷早 // SHOpenFolderAndSelectItems是非公开的API函数,需要从shell32.dll获取
// 该函数只有XP及以上的系统才支持,Win2000和98是不支持的,考虑到Win2000 巧御
// 和98已经基本不用了,所以就不考虑了,如果后面要支持上述老的系统,则要
// 添加额外的处理代码
HMODULE hShell32DLL = ::LoadLibraryA("shell32.dll")
//ASSERT( hShell32DLL != NULL )
if( hShell32DLL != NULL )
{
typedef HRESULT (WINAPI *pSelFun)( LPCITEMIDLIST pidlFolder, UINT cidl, LPCITEMIDLIST *apidl, DWORD dwFlags )
pSelFun pFun = (pSelFun)::GetProcAddress( hShell32DLL, "SHOpenFolderAndSelectItems" )
//ASSERT( pFun != NULL )
if( pFun != NULL )
{
hr = pFun( cpidl, 0, NULL, 0 ) // 第二个参数cidl置为0,表示是选中文件
if ( FAILED( hr ) )
{
::FreeLibrary( hShell32DLL )
pDesktopFolder->Release()
::CoUninitialize()
return FALSE
}
}
::FreeLibrary( hShell32DLL )
}
else
{
pDesktopFolder->Release()
::CoUninitialize()
return FALSE
}
// 释放pDesktopFolder
pDesktopFolder->Release()
}
else
{
::CoUninitialize()
return FALSE
}
::CoUninitialize()
return TRUE
#else
QString pathIn(filePath)
QStringList scriptArgs
scriptArgs << QLatin1String("-e") << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"").arg(pathIn.replace('\\', '/'))
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs)
scriptArgs.clear()
scriptArgs << QLatin1String("-e") << QLatin1String("tell application \"Finder\" to activate")
QProcess::execute("/usr/bin/osascript", scriptArgs)
return true
#endif
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)