Avatar billede tjalle Nybegynder
18. september 2002 - 23:05 Der er 12 kommentarer og
1 løsning

ico -> dll

Hejsa.

Jeg har en masse ikoner, som jeg gerne vil have ind i en dll... Fra windows kender man jo shell32.dll som er windows ikon-fil. Nu vil jeg gerne lave min egen til brug i en .net applikation...

Hvordan gøres dette ??
Er der nogen "gode" nemme ikon-editorere ??

Hvordan tilgås et ikon i en dll ??

Tj.
Avatar billede z42cool Nybegynder
19. september 2002 - 08:18 #1
Avatar billede tjalle Nybegynder
19. september 2002 - 10:20 #2
Jeg har faktisk fundet ud af hvordan jeg laver dem til DLL'er.. der findes en række freware tools der gør dette.

Problemet er nu at jeg skal have det ind i vb.net fra en dll.
Alt hvad jeg kan finde på internettet af eksempler er til vb6 eller tidligere....

selv msdn har ikke en artikel om noget så elementært ??

z42cool.. det må da lige være noget du kan løse ??
Avatar billede z42cool Nybegynder
19. september 2002 - 10:27 #3
Du skal ikke lave en "almindelig" windows dll. Du skal gøre som tutorialen siger og lave en resx fil -> til en .resources fil -> som du kompilerer med ind i din .dll. På denne måde kan du bruge .Net resource systemet!
Du kan godt loade ressourcer fra gammeldags .dll filer, men det er noget værre bøvl der inkludere kald til Win32 vha. p/Invoke og da du vel alligevel skal distribuere dine ikoner sammen med din applikation er .Net løsningen meget bedre!
Avatar billede tjalle Nybegynder
19. september 2002 - 10:34 #4
ok.. jeg kigger tutorial'et igennem...

håber jeg kan finde ud af det !!!
Avatar billede z42cool Nybegynder
19. september 2002 - 11:02 #5
Sig til hvis du får problemer så skal jeg nok forsøge at hjælpe!
Avatar billede tjalle Nybegynder
19. september 2002 - 11:12 #6
tager tutoriallet fra bunden og har lavet .resource-fil med strings... kan dog ikke finde det omtalt rexxgen.exe -tools som der står man kan hente ??

har du det ??
Avatar billede tjalle Nybegynder
19. september 2002 - 11:22 #7
hvordan kan de skrive der her : "ResXGen — A handy tool for converting resources is the ResXGen utility included with this tutorial. " når man ikke kan finde tool'et nogle steder ??

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptutorials/html/image_resources.asp
Avatar billede z42cool Nybegynder
19. september 2002 - 12:03 #8
/*=====================================================================
  File:      ArgParse.cs

  Summary:  Reusable class for parsing command-line arguments.

---------------------------------------------------------------------
  This file is part of the Microsoft .NET Framework SDK Code Samples.

  Copyright (C) 2001 Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
=====================================================================*/

// Add the classes in the following namespaces to our namespace
using System;


///////////////////////////////////////////////////////////////////////////////


public abstract class ArgParser {
    private String[] switchChars;            // For example: "/", "-"
    private String[] switchSymbols;          // Switch character(s)
    private Boolean  caseSensitiveSwitches;  // Are switches case-sensitive?


    // Domain of results when processing a command-line argument switch
    protected enum SwitchStatus { NoError, Error, ShowUsage, ShowSchema };


    // Constructor that defaults to case-insensitive switches and
    // defaults to "/" and "-" as the only valid switch characters
    public ArgParser(String[] switchSymbols)
        : this(switchSymbols, false, new string[] { "/", "-" }) {
    }


    // Constructor that defaults to "/" and "-" as the only valid switch characters
    public ArgParser(String[] switchSymbols, Boolean caseSensitiveSwitches)
        : this(switchSymbols, caseSensitiveSwitches, new string[] { "/", "-" }) {
    }


    // Constructor with no defaults
    public ArgParser(String[] switchSymbols, Boolean caseSensitiveSwitches, String[] switchChars) {
        this.switchSymbols = switchSymbols;
        this.caseSensitiveSwitches = caseSensitiveSwitches;
        this.switchChars  = switchChars;
    }


    // Every derived class must implement an OnUsage method
    public abstract void OnUsage(String errorInfo);

    // Every derived class must implement an OnSchema method
    public abstract void OnSchema();


    // Every derived class must implement an OnSwitch method or a switch is considerred an error
    protected virtual SwitchStatus OnSwitch(String switchSymbol, String switchValue) {
        return(SwitchStatus.Error);
    }


    // Every derived class must implement an OnNonSwitch method or a non-switch is considerred an error
    protected virtual SwitchStatus OnNonSwitch(String value) {
        return(SwitchStatus.Error);
    }


    // The derived class is notified after all command-line switches have been parsed.
    // The derived class can perform any sanity checking required at this time.
    protected virtual SwitchStatus OnDoneParse() {
        // By default, we'll assume that all parsing was successful
        return(SwitchStatus.Error);
    }


    // This Parse method always parses the application's command-line arguments
    public Boolean Parse() {
        // Visual Basic will use this method since its entry-point function
        // doesn't get the command-line arguments passed to it.
        return(Parse(Environment.GetCommandLineArgs()));
    }


    // This Parse method parses an arbitrary set of arguments
    public Boolean Parse(String[] args) {
        SwitchStatus ss = SwitchStatus.NoError;        // Assume parsing is sucessful.

        int ArgNum;
        for (ArgNum = 0; (ss == SwitchStatus.NoError) && (ArgNum < args.Length); ArgNum++) {

            // Determine if this argument starts with a valid switch character
            Boolean fIsSwitch = false;
            for (int n = 0; !fIsSwitch && (n < switchChars.Length); n++) {
                fIsSwitch = (0 == String.CompareOrdinal(args[ArgNum], 0,
                    switchChars[n], 0, 1));
            }

            if (fIsSwitch) {
                // Does the switch begin with a legal switch symbol?
                Boolean fLegalSwitchSymbol = false;
                int n;
                for (n = 0; !fLegalSwitchSymbol && (n < switchSymbols.Length); n++) {
                    if (caseSensitiveSwitches) {
                        fLegalSwitchSymbol = (0 == String.CompareOrdinal(args[ArgNum], 1,
                            switchSymbols[n], 0, switchSymbols[n].Length));
                    } else {
                        fLegalSwitchSymbol = (0 == String.CompareOrdinal(args[ArgNum].ToUpper(), 1,
                            switchSymbols[n].ToUpper(), 0, switchSymbols[n].Length));
                    }
                    if (fLegalSwitchSymbol) break;
                }
                if (!fLegalSwitchSymbol) {
                    // User specified an unrecognized switch, exit
                    ss = SwitchStatus.Error;
                    break;
                } else {
                    // This is a legal switch, notified the derived class of this switch and its value
                    ss = OnSwitch(
                        caseSensitiveSwitches ? switchSymbols[n] : switchSymbols[n].ToLower(),
                        args[ArgNum].Substring(1 + switchSymbols[n].Length));
                }
            } else {
                // This is not a switch, notified the derived class of this "non-switch value"
                ss = OnNonSwitch(args[ArgNum]);
            }
        }

        // Finished parsing arguments
        if (ss == SwitchStatus.NoError) {
            // No error occurred while parsing, let derived class perform a
            // sanity check and return an appropraite status
            ss = OnDoneParse();
        }

        if (ss == SwitchStatus.ShowSchema) {
            // Status indicates that schema should be shown, show it
            OnSchema();
        }

        if (ss == SwitchStatus.ShowUsage) {
            // Status indicates that usage should be shown, show it
            OnUsage(null);
        }

        if (ss == SwitchStatus.Error) {
            // Status indicates that an error occurred, show it and the proper usage
            OnUsage((ArgNum == args.Length) ? null : args[ArgNum]);
        }

        // Return whether all parsing was sucessful.
        return(ss == SwitchStatus.NoError);
    }
}


///////////////////////////////// End of File /////////////////////////////////
Avatar billede z42cool Nybegynder
19. september 2002 - 12:03 #9
/*+==========================================================================
  File:      ResGenX.cs

  Summary:  Command-line utility to produce .resX files from binary files.

----------------------------------------------------------------------------
  This file is part of the Microsoft .NET Framework SDK.

  Copyright (C) 2001 Microsoft Corporation.  All rights reserved.

  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.

==========================================================================+*/


using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Resources;
using System.Windows.Forms;

[assembly: System.Reflection.AssemblyVersion("1.0.2510.0")]

public class MainApp {

    public static int Main(string[] args) {
    Console.WriteLine("Microsoft (R) .ResX Generator - Version 1.0.3.0\r");
    Console.WriteLine("Copyright (c) Microsoft Corp 2001.  All rights reserved.\r\n");

    ResXGenArgParser ap = new ResXGenArgParser();
        if (!ap.Parse(args)) {
            // An error occurrend while parsing
            return 1;
          }
   
    try {
        Image img = Image.FromFile(ap.InputFile);
        ResXResourceWriter rsxw = new ResXResourceWriter(ap.OutputFile);

        rsxw.AddResource(ap.ResourceName, img);
        Console.WriteLine ("Results written to " + ap.OutputFile);
        rsxw.Close();
    }
       
    catch (FileNotFoundException) {
        Console.WriteLine("Error: Inputfile " + ap.InputFile + " could not be found.\r\n",args[0]);
    }
       
    catch (Exception e) {
        Console.WriteLine(e.Message);
    }
        return 0;
    }
}

///////////////////////////////////////////////////////////////////////////////

class ResXGenArgParser : ArgParser {

    private string  inputFile = "";
    private string  outputFile = "";
    private string  resourceName = "";


    // Members identifying command-line argument settings
    public string filename = "";


    // Give the set of valid command-line switches to the base class
    public ResXGenArgParser() : base(new string[] { "?", "i:", "n:", "o:", "s"}) {
    }


    // Shows resource schema.
    public override void OnSchema() {
    Console.WriteLine(ResXResourceWriter.ResourceSchema);
    }

    // Returns the user-specified input filename
    public String InputFile { get { return inputFile; } }


    // Returns the user-specified output filename
    public String OutputFile { get { return outputFile; } }


    // Returns the user-specified resource name
    public String ResourceName { get { return resourceName; } }


    // Shows application's usage info and also reports command-line argument errors.
    public override void OnUsage(String errorInfo) {
        if (errorInfo != null) {
            // An command-line argument error occurred, report it to user
            // errInfo identifies the argument that is in error.
            Console.WriteLine("Command-line switch error: {0}\n", errorInfo);
        }

    Console.WriteLine("");
    Console.WriteLine("Usage:\r");
    Console.WriteLine("    ResXGen [/i:<inputfile> /o:<outputfile> /n:<name>] [/s] [/?]\r\n");
    Console.WriteLine("Parameters:\r");
    Console.WriteLine("    /i:          Input image filename to convert\r");
    Console.WriteLine("    /o:          Output .resx filename\r");
    Console.WriteLine("    /n:          Name of the resource\r");
    Console.WriteLine("");
    Console.WriteLine("    /s            Displays ResX Resource Schema.\r");
    Console.WriteLine("");
    Console.WriteLine("    /?            Show usage information\r");
    Console.WriteLine("");
    Console.WriteLine("ResXGen.exe is a file generator utility that reads image files\r");
    Console.WriteLine("and generates .ResX (XML-based resource format) files as output.");
    }


    // Called for each non-switch command-line argument (filespecs)
    protected override SwitchStatus OnNonSwitch(String switchValue) {
        SwitchStatus ss = SwitchStatus.Error;
        filename = switchValue;
        return(ss);
    }


    // Called for each switch command-line argument
    protected override SwitchStatus OnSwitch(String switchSymbol, String switchValue) {
        // NOTE: For case-insensitive switches,
        //      switchSymbol will contain all lower-case characters

        SwitchStatus ss = SwitchStatus.NoError;
        switch (switchSymbol) { 

        case "i:":  // Input filename
            if (switchValue.Length < 1) {
                Console.WriteLine("No input file specified.");
                ss = SwitchStatus.Error;
            } else {
                inputFile = switchValue;
            }
            break;

        case "o:":  // Output filename
            if (switchValue.Length < 1) {
                Console.WriteLine("No output file specified.");
                ss = SwitchStatus.Error;
            } else {
                outputFile = switchValue;
            }
            break;

        case "n:":  // Resource name
            if (switchValue.Length < 1) {
                Console.WriteLine("No resourcename file specified.");
                ss = SwitchStatus.Error;
            } else {
                resourceName = switchValue;
            }
            break;

        case "s":  // User wants to see Schema
            ss = SwitchStatus.ShowSchema;
            break;

        case "?":  // User wants to see Usage
            ss = SwitchStatus.ShowUsage;
            break;

        default:
            Console.WriteLine("Invalid switch: \"" + switchSymbol + "\".\n");
            ss = SwitchStatus.Error;
            break;
        }
        return(ss);
    }


    // Called when all command-line arguments have been parsed
    protected override SwitchStatus OnDoneParse() {
        SwitchStatus ss = SwitchStatus.NoError;
        // Sort all the filenames in the list
        if (inputFile == "") {
            Console.WriteLine("Error: Must include input filename.");
            ss = SwitchStatus.Error;
        }
        if (outputFile == "") {
            Console.WriteLine("Error: Must include output filename.");
            ss = SwitchStatus.Error;
        }
        if (resourceName == "") {
            Console.WriteLine("Error: Must include resource name.");
            ss = SwitchStatus.Error;
        }
        return(ss);
    }
}
Avatar billede z42cool Nybegynder
19. september 2002 - 12:04 #10
Eksperten, nu også so P2P tjeneste :-) Kompiler med:

csc /r:system.dll /r:system.windows.forms.dll /r:system.drawing.dll resxgen.cs argparser.cs
Avatar billede tjalle Nybegynder
19. september 2002 - 12:28 #11
hehe.. har selv fikset en løsning:

Dette program :: http://www.aisto.com/roeder/dotnet/
Kan lave resource-filer grafisk, hvor jeg giver ikonerne navne.. eks. "icoAccess".

Denne Funktion, henter et ikon fra resource-filen:

Function getIcon(ByVal icoName As String) As Icon
        Dim i As Icon
        Dim rr As ResourceReader = New ResourceReader("icons.resources")
        Dim de As IDictionaryEnumerator = rr.GetEnumerator()
        While de.MoveNext()

            If (icoName = de.Key) Then
                i = CType(de.Value, System.Drawing.Icon)
                Return i
            End If

        End While
        rr.Close()
        Return i

    End Function

et kald i min kode "getIcon("icoAccess") vil returnere et ikon som i resource-filen har fået navnet "icoAccess"....

Tj.

Mange tak for din deltagelse....
Avatar billede tjalle Nybegynder
19. september 2002 - 12:29 #12
forresten z42cool. En af mine venner (er også her på eksperten, kaldet Meek), har gang i noget nyt indenfor VB.NET

Han har købt "openvb.net" og vil lave en slags opensource-portal for VB.NET... måske var det noget for dig at deltage, når siden kommer op at køre... du lyder til at have styr på det !!!

Tj.
Avatar billede z42cool Nybegynder
19. september 2002 - 12:49 #13
Hmmm..... Det grafiske værktøj er self. smart nok, men måden at hente ressourcen på er en anelse omstændig:

Function getIcon(ByVal icoName As String) As Icon
  Dim rm As ResourceManager = ResourceManager.CreateFileBasedResourceManager("icons.resources", ".", Nothing)
  return CType(rm.GetObject(icoName), Icon)
End Function

Og så vil jeg i øvrigt sige at fil baserede ressourcer (.resource filer) er en dårlig løsning hvis du laver stand-alone applikationer. Det er langt bedre at kompilere dem med ind i dit assembly.
Mht. til Meeks .Net portal er det da ikke umuligt at jeg kan være til nytte, men det er lidt nemmere at svare på når du har noget der er en anelse mere konkret!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester