18. september 2002 - 23:05Der 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 ??
Hos Computerworld it-jobbank er vi stolte af at fortsætte det gode partnerskab med folkene bag IT-DAY – efter vores mening Danmarks bedste karrieremesse for unge og erfarne it-kandidater.
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!
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 ??
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 /////////////////////////////////
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.
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; }
// 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;
// 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); } }
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"....
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 !!!
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!
Synes godt om
Ny brugerNybegynder
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.