ExtractAssociatedIcon 
Author Message
 ExtractAssociatedIcon

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

Thanx,

 Frederic



Thu, 22 Feb 2001 03:00:00 GMT  
 ExtractAssociatedIcon

Quote:

>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



Fri, 23 Feb 2001 03:00:00 GMT  
 ExtractAssociatedIcon


Quote:

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


Fri, 23 Feb 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ExtractAssociatedIcon API Help

2. ExtractAssociatedIcon API

3. ExtractAssociatedIcon

4. ExtractAssociatedIcon API, help needed!!!

5. Nobody knows how to use ExtractAssociatedIcon ??!!

6. how to use ExtractAssociatedIcons in VB5?

7. ExtractAssociatedIcon API call

8. EXTRACTASSOCIATEDICON - Help required ..PLS

9. ExtractAssociatedIcon

10. ExtractAssociatedIcon

11. ExtractAssociatedIcon like Windows Explorer

12. ExtractAssociatedIcon API

 

 
Powered by phpBB® Forum Software