Can anyone give me an example of the ExtractAssociatedIcon API-function ?
Thanx,
Frederic
Thanx,
Frederic
Twan Kogels
-------------------------begin code---------------------
/*
ExtractAssociatedIcon() example
Made by Twan Kogels
Copyright 1998 4YOU
How to use :
Choose menu file, test. The program now extracts the first icon of the
exe file located
in c:\\windows\program.exe and then displays it on the screen.
Website : http://twan.hypermart.net
*/
#include "ico.h"
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
//wndclass.hIcon = LoadIcon (hInstance, "IDI_OWN4") ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH)
;
wndclass.lpszMenuName = "MAINMENU" ;
wndclass.lpszClassName = "icoclass" ;
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
RegisterClassEx (&wndclass) ;
hwnd = CreateWindow ("icoclass",
"ico",
WS_OVERLAPPEDWINDOW,
0,
0,
300,
300,
NULL,
NULL,
hInstance,
NULL) ;
hinst=hInstance;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAMQuote:}
switch (iMsg)
{
case WM_CREATE :
return 0 ;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_TEST:
go(hwnd);
break;
case IDM_EXIT:
SendMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
return 0;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
void go(HWND hwnd)Quote:}
word=1; //which icon to extract
hicon=ExtractAssociatedIcon(hinst, "c:\\windows\\program.exe",
&word);
if(NULL==hicon)
{
MessageBox(hwnd, "hicon = NULL", "error", MB_OK);
}
hdc=GetDC(hwnd);
DrawIcon(hdc, 10, 10, hicon);
ReleaseDC(hwnd, hdc);
-------------------------end code---------------------Quote:}
Email : Remove ALL 8's to obtain my valid email address
Website : http://twan.hypermart.net
>>Can anyone give me an example of the ExtractAssociatedIcon API-function ?
>Here is a little program that demonstrate the ExtractAssociatedIcon
>API-function. The full source code is availeble to dowload on this
>address : http://twan.hypermart.net/ico.zip
>Twan Kogels
the variable "word" as to be 0 to extract the first icon. And the
program.exe doesn't have a associatedicon so the program displayed the
default icon. Notepad.exe does have 2 associatedicons, so i changed
the program.
I have already uploaded the full source code to my website :
http://twan.hypermart.net/ico.zip
Twan Kogels
--------begin code--------
void go(HWND hwnd)
{
HICON hicon;
WORD word;
HDC hdc;
word=0; //which icon to extract
hicon=ExtractAssociatedIcon(hinst, "c:\\windows\\notepad.exe",
&word);
if(NULL==hicon)
{
MessageBox(hwnd, "hicon = NULL", "error", MB_OK);
}
hdc=GetDC(hwnd);
DrawIcon(hdc, 10, 10, hicon);
ReleaseDC(hwnd, hdc);
---------- end code---------------Quote:}
. . .
Dim sExecutable As String, lIconIndex As Long
Dim lIcon As Long, lRetVal As Long
Dim lLarge() As Long, lSmall() As Long
ReDim lLarge(0 To 0), lSmall(0 To 0)
GetDefaultIcon sExtension, sExecutable, lIconIndex
'If the registry doesn't have a default icon, then use the default
' Windows icon for unassociated files
If sExecutable = "" Then
sExecutable = "shell32.dll"
lIconIndex = 0
End If
'Try to get the associated icon (small)
lIcon = ExtractIconEx(sExecutable, lIconIndex, lLarge(0), lSmall(0),
1)
. . .
Public Function GetDefaultIcon(ByVal Extension As String, _
ByRef Executable As String, ByRef IconIndex As Long) As Boolean
Dim sDescription$, sPathAndIndex$
Dim lPos As Long
On Error GoTo SystemError
If Not GetKeyValue(HKEY_CLASSES_ROOT, "." & Extension, "", sDescription)
Then
Exit Function
End If
If Not GetKeyValue(HKEY_CLASSES_ROOT, sDescription & "\DefaultIcon", "",
sPathAndIndex) Then
Exit Function
End If
lPos = InStr(sPathAndIndex, ",")
If lPos > 0 Then
Executable = Left$(sPathAndIndex, lPos - 1)
IconIndex = Val(Mid$(sPathAndIndex, lPos + 1))
Else
Executable = sPathAndIndex
IconIndex = 0
End If
GetDefaultIcon = True
Exit Function
SystemError:
'However you deal w/ errors...
End Function
---
Troy Young
(Remove "nospam" to reply.)
Hi
I've just started using API calls. I used ExtractIcon
(copied straight out of a book) and got the expected
result. Then I tried to use ExtractAssociatedIcon using
the following code.
Declare Function MyExtractAssociatedIcon Lib "shell32.dll"
Alias "ExtractAssociatedIcon" _
(ByVal hInst As Long, ByVal lpIconPath As String, _
ByVal lpiIcon As Integer) As Long
Sub hIconToPicture()
Dim strIconFilePath As String
Dim hIcon As Long
Dim intLpiIcon As Integer
strIconFilePath = "C:\Program Files\Microsoft
Office\Office10\excel.exe"
intLpiIcon = 0
hIcon = MyExtractAssociatedIcon(0, strIconFilePath,
intLpiIcon)
Form1.Picture1.Picture = GPicTool.IconToPicture(hIcon)
End Sub
And VB returned the following error:
'453' Can't find DLL entry point ExtractAssociatedIcon in
shell32.dll
Is this because of syntax, logic .?
Thanks
2. Hash's Animation Master and Lighwave Comparison
3. ExtractAssociatedIcon into ImageList?
4. 3D-visualization slice (Java) tool
5. ExtractAssociatedIcon and ListView
7. API: ExtractAssociatedIcon Error etc.
8. color
9. ExtractAssociatedIcon() to picture object?
11. Something Like ExtractAssociatedIcon