Using Win32 functions in Visual FoxPro Image Gallery
Icon
..msdn
CopyIcon
DestroyIcon
DrawIcon
ExtractAssociatedIcon
ExtractIcon
GetIconInfo
LoadIcon
Code examples:
GDI+: Storing DLL icon resources in image files
How to view icons stored in executable files (Icon Viewer)
How to view icons stored in executable files (Icon Viewer) - II
GDI+: Storing DLL icon resources in image files

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

It shows how to save icon resources in image files (BMP, GIF, PNG, TIF and JPEG).

See also:
  • Storing DLL icon resources in .ICO files
  • How to view icons stored in executable files (Icon Viewer)
  • GDI+ function GdipCreateBitmapFromHICON

  •  
    DO declare
     
    * an instance of gdiplusinit should be created before 
    * and released after using any of gdi+ objects
    PRIVATE gdip As gdiplusinit
    gdip = NEWOBJECT("gdiplusinit", "gdiplus.prg")
     
    LOCAL cSourceFile, hModule, nIconIndex, hIcon, cTargetFile
    hModule = GetModuleHandle(0)
     
    * use any EXE or DLL file that contains icons
    *!*    cSourceFile = "C:\Program Files\Microsoft Visual Studio " +;
    *!*        ".NET\Common7\IDE\devenv.exe"
    cSourceFile = _vfp.ServerName
     
    * enumerating icons in the source file from 0 and on
    nIconIndex = 0
    DO WHILE .T.
        hIcon = ExtractIcon(hModule, cSourceFile, nIconIndex)
     
        IF hIcon <> 0
     
            * PNG, TIF
            * BMP, JPG, GIF
            * make sure the target path is valid
            cTargetFile = "c:\temp\appicon" +;
                STRTRAN(STR(nIconIndex,3)," ","0") + ".png"
     
            LOCAL oBitmap As gdibitmap
            oBitmap = NEWOBJECT("gdibitmap", "gdiplus.prg")
     
            WITH oBitmap
                .CreateFromHIcon(m.hIcon)
                IF .SaveToFile(cTargetFile)
                    ? cTargetFile + " saved"
                ELSE
                    ? cTargetFile + " - error"
                ENDIF
            ENDWITH
     
            oBitmap=NULL
            = DestroyIcon(hIcon)
            nIconIndex = nIconIndex + 1
        ELSE
            EXIT
        ENDIF
    ENDDO
     
    PROCEDURE declare
        DECLARE INTEGER DestroyIcon IN user32 INTEGER hIcon 
     
        DECLARE INTEGER ExtractIcon IN shell32;
            INTEGER hInst, STRING lpszExeFileName,;
            INTEGER lpiIcon
     
        DECLARE INTEGER GetModuleHandle IN kernel32;
            INTEGER lpModuleName 
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    1407 bytes  
    Created: 2005-12-07 14:45:31  
    Modified: 2011-01-17 19:26:39  
    Visits in 7 days: 75  
    Listed functions:
    DestroyIcon
    ExtractIcon
    GetModuleHandle
    Printer friendly API declarations
    My comment:
    To load the icon data from a .ICO file, not from resource, use this code:

    #DEFINE LR_LOADFROMFILE 0x0010
    #DEFINE LR_SHARED 0x8000
    #DEFINE IMAGE_ICON 1

    hIcon = LoadImage(0, cIconFile, IMAGE_ICON,;
            0, 0, BITOR(LR_LOADFROMFILE, LR_SHARED))

    While Windows imposes no restrictions on the sizes of icons, common sizes include 16, 32, and 48 pixels square.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (23.22.252.150)
    6.97 min.Example: 'Retrieving information about the specified icon'
    7.08 min.Function: 'ReleaseMutex'
    Function group: 'Synchronization'
    2.3 hrs.Example: 'Writing to INI file'
    12.34 hrs.Example: 'How to make a VFP form fading out when released (GDI version)'
    14.55 hrs.Example: 'Obtaining information about all user accounts on a server (WinNT only)'
     Function: 'GdipNewInstalledFontCollection'
    1 day(s)Function: 'WNetGetUser'
     Example: 'Simple Window Viewer'
     Function: 'GdipDrawLineI'
    Function group: 'GDI+ Graphics'
     Example: 'Displaying system dialog that selects a folder'
    Google
    Advertise here!