Работа с ресурсами – загрузка иконки и курсора

{codecitation class=»brush: pascal; gutter: false;» width=»600px»}

Автор: Xavier Pacheco

{

Copyright © 1998 by Delphi 4 Developer’s Guide — Xavier Pacheco and Steve Teixeira

}

program resource;

uses

Forms,

MainFrm in ‘MainFrm.pas’ {MainForm};

{$R *.RES}

{$R RESFILE2.RES} // Add the additional resource file

begin

Application.Initialize;

Application.CreateForm(TMainForm, MainForm);

Application.Run;

end.

{

Copyright © 1999 by Delphi 5 Developer’s Guide — Xavier Pacheco and Steve Teixeira

}

unit MainFrm;

interface

uses

Windows, Forms, Controls, Classes, StdCtrls, ExtCtrls;

const

crXHair = 1; // Declare a constant for the new cursor. This value

type // must be a positive number. or less than -20.

TMainForm = class(TForm)

imgBitmap: TImage;

btnChemicals: TButton;

btnClear: TButton;

btnChangeIcon: TButton;

btnNewCursor: TButton;

btnOldCursor: TButton;

btnOldIcon: TButton;

btnAthena: TButton;

procedure btnChemicalsClick(Sender: TObject);

procedure btnClearClick(Sender: TObject);

procedure btnChangeIconClick(Sender: TObject);

procedure btnNewCursorClick(Sender: TObject);

procedure btnOldCursorClick(Sender: TObject);

procedure btnOldIconClick(Sender: TObject);

procedure btnAthenaClick(Sender: TObject);

end;

var

MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.btnChemicalsClick(Sender: TObject);

begin

{ Load the bitmap from the resource file. The bitmap must be

specified in all CAPS! }

imgBitmap.Picture.Bitmap.LoadFromResourceName(hInstance, ‘CHEMICAL’);

end;

procedure TMainForm.btnClearClick(Sender: TObject);

begin

imgBitmap.Picture.Assign(nil); // Clear the image

end;

procedure TMainForm.btnChangeIconClick(Sender: TObject);

begin

{ Load the icon from the resource file. The icon must be

specified in all CAPS! }

Application.Icon.Handle := LoadIcon(hInstance, ‘SKYLINE’);

end;

procedure TMainForm.btnNewCursorClick(Sender: TObject);

begin

{ Assign the new cursor to the Screen’s Cursor array }

Screen.Cursors[crXHair] := LoadCursor(hInstance, ‘XHAIR’);

Screen.Cursor := crXHair; // Now change the cursor

end;

procedure TMainForm.btnOldCursorClick(Sender: TObject);

begin

// Change back to default cursor

Screen.Cursor := crDefault;

end;

procedure TMainForm.btnOldIconClick(Sender: TObject);

begin

{ Load the icon from the resource file. The icon must be

specified in all CAPS! }

Application.Icon.Handle := LoadIcon(hInstance, ‘DELPHI’);

end;

procedure TMainForm.btnAthenaClick(Sender: TObject);

begin

{ Load the bitmap from the resource file. The bitmap must be

specified in all CAPS! }

imgBitmap.Picture.Bitmap.LoadFromResourceName(hInstance, ‘ATHENA’);

end;

end.

Загрузить весь проект

{/codecitation}