在Delphi中用Loadcursor()得到的光標(biāo)只有黑白兩色,怎樣在程序中得到彩色光標(biāo)呢?筆者嘗試制作了以下程序: 方法一 用Loadcursorfromfile()從外部調(diào)入圖標(biāo)作為光標(biāo) Loadcursorfromfile()函數(shù)可以讀*CUR,*ICO,*ANI為后綴的文件作為光標(biāo),其中ICO為彩色圖標(biāo)格式(可用Image Editor制作),ANI為動(dòng)畫光標(biāo)格式。以下為打開一圖標(biāo)作為光標(biāo)的演示程序段,當(dāng)光標(biāo)移動(dòng)到測(cè)試區(qū)域內(nèi)光標(biāo)會(huì)變成選定的圖案; {設(shè):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; 方法二 從資源文件加載彩色光標(biāo) 用方法一發(fā)送程序時(shí)必須包含*CUR文件,因而從資源文件中加載彩色光標(biāo)是更可行的方法。用圖標(biāo)存放彩色光標(biāo),使用時(shí)把圖標(biāo)存入臨時(shí)文件,用Loadcursorfromfile()從臨時(shí)文件讀出彩色光標(biāo)。 程序段: 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的圖標(biāo)變?yōu)樾蛱?hào)為screenindex的光標(biāo); 例: ZloadfromResourse(2,′myicon′); Form1.cursor:=2; 注意:′myicon′這個(gè)圖標(biāo)一定要在資源文件中,否則會(huì)出現(xiàn)異常。
|
溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!