Recently wrote a development aids, in this process to do a similar file shortcuts to find the target function, first check MSDN98, we do not laugh, I have been using it, there is no corresponding API, and then. Net 2003, we found the API, Shopenfolderandselectitems () function, which can implement this function, and its prototype is as follows:
(Specific usage reference MSDN) "opens a microsoft®windows®explorer window with specified items in a particular folder selected."
HRESULTSHOpenFolderAndSelectItems(
LPCITEMIDLISTpidlFolder,
UINTcidl,
LPCITEMIDLIST*apidl,
DWORDdwFlags
);
But does it need Windows XP and on, how do you implement it in Win2000 or Win98? So I went online to search, after several twists and turns to find an article, but it is only the use of tools through the disassembly of Windows API functions to get the code, may be implemented with the same dialog box (I have not tried), but its code is very poor readability, I can only refer to the approximate process, He mentions a very important point, which is to use an Shgetidispatchforfolder API function to help me open the folder. Okay, here's the key part:
Find the target feature, divided into two steps to first open or locate the folder where the destination file resides, and then select the appropriate item (that is, file) in the Open folder. Before you say this step, first get to know the following two structures
typedef struct _SHITEMID {
USHORT cb;
BYTE abID[1];
} SHITEMID, * LPSHITEMID;
typedef const SHITEMID * LPCSHITEMID;
typedef struct _ITEMIDLIST {
SHITEMID mkid;
} ITEMIDLIST, * LPITEMIDLIST;
typedef const ITEMIDLIST * LPCITEMIDLIST;
The data for these two constructs is the project definition characters (literal translation only), this structure represents the folder and the file in addition to the normal, but also includes some special folders and files (such as directory, my Computer, etc.), the Shgetidispatchforfolder function is using it as a parameter, You can open some special folders. The prototype of the Shgetidispatchforfolder function is:HRESULT (WINAPI*gpfSHGetIDispatchForFolder)(ITEMIDLIST* pidl, IWebBrowserApp** ppIWebBrowserApp);
Usually the shortcut to me is the itemidlist that contains the file name, and if you call the above function directly, it will open the destination file directly instead of opening the folder. The following are the code that distinguishes files and folders:
pIdlFile = pidl;
/// 找出目标文件中文件名的偏移量
while (cb = pIdlFile->mkid.cb)
{
pidl2 = pIdlFile;
pIdlFile = (ITEMIDLIST*)((BYTE*)pIdlFile + cb);
}
cb = pidl2->mkid.cb;
pidl2->mkid.cb = 0;