An application can use the ExtractIcon function to retrieve the handle of an icon from a specified executable file, dynamic-link library, or icon file. The following example uses the DragQueryPoint function to retrieve the coordinates of the point where a file was dropped, the DragQueryFile function to retrieve the filename of a dropped file, and the ExtractIcon function to retrieve the handle of the first icon in the file, if any:
HDC hdc;
HANDLE hCurrentInst, hicon;
POINT pt;
char szFile[80];
hCurrentInst = (HANDLE) GetWindowWord(hwnd, GWW_HINSTANCE);
DragQueryPoint((HANDLE) wParam, &pt);
DragQueryFile((HANDLE) wParam, 0, szFile, sizeof(szFile));
hicon = ExtractIcon(hCurrentInst, szFile, 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);
else
DrawIcon(hdc, pt.x, pt.y, hicon);