在Delphi中用Loadcursor()得到的光标只有黑白两色,怎样在程序中得到彩色光标呢?
方法一 用Loadcursorfromfile()从外部调入图标作为光标 Loadcursorfromfile()函数可以读*.CUR,*.ICO,*.ANI为后缀的文件作为光标,其中ICO为彩色图标格式(可用Image Editor制作),ANI为动画光标格式。以下为打开一图标作为光标的演示程序段,当光标移动到测试区域内光标会变成选定的图案; {设:opendialog1:Topendialog;Bitbtn1:Tbitbtn} procedure TForm1.BitBtn1Click(Sender:TObject); var tt:pchar;size:integer;s:string; begin if opendialog1.Execute then begin size:=length(opendialog1.filename); getmem(tt,size); s:=opendialog1.filename; strpcopy(tt,s); screen.cursors[2]:=loadcursorfromfile(tt); bf.cursor:=2; freemem(tt,size); end; end; 方法二 从资源文件加载彩色光标 用方法一发送程序时必须包含*.CUR文件,因而从资源文件中加载彩色光标是更可行的方法。用图标存放彩色光标,使用时把图标存入临时文件,用Loadcursorfromfile()从临时文件读出彩色光标。 程序段: procedure ZloadfromResourse(screenindex:integer;name:Pchar); var td:ticon; begin try td:=ticon.Create; td.Handle:=LoadIcon(Hinstance,name); td.SaveToFile(′temp.cur′); screen.Cursors[screenindex]:=loadcursorfromfile(′temp.cur′); deletefile(′temp.cur′); finally td.free; end; end; 此程序把名字为name的图标变为序号为screenindex的光标; 例: ZloadfromResourse(2,′myicon′); Form1.cursor:=2; 注意:′myicon′这个图标一定要在资源文件中,否则会出现异常。
方法一 用Loadcursorfromfile()从外部调入图标作为光标 Loadcursorfromfile()函数可以读*.CUR,*.ICO,*.ANI为后缀的文件作为光标,其中ICO为彩色图标格式(可用Image Editor制作),ANI为动画光标格式。以下为打开一图标作为光标的演示程序段,当光标移动到测试区域内光标会变成选定的图案; {设:opendialog1:Topendialog;Bitbtn1:Tbitbtn} procedure TForm1.BitBtn1Click(Sender:TObject); var tt:pchar;size:integer;s:string; begin if opendialog1.Execute then begin size:=length(opendialog1.filename); getmem(tt,size); s:=opendialog1.filename; strpcopy(tt,s); screen.cursors[2]:=loadcursorfromfile(tt); bf.cursor:=2; freemem(tt,size); end; end; 方法二 从资源文件加载彩色光标 用方法一发送程序时必须包含*.CUR文件,因而从资源文件中加载彩色光标是更可行的方法。用图标存放彩色光标,使用时把图标存入临时文件,用Loadcursorfromfile()从临时文件读出彩色光标。 程序段: procedure ZloadfromResourse(screenindex:integer;name:Pchar); var td:ticon; begin try td:=ticon.Create; td.Handle:=LoadIcon(Hinstance,name); td.SaveToFile(′temp.cur′); screen.Cursors[screenindex]:=loadcursorfromfile(′temp.cur′); deletefile(′temp.cur′); finally td.free; end; end; 此程序把名字为name的图标变为序号为screenindex的光标; 例: ZloadfromResourse(2,′myicon′); Form1.cursor:=2; 注意:′myicon′这个图标一定要在资源文件中,否则会出现异常。
解决方案 »
- 推荐一本delphi网络开发好书,最好有电子的
- HWnd 是个什么东西啊(急!!!)
- ACCESS 事务处理 和表锁定的SQL语句
- 如何判断文件的总量
- 有TForm的初始化方法嗎?
- Express Quantnum Grid V3.22+Pardox 7的数据库,在Delphi 6.240里不能显示?
- delphi(9813117)
- 请问如何用adotable修改一条记录和删除一条记录呢
- 为什么我的dblookupcombox显示不出数据
- 我在学DELPHI的XML编程,请问少了MSXML2_TLB.DCU文件....
- Delphi报表不能正确释放内存SOS
- 我做的一个程序在delphi5.0下编译出来的可执行文件只有325KB,为什么在.delphi6.0下编译出来就有396KB之多?delphi6.0的编译系统是不是作了一个很大的改动啊?编译出来的exe文件是不是比以前的更优秀了?
- Stop On delphi
unit Unit1;interfaceuses
SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Image3: TImage;
procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image3Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
i:integer;
td:ticon;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Image2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
image2.Canvas.Draw(0,0,image1.picture.icon);
end;procedure TForm1.Image3Click(Sender: TObject);
begin
screen.Cursors[2]:=loadcursorfromfile('100.ico');
image3.Cursor:=2;
image2.Cursor:=2;
cursor:=2;
end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
tt:pchar;
size:integer;
s:string;
begin
// size:=15;
// getmem(tt,size);
// s:='g:\drog\100.ico';
// strpcopy(tt,s);
screen.Cursors[1]:=loadcursorfromfilea(pchar('100.ico'));
image1.Cursor:=1;
image2.Cursor:=1;
cursor:=1;
// freemem(tt,size);end;end.