Laden...

ExtractIconEx

Erstellt von Verus vor 18 Jahren Letzter Beitrag vor 18 Jahren 2.566 Views
V
Verus Themenstarter:in
16 Beiträge seit 2005
vor 18 Jahren
ExtractIconEx

Moin,

ich wollte ExtractIconEx in meinem Programm verwenden, nur schaffe ich es leider nícht ganz. (Ist mein erster Versuch eine Funktion aus einer DLL zu nutzen)

Ich habe folgendes gemacht:


[System.Runtime.InteropServices.DllImport("Shell32.dll";)]
private static extern uint ExtractIconEx( string lpszFile,
int nIconIndex,
System.IntPtr phiconLarge,
System.IntPtr phiconSmall,
uint nIcons);


public static System.Drawing.Icon GetIcon(IconSize size)
{
System.IntPtr hIcon = new IntPtr();
ExtractIconEx( "Shell32.dll",
15,
size == IconSize.Large ? hIcon : System.IntPtr.Zero,
size == IconSize.Small ? hIcon : System.IntPtr.Zero,
1);

System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(hIcon).Clone();

DestroyIcon(hIcon);

return icon;
}

So wie ich das oben geschrieben habe funktioniert es leider nicht. Scheinbar initialisiere ich hIcon falsch. Kann mir einer sagen, wie ich das machen muss?

phiconLarge [out] Pointer to an array of icon handles that receives handles to the large icons extracted from the file. If this parameter is NULL, no large icons are extracted from the file.
_ phiconSmall_ [out] Pointer to an array of icon handles that receives handles to the small icons extracted from the file. If this parameter is NULL, no small icons are extracted from the file.

Und wie bekommt man Tabs in den Quellcode??

"Ein Mensch ohne Macke ist kacke."

X
2.051 Beiträge seit 2004
vor 18 Jahren
 
		private static extern uint ExtractIconEx( string lpszFile,
            int nIconIndex,
            out System.IntPtr phiconLarge,
            out System.IntPtr phiconSmall,
            uint nIcons);

        public static System.Drawing.Icon GetIcon()
        {
            System.IntPtr hIconL;
            System.IntPtr hIconS;
            ExtractIconEx( "Shell32.dll",
                15,
                out hIconL,
                out hIconS,
                1);

            System.Drawing.Icon icon = Icon.FromHandle(hIconL); //oder hIconS
...

49.485 Beiträge seit 2005
vor 18 Jahren

Hallo Verus,

kennst du http://pinvoke.net ? Das ist für solche Fälle sehr praktisch.

herbivore

V
Verus Themenstarter:in
16 Beiträge seit 2005
vor 18 Jahren

@Xggene
danke, hat bestens funktioniert.

@herbivore
kannte ich noch nicht, scheint sehr hilfreich zu sein

"Ein Mensch ohne Macke ist kacke."