ExtractAssociatedIcon

ExtractAssociatedIcon

Post by F.N. » Mon, 07 Sep 1998 04:00:00



Can anyone give me an example of the ExtractAssociatedIcon API-function ?

Thanx,

 Frederic

 
 
 

ExtractAssociatedIcon

Post by Twan Koge » Tue, 08 Sep 1998 04:00:00



>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

-------------------------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 ;

Quote:}

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM
lParam)
{
        HDC         hdc ;
        PAINTSTRUCT ps ;

        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) ;

Quote:}

void go(HWND hwnd)
{
        HICON hicon;
        WORD word;
        HDC hdc;

        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);

Quote:}

-------------------------end code---------------------

Email   : Remove ALL 8's to obtain my valid email address
Website : http://twan.hypermart.net

 
 
 

ExtractAssociatedIcon

Post by Twan Koge » Tue, 08 Sep 1998 04:00:00





>>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

I'm sorry, i was a little little error is the first code. Here is the
correct code :

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);

Quote:}

---------- end code---------------
Email   : Remove ALL 8's to obtain my valid email address
Website : http://twan.hypermart.net
 
 
 

ExtractAssociatedIcon

Post by Troy Youn » Wed, 16 Sep 1998 04:00:00



>Can anyone give me an example of the ExtractAssociatedIcon API-function ?

I've had better luck getting the associated file from the registry, then
calling ExtractIconEx().  This allows you to get the large icon and small
icon separately.  Then draw the the icon you need whereever you need it
using DrawIconEx().

. . .
        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.)

 
 
 

1. ExtractAssociatedIcon

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

6. after-effects

7. API: ExtractAssociatedIcon Error etc.

8. color

9. ExtractAssociatedIcon() to picture object?

10. ExtractAssociatedIcon

11. Something Like ExtractAssociatedIcon

12. ExtractAssociatedIcon