问一个API函数(StretchBlt)的使用

GreenWaterBlueSky 2003-08-22 05:08:58
为什么我用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.
...全文
134 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
GreenWaterBlueSky 2003-08-22
  • 打赏
  • 举报
回复
多谢DWGZ()
DWGZ 2003-08-22
  • 打赏
  • 举报
回复
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 if Message.Msg = WM_SIZE then
begin
InvalidateRect(ClientHandle, nil, True);
Message.Result:=CallWindowProc(FPrevClientProc,ClientHandle,Message.Msg,Message.wParam,Message.lParam);
end
else Message.Result:=CallWindowProc(FPrevClientProc,ClientHandle,Message.Msg,Message.wParam,Message.lParam);
end;

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧