多线程 靠,在Delphi的Demo下不是有一个吗???????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //这是一个未完的程序,飞机开火是单独的一个线程完成的unit Fly;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls,shellapi, StdCtrls,mmsystem, Menus; procedure ThreadFire;stdcall;type TFlyer=Record //飞行器类 Speed:integer;//速度 Life:integer;//飞行器数量 Value:integer;//飞行器生命力 Score:Integer;//得分 Left:integer;//左右位置 Top:integer;//上下位置 Face:integer;//飞行器图像句柄 State:integer;//飞行器状态 0:未开始;1:正常;2:子弹发射中; ConFig:integer;//武器装备 KeyStack:string;//当前未释放的键end;type TForm1 = class(TForm) Image1: TImage; TimerSky: TTimer; MainMenu1: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; A1: TMenuItem; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; H1: TMenuItem; Label1: TLabel; Label2: TLabel; procedure TimerSkyTimer(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure N5Click(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } bmp,tmpBmp:Tbitmap; Flys:TFlyer; ThreadID: DWORD; public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure ThreadFire;stdcall;var Iwhite,itmp:Integer;begin with form1 do begin Iwhite:=CreatePen(PS_SOLID,0,RGB(255,255,255)); selectOBject(Canvas.handle,Iwhite); MoveToEx(Canvas.handle,flys.Left+6,flys.Top,nil); for itmp:=form1.flys.Top downto 0 do begin// bitblt(btmp.Canvas.handle,0,0,form1.Width,form1.Height,bmp.canvas.Handle ,0,0,SRCCOPY); LineTo(Canvas.handle,flys.Left+6,itmp); // bitblt(form1.Canvas.handle,0,0,form1.Width,form1.Height,btmp.canvas.Handle ,0,0,SRCCOPY); end; DeleteObject(Iwhite); end;end;procedure TForm1.TimerSkyTimer(Sender: TObject);begin if pos('32',flys.KeyStack)>0 then CreateThread(nil,0,@ThreadFire,nil,0,ThreadID); //空格 bitblt(tmpBmp.Canvas.handle,0,0,clientWidth,clientHeight,bmp.Canvas.handle,0,0,SRCCOPY); DrawIcon(tmpbmp.canvas.handle,flys.Left ,flys.Top,flys.Face ); bitblt(Canvas.handle,0,0,clientWidth,clientHeight,tmpbmp.Canvas.handle,0,0,SRCCOPY); bitblt(tmpBmp.Canvas.Handle,0,0,bmp.Width,2,bmp.Canvas.handle,0,bmp.Height-2,SRCCOPY); bitblt(bmp.Canvas.Handle,0,2,bmp.Width,bmp.Height,bmp.Canvas.handle,0,0,SRCCOPY); bitblt(bmp.Canvas.Handle,0,0,bmp.Width,2,TmpBmp.Canvas.handle,0,0,SRCCOPY);end;procedure TForm1.FormCreate(Sender: TObject);var i,j :integer; dct:Trect;begin playsound('bk.wav',0,SND_ASYNC+SND_Loop+SND_SYNC); cursor:=-3; bmp:=Tbitmap.Create ; tmpBmp:=Tbitmap.Create ; bmp.Width :=(screen.width div image1.Width+1) *image1.Width ; bmp.Height:=(screen.Height div image1.Height+1) *image1.Height ; TmpBmp.Width :=bmp.Width; TmpBmp.Height :=bmp.Height; bmp.Canvas.Brush.Bitmap := IMAGE1.Picture.Bitmap; For i := 0 To (screen.Width div IMAGE1.Width+1) do For j := 0 To (screen.Height div IMAGE1.Height+1) do dct:=rect(i*2,0,(i+1)*2,bmp.Height); bmp.Canvas.fillRect(Rect(0,0,i * IMAGE1.Width, j * IMAGE1.Height)); flys.Left:=(clientWidth-application.Icon.Width) div 2 ; Flys.Top :=clientHeight - application.Icon.Height ; flys.Face:=application.Icon.Handle; flys.Speed:=15; flys.State:=0;end;procedure TForm1.FormDestroy(Sender: TObject);begin bmp.Free; tmpbmp.Free;end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin//caption:=inttostr(key); if pos(inttostr(key),flys.KeyStack)=0 then flys.KeyStack:=flys.KeyStack+inttostr(key)+','; if pos('37',flys.KeyStack)>0 then if flys.Left>5 then flys.Left :=flys.Left-flys.Speed;//左 if pos('38',flys.KeyStack)>0 then if flys.Top >0 then flys.Top := flys.Top-flys.Speed;//上 if pos('39',flys.KeyStack)>0 then if flys.Left <clientwidth-32 then flys.Left :=flys.Left+flys.Speed; //右 if pos('40',flys.KeyStack)>0 then if flys.Top <clientheight-32 then flys.Top :=flys.Top +flys.Speed; //下end;procedure TForm1.N5Click(Sender: TObject);begin case TMenuItem(sender).tag of 1: begin flys.State:=1; timersky.Enabled :=true; playsound('start.wav',0,SND_SYNC); playsound('bk1.wav',0,SND_ASYNC+SND_Loop); n3.Enabled :=true; end; 2: begin timersky.Enabled :=not timersky.Enabled; if timersky.Enabled=true then n3.Caption:='暂停' else n3.Caption:='继续'; end; 3: begin PlaySound(nil,0,SND_PURGE); PostQuitMessage (0); end; 4:messagebox(handle,'光标键 飞行控制' + #13 + '空格键 常规武器','操作说明',mb_ok); 5:shellabout(handle,Pchar(caption),'RedBird Times',flys.Face); 6:ShellExecute(0, nil, 'mailto:[email protected]', nil, nil, SW_NORMAL); 7:ShellExecute(0, nil, 'http://rbsky.myetang.com', nil, nil, SW_NORMAL); end;end;procedure TForm1.FormResize(Sender: TObject);begin if flys.State <>0 then begin if flys.Left >clientwidth-32 then flys.Left :=clientwidth-32; if flys.Top >clientheight-32 then flys.Top :=clientheight-32; end;end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);var itmp:integer;begin itmp:=pos(inttostr(key),flys.KeyStack); if itmp>0 then flys.KeyStack:=copy(flys.KeyStack,1,itmp-1)+copy(flys.KeyStack,itmp+length(flys.keystack),255);end;end. <DelphiDir>\Demos\Threads\thrddemo.dpr__________________________________________________________________________http://i58.boy.net.cn/ (抱歉,未建好)邮件列表,大家互助, mailto:[email protected]http://cn.groups.yahoo.com/group/delphi_sky/或: http://agui.delphibbs.com/ 目标IP地址和目标PORT端口 dbexpsda -- dbExpress for SQL Server 4.20问题,知道的兄弟说一下 实现模糊查询时出错,提示无效字符 呕心沥血完成物业管理软件,寻求各种形式的合作。 关于DateTimePicker控件的使用问题? 哈哈,哈哈,高兴,散分,谁第一个进来就都给他!!!! 贴子回复次数大于跟给分次数 ,什么意思? 求30选7彩票对奖的算法 关于消息反应... 关于PARADOX的一个小菜问题! 怎么把自己编写的程序注册成系统服务?? 请帮我看看
unit Fly;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls,shellapi, StdCtrls,mmsystem, Menus;
procedure ThreadFire;stdcall;
type
TFlyer=Record //飞行器类
Speed:integer;//速度
Life:integer;//飞行器数量
Value:integer;//飞行器生命力
Score:Integer;//得分
Left:integer;//左右位置
Top:integer;//上下位置
Face:integer;//飞行器图像句柄
State:integer;//飞行器状态 0:未开始;1:正常;2:子弹发射中;
ConFig:integer;//武器装备
KeyStack:string;//当前未释放的键
end;type
TForm1 = class(TForm)
Image1: TImage;
TimerSky: TTimer;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
A1: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
H1: TMenuItem;
Label1: TLabel;
Label2: TLabel;
procedure TimerSkyTimer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure N5Click(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
bmp,tmpBmp:Tbitmap;
Flys:TFlyer;
ThreadID: DWORD;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure ThreadFire;stdcall;
var Iwhite,itmp:Integer;begin
with form1 do
begin
Iwhite:=CreatePen(PS_SOLID,0,RGB(255,255,255));
selectOBject(Canvas.handle,Iwhite); MoveToEx(Canvas.handle,flys.Left+6,flys.Top,nil); for itmp:=form1.flys.Top downto 0 do
begin
// bitblt(btmp.Canvas.handle,0,0,form1.Width,form1.Height,bmp.canvas.Handle ,0,0,SRCCOPY);
LineTo(Canvas.handle,flys.Left+6,itmp);
// bitblt(form1.Canvas.handle,0,0,form1.Width,form1.Height,btmp.canvas.Handle ,0,0,SRCCOPY);
end;
DeleteObject(Iwhite);
end;
end;procedure TForm1.TimerSkyTimer(Sender: TObject);
begin
if pos('32',flys.KeyStack)>0 then CreateThread(nil,0,@ThreadFire,nil,0,ThreadID); //空格
bitblt(tmpBmp.Canvas.handle,0,0,clientWidth,clientHeight,bmp.Canvas.handle,0,0,SRCCOPY);
DrawIcon(tmpbmp.canvas.handle,flys.Left ,flys.Top,flys.Face );
bitblt(Canvas.handle,0,0,clientWidth,clientHeight,tmpbmp.Canvas.handle,0,0,SRCCOPY);
bitblt(tmpBmp.Canvas.Handle,0,0,bmp.Width,2,bmp.Canvas.handle,0,bmp.Height-2,SRCCOPY);
bitblt(bmp.Canvas.Handle,0,2,bmp.Width,bmp.Height,bmp.Canvas.handle,0,0,SRCCOPY);
bitblt(bmp.Canvas.Handle,0,0,bmp.Width,2,TmpBmp.Canvas.handle,0,0,SRCCOPY);
end;procedure TForm1.FormCreate(Sender: TObject);
var i,j :integer;
dct:Trect;
begin
playsound('bk.wav',0,SND_ASYNC+SND_Loop+SND_SYNC);
cursor:=-3;
bmp:=Tbitmap.Create ;
tmpBmp:=Tbitmap.Create ;
bmp.Width :=(screen.width div image1.Width+1) *image1.Width ;
bmp.Height:=(screen.Height div image1.Height+1) *image1.Height ;
TmpBmp.Width :=bmp.Width;
TmpBmp.Height :=bmp.Height;
bmp.Canvas.Brush.Bitmap := IMAGE1.Picture.Bitmap;
For i := 0 To (screen.Width div IMAGE1.Width+1) do
For j := 0 To (screen.Height div IMAGE1.Height+1) do
dct:=rect(i*2,0,(i+1)*2,bmp.Height);
bmp.Canvas.fillRect(Rect(0,0,i * IMAGE1.Width, j * IMAGE1.Height));
flys.Left:=(clientWidth-application.Icon.Width) div 2 ;
Flys.Top :=clientHeight - application.Icon.Height ;
flys.Face:=application.Icon.Handle;
flys.Speed:=15;
flys.State:=0;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
bmp.Free;
tmpbmp.Free;
end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);begin
//caption:=inttostr(key);
if pos(inttostr(key),flys.KeyStack)=0 then flys.KeyStack:=flys.KeyStack+inttostr(key)+',';
if pos('37',flys.KeyStack)>0 then if flys.Left>5 then flys.Left :=flys.Left-flys.Speed;//左
if pos('38',flys.KeyStack)>0 then if flys.Top >0 then flys.Top := flys.Top-flys.Speed;//上
if pos('39',flys.KeyStack)>0 then if flys.Left <clientwidth-32 then flys.Left :=flys.Left+flys.Speed; //右
if pos('40',flys.KeyStack)>0 then if flys.Top <clientheight-32 then flys.Top :=flys.Top +flys.Speed; //下
end;
procedure TForm1.N5Click(Sender: TObject);
begin
case TMenuItem(sender).tag of
1:
begin
flys.State:=1;
timersky.Enabled :=true;
playsound('start.wav',0,SND_SYNC);
playsound('bk1.wav',0,SND_ASYNC+SND_Loop);
n3.Enabled :=true;
end;
2:
begin
timersky.Enabled :=not timersky.Enabled;
if timersky.Enabled=true then n3.Caption:='暂停' else n3.Caption:='继续';
end;
3:
begin
PlaySound(nil,0,SND_PURGE);
PostQuitMessage (0);
end;
4:messagebox(handle,'光标键 飞行控制' + #13 + '空格键 常规武器','操作说明',mb_ok);
5:shellabout(handle,Pchar(caption),'RedBird Times',flys.Face);
6:ShellExecute(0, nil, 'mailto:[email protected]', nil, nil, SW_NORMAL);
7:ShellExecute(0, nil, 'http://rbsky.myetang.com', nil, nil, SW_NORMAL);
end;
end;procedure TForm1.FormResize(Sender: TObject);
begin
if flys.State <>0 then
begin
if flys.Left >clientwidth-32 then flys.Left :=clientwidth-32;
if flys.Top >clientheight-32 then flys.Top :=clientheight-32;
end;
end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var itmp:integer;
begin
itmp:=pos(inttostr(key),flys.KeyStack);
if itmp>0 then flys.KeyStack:=copy(flys.KeyStack,1,itmp-1)+copy(flys.KeyStack,itmp+length(flys.keystack),255);
end;end.
http://i58.boy.net.cn/ (抱歉,未建好)
邮件列表,大家互助, mailto:[email protected]
http://cn.groups.yahoo.com/group/delphi_sky/
或: http://agui.delphibbs.com/