소스를 올립니다.
일단이미지를 불러와서 화면에 글씨를 뿌린다음 ...
마우스 MOVE 이벤트로 드래그합니다.
이때 화면이 깜박거려서 신경이 쓰입니다. 이깜박거림을 해제
시킬려고 WMEraseBkgnd를 처음 써보는데 잘안돼서 올립니다
소스를 올리니 여러고수님들의 지도부탁드립니다.
-소스-
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DXSprite, DXInput, DIB, DXDraws, Menus, ExtDlgs, ExtCtrls, ImgList;
type
MapSize = record
A : longint;
end;
TMyComponent = class(Timage) //깜박임처리를 위하여 ....
protected
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
end;
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
N10: TMenuItem;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
ImageList1: TImageList;
Image1: TImage;
Image2: TImage;
Image3: TImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure N3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
Map : array[0..199,0..14] of Mapsize; public
{ Public declarations }
end;
var
msX,msY : integer;
Form1: TForm1;
implementation
{$R *.DFM}
{===============================================================================}
procedure TForm1.N3Click(Sender: TObject);
{-------------------------------------------------------------------------------}
var
PathName :string;
FileName :string;
bmp : TBitmap;
i,j :integer;
begin
if OpenPictureDialog1.execute then
begin
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
Image1.Canvas.Font.Color :=clwhite;
Image1.Canvas.Font.Size := 15;
Image1.Canvas.Brush.Style :=bsClear;
for i:= 0 to 199 do
begin
for j:= 0 to 14 do
begin
Image1.Canvas.TextOut(i*32,j*32,InttoStr(map[i,j].A));
end;
end;
end;
{===============================================================================}
procedure TForm1.FormCreate(Sender: TObject);
{-------------------------------------------------------------------------------}
var
i,j,k : integer;
begin
for i:= 0 to 199 do
begin
for j:= 0 to 14 do
begin
Map[i,j].A :=0;
end;
end;
end;
{===============================================================================}
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
{-------------------------------------------------------------------------------}
begin
MsX := X;
msY := Y;
end;
{===============================================================================}
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
{-------------------------------------------------------------------------------}
var
R :Trect;
begin
r.Left := msx;
r.Top := msY;
r.Bottom := Y;
r.Right := X;
Canvas.Brush.Style :=bsClear;
Canvas.Rectangle(msX,msY,X,Y);
end;
{===============================================================================}
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
{-------------------------------------------------------------------------------}
var
r : TRect;
begin
if shift = [ssLeft] then //Mouse left button
begin
r.Left := msx;
r.Top := msY;
r.Bottom := Y;
r.Right := X;
Canvas.Brush.Style :=bsClear;
Refresh;
Canvas.Rectangle(msX,msY,X,Y);
end;
end;
{==============================================================================}
procedure TMyComponent.WMEraseBkgnd(var Message: TWMEraseBkgnd);
{------------------------------------------------------------------------------}
begin
Message.Result := 1; //이부분에서 깜빡거림이 없어져야 하는디....
end;
end.
이때 그림이 무지하게 깜박거린다는 말씀이것 같은데요
깜박임을 방지하기 위해 델파이의 폼에는 매우 기특한 옵션이 있답니다.
TWinControl에서 상속받은 DoubleBuffered 라는 부울리언 속성인데요 이것을 true로 하면 깜박임이 없어집니다.
폼위에 그려지는 내용을 더블버퍼링하는 것이지요 스프라이트 에니메이션에서 사용하는 그 더블버퍼말이지요
FormCreate 이벤트에
DoubleBuffered := true;
이렇게 넣어 보시죠
델초보 wrote:
> 소스를 올립니다.
> 일단이미지를 불러와서 화면에 글씨를 뿌린다음 ...
> 마우스 MOVE 이벤트로 드래그합니다.
> 이때 화면이 깜박거려서 신경이 쓰입니다. 이깜박거림을 해제
> 시킬려고 WMEraseBkgnd를 처음 써보는데 잘안돼서 올립니다
> 소스를 올리니 여러고수님들의 지도부탁드립니다.
>
> -소스-
>
> interface
>
> uses
> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
> DXSprite, DXInput, DIB, DXDraws, Menus, ExtDlgs, ExtCtrls, ImgList;
>
> type
> MapSize = record
> A : longint;
> end;
>
> TMyComponent = class(Timage) //깜박임처리를 위하여 ....
> protected
> procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
> end;
>
> TForm1 = class(TForm)
> MainMenu1: TMainMenu;
> N1: TMenuItem;
> N2: TMenuItem;
> N3: TMenuItem;
> N4: TMenuItem;
> N5: TMenuItem;
> N6: TMenuItem;
> N7: TMenuItem;
> N8: TMenuItem;
> N9: TMenuItem;
> N10: TMenuItem;
> N11: TMenuItem;
> N12: TMenuItem;
> N13: TMenuItem;
> N14: TMenuItem;
> ImageList1: TImageList;
> Image1: TImage;
> Image2: TImage;
> Image3: TImage;
> OpenPictureDialog1: TOpenPictureDialog;
>
> procedure N3Click(Sender: TObject);
> procedure FormCreate(Sender: TObject);
> procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
> Shift: TShiftState; X, Y: Integer);
> procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
> Shift: TShiftState; X, Y: Integer);
> procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
> Y: Integer);
>
> private
> { Private declarations }
> Map : array[0..199,0..14] of Mapsize; public
> { Public declarations }
> end;
>
>
> var
> msX,msY : integer;
>
> Form1: TForm1;
>
> implementation
>
> {$R *.DFM}
>
> {===============================================================================}
> procedure TForm1.N3Click(Sender: TObject);
> {-------------------------------------------------------------------------------}
> var
> PathName :string;
> FileName :string;
> bmp : TBitmap;
> i,j :integer;
>
> begin
> if OpenPictureDialog1.execute then
> begin
> Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
> end;
> Image1.Canvas.Font.Color :=clwhite;
> Image1.Canvas.Font.Size := 15;
> Image1.Canvas.Brush.Style :=bsClear;
>
> for i:= 0 to 199 do
> begin
> for j:= 0 to 14 do
> begin
> Image1.Canvas.TextOut(i*32,j*32,InttoStr(map[i,j].A));
> end;
> end;
>
> end;
> {===============================================================================}
> procedure TForm1.FormCreate(Sender: TObject);
> {-------------------------------------------------------------------------------}
> var
> i,j,k : integer;
> begin
>
> for i:= 0 to 199 do
> begin
> for j:= 0 to 14 do
> begin
> Map[i,j].A :=0;
> end;
> end;
>
> end;
> {===============================================================================}
> procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
> Shift: TShiftState; X, Y: Integer);
> {-------------------------------------------------------------------------------}
> begin
> MsX := X;
> msY := Y;
> end;
> {===============================================================================}
> procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
> Shift: TShiftState; X, Y: Integer);
> {-------------------------------------------------------------------------------}
> var
> R :Trect;
> begin
> r.Left := msx;
> r.Top := msY;
> r.Bottom := Y;
> r.Right := X;
> Canvas.Brush.Style :=bsClear;
> Canvas.Rectangle(msX,msY,X,Y);
> end;
>
> {===============================================================================}
> procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
> Y: Integer);
> {-------------------------------------------------------------------------------}
> var
> r : TRect;
>
> begin
>
> if shift = [ssLeft] then //Mouse left button
> begin
> r.Left := msx;
> r.Top := msY;
> r.Bottom := Y;
> r.Right := X;
> Canvas.Brush.Style :=bsClear;
> Refresh;
> Canvas.Rectangle(msX,msY,X,Y);
> end;
> end;
> {==============================================================================}
> procedure TMyComponent.WMEraseBkgnd(var Message: TWMEraseBkgnd);
> {------------------------------------------------------------------------------}
> begin
> Message.Result := 1; //이부분에서 깜빡거림이 없어져야 하는디....
> end;
>
>
> end.
>
>
>