Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2003, 10:45 PM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mokka°logic
Default C# and ExtractIcon...


Hi everyone,

I'm desperately after a good wrapping code for the ExtractIcon or ExtractIconEx API functions. Does someone have that already in your code repositories? I'm not too much into P/Invoke, and that is a recurring task every once in a while, so maybe someone can help me out with that... basically, I need it to extract icons with a given index from a library (icl, dll, exe), but I wonder whether I can specify the desired size as well. I currently have something found [a href="http://www.kennyandkarin.com/Kenny/CodeCorner/Tools/IconBrowser"]here[/a] and of course I have analysed it, but have not been able to work out how to specify the preferred size.

Many thanks for your advice,
Best, Philipp
 
Old June 18th, 2003, 04:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Hi Philipp

while reading your mail I wrote this code. Just go through
it.

[DllImport("shell32.dll",CharSet=CharSet.Auto)]
public static extern int ExtractIconEx(
    string path, int i, IntPtr[] small, IntPtr[] big, uint op);


[DllImport("user32.dll",CharSet=CharSet.Auto)]
public static extern int DrawIconEx(
    IntPtr hdc, // handle to device context
    int xLeft, // x-coord of upper left corner
    int yTop, // y-coord of upper left corner
    IntPtr hIcon, // handle to icon
    int cxWidth, // icon width
    int cyWidth, // icon height
    uint istepIfAniCur, // frame index, animated cursor
    IntPtr dbrFlickerFreeDraw, // handle to background brush
    uint diFlags); // icon-drawing flags

.
.
.
.
.
.
.
.
.
.

int m_nIcons = ExtractIconEx(
    "C:\\WINNT\\system32\\SHELL32.dLL",
    -1,
    null,
    null,
    0);

if(m_nIcons == -1)
{
    MessageBox.Show("Couldn't retreive icons.");
    return;
}

IntPtr[] m_pIconsLarge = new IntPtr[m_nIcons];
IntPtr[] m_pIconsSmall = new IntPtr[m_nIcons];

ExtractIconEx(
    "C:\\WINNT\\system32\\SHELL32.dLL",
    0,
    m_pIconsLarge,
    m_pIconsSmall,
    (uint)m_nIcons);

Graphics gf = Graphics.FromHwnd(this.Handle);
IntPtr hDC = gf.GetHdc();

for(int i = 0 ; i < m_nIcons; i++)
{
    DrawIconEx(hDC, // DC
        60,60, // x,y
        m_pIconsLarge[i], // HICON
        100,100, // cx,cy
        0, // frame num N/A
        (IntPtr)null , // background brush
        3); // flags

        System.Threading.Thread.Sleep(500);
}


There are some easier ways of drawing icons and bitmaps
under .Net.
you might wanna explore functions like Graphics
class's DrawIcon function.

Do write back if there is anything you wanna ask.



Ankur Verma
.Net and C++ Specialist
Wiley Tech Support









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.