问一个API函数(StretchBlt)的使用
为什么我用StretchBlt函数时,当图形大小改变时,它不是按比例拉伸,而是错位了;
代码如下:其中Form1为MDI中的父窗体,Form2为子窗体,并且动态生成;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
MainMenu1: TMainMenu;
new1: TMenuItem;
procedure new1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FClientInstance,FPrevClientProc:TFarProc;
procedure ClientWndProc(Var Message:TMessage);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.ClientWndProc(var Message: TMessage);
var
MyDC:hDC;
begin
if Message.Msg=WM_ERASEBKGND then
begin
MyDC:=TWMERASEBKGND(Message).DC;
StretchBlt(MyDC,0,0,ClientWidth,ClientHeight,Image1.Picture.Bitmap.Canvas.Handle,0,0,Image1.Picture.Width,Image1.Picture.Height,SRCCOPY);
Message.result:=1;
end else Message.Result:=CallWindowProc(FPrevClientProc,ClientHandle,Message.Msg,Message.wParam,Message.lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
end;
procedure TForm1.new1Click(Sender: TObject);
begin
form2:=Tform2.Create(self)
end;
end.