Extract icon resources in your application

zhaozj2021-02-11  195

Extract icon resources in your application

I often see some software has a beautiful, light-graceful, very personal icon, and I have wanted to have, I have to have a little art cell, I have to play a good idea. After a day, I also found some doorway, the effect is still good, and then use the image editor comes with Delphi to modify, thoroughly privatize, for me. Spriving this method has made some beautiful icons in this method, making old friends envious. Ok, a good thing is certainly not exclusive, and I will take a slow way to you: first use the API function loadLibrary (LPLIBFILENAME: PCHAR): hModule; stdcall; map the specified program module to the address space of the calling program. The function returns the handle of the module, assumes Hexe; then find the resource name of the icon with EnumResourceNames (HEXE, RT_ICON, @ enumresName, myflag), where the parameter enumresName is a callback function, and the Name value of the icon will be gave a parameters of the callback function. Then add the code extraction icon to the callback function. The EnumResourceNames function will always look for every icon until the lookup failed or EnumResName returns a false value.

In this way, we can extract each icon contained in the program, and strike the last drop of oil, enough! Detailed code is as follows: unit main; interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, Menus, ImgList; typeTForm1 = class (TForm) MainMenu1: TMainMenu; File1: TMenuItem; Open1: TMenuItem; Save1: TMenuItem ; Exit1: TMenuItem; OpenDialog1: TOpenDialog; ListView1: TListView; StatusBar1: TStatusBar; ImageList1: TImageList; procedure Open1Click (Sender: TObject); procedure FormCreate (Sender: TObject); procedure FormDestroy (Sender: TObject); procedure Exit1Click (Sender: TObject); private {Private declarations} FileName: TFileName; FIcon: TIcon; public {public declarations} end; Function EnumResName (hModule: HMODULE; lpType, lpName: PChar; lParam: Longint): BOOL; stdcall; varForm1: TForm1; hExe : Hinst; implemethation {$ r * .dfm} function enumresName (HModule: hmodule; lptype, lpname: pchar; lparam: longint): BOOL; // callback function cannot be an object method // lptype is the resource type to extract, here For RT_ICON // lpname is the icon resource name Varhicon1: Hicon; hResource: hrsrc; hmem: hrsrc; lpresource: pbyte; listitem: tlistItem; begin // Returns the handle of the icon resource specified in the HEXE module; HRESOURCE: = FIN Dresource (HEXE, LPNAME, RT_ICON); // Load and Lock the iconhmem: = loadResource (HRESOURCE); lpresource: = lockResource (hmem); // Create an icon from the resource file and returns its handle Hicon1: = CREATE ICONFROM Resource EX (LP Resource, SizeOf Resource (HEXE, H Resource), True, $ 00030000, 32, 32, LR-DefaultColor); with Form1 DobeGIN // Saves the extracted icon with control imagelist and displays Ficon in ListView. Handle: = hicon1; imagelist1.addicon (ficon); ListItem: = listview1.items.add; ListItem.imageIndex: = imagelist1.count-1; end; result: = true; // Note: When returning to true value, Can you continue to extract the next icon End; Procedure TFORM1.Open1Click (Sender: TOBJECT); VarmyFlag: Integer;

转载请注明原文地址:https://www.9cbs.com/read-5467.html

New Post(0)