if (x<0) then dx:= 1;
if (dx>0) then
dx:=TrackBar1.Position
else
dx:=-TrackBar1.Position;
x:=x+dx;
SetWindowPos(wnd,0,x,0,0,0,SWP_NOSIZE );
end;
7. “Button1” tugmachasining dasturlash maydonchasiga quyidagi dasturni kiritamiz:
begin
if f then
begin
Timer1.Enabled := true;
f:=false;
button1.Caption := 'Start';
end
else
begin
Timer1.Enabled := false;
f:=true;
button1.Caption := 'Stop';
end;
end;
8. “F9” tugmasini tanlaymiz.
Dastur kodi va oynaning umumiy ko‘rinishini keltiramiz:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
Timer1: TTimer;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x,dx: integer;
wnd: Hwnd;
f: Boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if f then
begin
Timer1.Enabled := true;
f:=false;
button1.Caption := 'Start';
end
else
begin
Timer1.Enabled := false;
f:=true;
button1.Caption := 'Stop';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
wnd:=FindWindow('Shell_TrayWnd',nil);
wnd:=FindWindowEx(wnd,0,'Button',nil);
x:=0;
dx:=10;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (x>Screen.Width ) then dx:= - 1;
if (x<0) then dx:= 1;
if (dx>0) then
dx:=TrackBar1.Position
else
dx:=-TrackBar1.Position;
x:=x+dx;
SetWindowPos(wnd,0,x,0,0,0,SWP_NOSIZE );
end;
end.
Izoh: Hosil bo‘lgan oynada agar siz “Start” tugmachasini tanlasangiz pusk tugmachasi chapdan o‘nga qarab harakatlanadi.
3-masala. Pusk tugmachasini ochish.
Bu masalani yechishimiz uchun quyidagi bosqichlarni amalga oshiramiz:
1. Standart komponentalar palitrasidan “Button1” tugmachasini hosil qilamiz.
2.“Button1” tugmachasining dasturlash maydonchasiga quyidagi dasturni kiritamiz:
begin
SendMessage(Handle,WM_SYSCOMMAND,SC_TASKLIST,0);
end;
3. “F9” tugmasini tanlaymiz.
Dastur kodi va oynaning umumiy ko‘rinishini keltiramiz:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(Tform)
Button1: Tbutton;
procedure Button1Click(Sender: Tobject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: Tform1;
implementation
{$R *.dfm}
procedure Tform1.Button1Click(Sender: Tobject);
begin
Do'stlaringiz bilan baham: |