這章用到比較多的兩個(gè)接口
IShellLink IPersistFile
兩個(gè)COM接口,一個(gè)ShellLink提供對(duì)于快捷方式信息存取的方法,但是如果要載入或保存快捷方式,需要通過ShellLink Query一個(gè)IPersistFile接口,使用IPersistFile的載入保存方法.
貼載入與讀取的這段
1
WCHAR wszLnkFile[MAX_PATH] =
{0};
2
IShellLink* 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
//現(xiàn)在可以用pShellLink了
29
hr = pPF->Save(wszLnkFile, TRUE);
30
31
// Clean up
32
pPF->Release();
33
pShellLink->Release();
34
下面這段是一個(gè)Drag的例子
WindowFromPoint(pt)感覺很強(qiáng),可以獲取pt點(diǎn)(屏幕坐標(biāo)系)的窗體對(duì)象
DragQueryFile來分析hDrop
hDrop是WM_DROPFILES事件的(wParam)參數(shù),類型為HDROP
一般都用reinterpret_cast轉(zhuǎn)換
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);


