应用程序可以使用ExtractIcon函数从指定的可执行文件,动态链接库或图标文件中检索图标的句柄。以下示例使用DragQueryPoint函数来检索删除文件的点的坐标,用于检索删除文件的文件名的DragQueryFile函数以及检索第一个图标的句柄的ExtractIcon函数在文件中,如果有的话。
POINT pt;
WORD cFiles;
HDC hdc;
char lpszFile[80];
HANDLE hCurrentInst, hicon;
DragQueryPoint((HANDLE) wParam, &pt);
cFiles = DragQueryFile((HANDLE) wParam, 0xFFFF, NULL, NULL);
if(cFiles > 1){
TextOut(hdc,pt.x,pt.y,
"Please drop only one icon file.", 31);
return FALSE;
}
else {
DragQueryFile((HANDLE) wParam, 0, lpszFile, sizeof(lpszFile));
hCurrentInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
hicon = ExtractIcon(hCurrentInst, lpszFile, 0);
if (hicon == NULL)
TextOut(hdc, pt.x, pt.y, "No icons found.", 15);
else if (hicon == (HICON) 1)
TextOut(hdc,pt.x,pt.y,
"File must be .EXE, .ICO, or .DLL.", 33);
其他
DrawIcon(hdc, pt.x, pt.y, hicon);
}
DragFinish((HANDLE) wParam);