Wednesday, February 25, 2009

[VC++] Extracting and using icon from other Applications

If you want to have your application using the icons of some other application in an easy way ExtractIcon() or ExtractIconEx() serves you the best. See the below code snippet demonstrating how to extract and use the icon of calculator as your application icon.
HICON hIcon;
// Extract icon of Windows Calculator
hIcon = ExtractIcon( AfxGetApp()->m_hInstance, "C:\\WINDOWS\\system32\\calc.exe", 0 );
// Set the extracted icon as the application's icon.
SetIcon( hIcon, FALSE );
Do not forget to destroy the icon handle calling DestroyIcon(), when no longer needed.

No comments: