Qt Cómo seleccionar archivos con el mouse en una carpeta abierta
Seleccionar archivos automáticamente en una carpeta abierta, ¿verdad? No es necesario utilizar un mouse.
Prueba esto:
bool?OpenFolderAndSelectFile(const?char?*filePath)
{
#ifdef?Q_OS_WIN
p>LPITEMIDLIST?pidl;
LPCITEMIDLIST?cpidl;?
LPSHELLFOLDER?pDesktopFolder;?
ULONG?chEaten;?
HRESULT?hr;?
WCHAR?wfilePath[MAX_PATH+1]?{?0?};?
::CoInitialize(?NULL?);? p >
if(?SUCCEEDED(?SHGetDesktopFolder(? &pDesktopFolder?)?) ?) ?
{?
//?IShellFolder::ParseDisplayName ¿Pasar bytes anchos?
LPWSTR?
//#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?)?) ?
{? p>pDesktopFolder->Release();?
::CoUninitialize();?
regresar?
}
cpidl ?=?pidl;?
//?SHOpenFolderAndSelectItems es una función API no pública, ¿necesita obtenerla de shell32.dll?
//?Esta función solo es compatible con XP y versiones posteriores, no con Win2000 y 98. Teniendo en cuenta que Win2000?
/? y 98 básicamente ya no se usan, por lo que no considerar. , si el sistema anterior anterior se admite más adelante, entonces?
//?¿Agregar código de procesamiento adicional?
HMODULE?hShell32DLL?=? ::LoadLibraryA("shell32.dll");?
//ASSERT(?hShell32DLL?!!?);:LoadLibraryA("shell32. dll");? =?NULL?);?
if(?hShell32DLL?!! =?NULL?);? =?NULL?)?
{? p>
typedef?HRESULT?(WINAPI?*pSelFun)(?LPCITEMIDLIST?pidlFolder,?UINT?cidl,?LPCITEMIDLIST?*apidl,?DWORD?dwFlags?);?
pSelFun?( pSelFun)::GetProcAddress(?hShell32DLL, ?" SHO
penFolderAndSelectItems"?) ;?
//ASSERT(?pFun! =?NULL?) ;?
if(?pFun?! =?NULL?);? =?NULL ?)?
{?
hr?=?pFun(?cpidl,?0,?NULL,?0?);?//?El segundo parámetro cpidl está establecido en 0, lo que indica que el archivo ha sido seleccionado?
if(?FAILED(?hr?)?) ?
{?
::FreeLibrary(? hShell32DLL? );?
pDesktopFolder->Release();?
::CoUninitialize();?
¿regresar?
}?
}?
::FreeLibrary(?hShell32DLL?);?
}?
¿más?
{?
pDesktopFolder->Release();?
::CoUninitialize();?
¿regresar?
}?
//?¿Liberar pDesktopFolder?
pDesktopFolder->Release();?
}?
¿otra cosa? p>
{?
::CoUninitialize();?
regresar?
}
::CoUninitialize( ?
return?TRUE;
#else
QString?pathIn(filePath);
QStringList?scriptArgs; p>
scriptArgs?<
QProcess::execute(QLatin1String("/usr/bin/oscript"),?scriptArgs);
p>scriptArgs.clear();
scriptArgs?<< ;?QLatin1String("-e")? << ;QLatin1String("¿decir?aplicación?\"Finder\ "?para? activar");
QProcess::execute("/usr/bin/osascript",?scriptArgs);
return?true;
#endif
}