SHOpenFolderAndSelectItems - 实现查找目标
2009年08月11日 星期二 01:02
睡觉之前发点代码,今天发现R3下新的一个结束进程的方法,原理跟内存清零差不多,不过速度快多了(目前看到的那些清零的R3源码,连个判断都懒得加,速度太慢了...),哎,R3下拿不到句柄的话说这么多也就没用了.
不知道查找目标是啥的搜索下就知道了,根据网上一个人的代码改的,已经写成函数了,只要把目标的路径传进去就可以了.
应该都会用吧 ^_^
CoInitialize(NULL);
|
|
|
BOOL OpenFolderAndSelectFile( LPSTR lpszFilePath)
{
//
// GetFolder
//
DWORD dw = lstrlenA(lpszFilePath) - 1;
for (;dw != -1;dw--)
{
if ( lpszFilePath[dw] == '\\')
{
break;
}
}
if ( dw == -1)
{
return FALSE;
}
//
// Get a pointer to the Desktop's IShellFolder interface.
//
LPSHELLFOLDER pDesktopFolder;
if ( SUCCEEDED(SHGetDesktopFolder( &pDesktopFolder)))
{
//
// IShellFolder::ParseDisplayName requires the file name be in
// Unicode.
//
OLECHAR oleStr[MAX_PATH];
lpszFilePath[dw] = '\0';
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
lpszFilePath, -1, oleStr, _countof(oleStr));
//
// Convert the path to an ITEMIDLIST.
//
LPITEMIDLIST pidl;
ULONG chEaten;
ULONG dwAttributes;
HRESULT hr;
hr = pDesktopFolder->ParseDisplayName(
NULL, NULL, oleStr, &chEaten, &pidl, &dwAttributes);
if (FAILED(hr))
{
pDesktopFolder->Release();
return FALSE;
}
LPCITEMIDLIST pidlFolder = pidl;
lpszFilePath[dw] = '\\';
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
lpszFilePath, -1, oleStr, _countof(oleStr));
hr = pDesktopFolder->ParseDisplayName(
NULL, NULL, oleStr, &chEaten, &pidl, &dwAttributes);
if (FAILED(hr))
{
pDesktopFolder->Release();
return FALSE;
}
LPCITEMIDLIST pidlFile = pidl;
CoInitialize( NULL);
hr = SHOpenFolderAndSelectItems( pidlFolder, 1, &pidlFile, 0);
pDesktopFolder->Release();
if ( hr == S_OK)
{
return TRUE;
}
}
return FALSE;
} |
|