这章用到比较多的两个接口
IShellLink IPersistFile
两个COM接口,一个ShellLink提供对于快捷方式信息存取的方法,但是如果要载入或保存快捷方式,需要通过ShellLink Query一个IPersistFile接口,使用IPersistFile的载入保存方法.
贴载入与读取的这段
1WCHAR wszLnkFile[MAX_PATH] = {0};
2IShellLink* pShellLink = NULL;
3 IPersistFile* pPF = NULL;
4
5 // Create the appropriate COM server
6 HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL,
7 CLSCTX_INPROC_SERVER, IID_IShellLink,
8 reinterpret_cast<LPVOID*>(&pShellLink));
9 if(FAILED(hr))
10 return hr;
11
12 // Get the IPersistFile interface to load the LNK file
13 hr = pShellLink->QueryInterface(IID_IPersistFile, reinterpret_cast<LPVOID*>(&pPF));
14 if(FAILED(hr))
15 {
16 pShellLink->Release();
17 return hr;
18 }
19 MultiByteToWideChar(CP_ACP, 0, szLnkFile, -1, wszLnkFile, MAX_PATH);
20 hr = pPF->Load(wszLnkFile, STGM_READ);
21 if(FAILED(hr))
22 {
23 pPF->Release();
24 pShellLink->Release();
25 return hr;
26 }
27
28 //现在可以用pShellLink了
29 hr = pPF->Save(wszLnkFile, TRUE);
30
31 // Clean up
32 pPF->Release();
33 pShellLink->Release();
34
下面这段是一个Drag的例子
WindowFromPoint(pt)感觉很强,可以获取pt点(屏幕坐标系)的窗体对象
DragQueryFile来分析hDrop
hDrop是WM_DROPFILES事件的(wParam)参数,类型为HDROP
一般都用reinterpret_cast转换
POINT pt;
DragQueryPoint(hDrop, &pt);
ClientToScreen(hDlg, &pt);
HWND hwndDrop = WindowFromPoint(pt);
if(hwndDrop != GetDlgItem(hDlg, IDC_VIEW))
{
Msg(__TEXT("Sorry, you have to drop over the list view control!"));
return;
}
// Now check the files
int iNumOfFiles = DragQueryFile(hDrop, -1, NULL, 0);
for(int i = 0 ; i < iNumOfFiles; i++)
{
TCHAR szFileName[MAX_PATH] = {0};
DragQueryFile(hDrop, i, szFileName, MAX_PATH);
//获得了文件名,index为i的
}
DragFinish(hDrop);