为什么我用StretchBlt函数时,当图形大小改变时,它不是按比例拉伸,而是错位了;
代码如下:其中Form1为MDI中的父窗体,Form2为子窗体,并且动态生成;
unit Unit1;interfaceuses
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;implementationuses 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.
代码如下:其中Form1为MDI中的父窗体,Form2为子窗体,并且动态生成;
unit Unit1;interfaceuses
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;implementationuses 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.
解决方案 »
- 谁能帮我完全中山大学SocKet编程初级代码
- 谁能教我用delphi6做b/s模式的系统,我可以付钱!
- 怎樣在查詢結果中加入子序號 ?
- 关于用DELPHI来来连接安捷伦表(agilent)测量数据的问题
- class function 什么意思啊??100分相送
- 我的一个用于计算的BUTTON.ONCLICK事件里有1300条语句,每次点击它计算时,第一次计算的结果根本就不对,只有再次点击它一次,结果才计算
- data module 的问题。
- 如何让两个窗体就象一个窗体一样,一个移动另一个也跟着移动
- 50分求如何在DBGridEh做出“速达3000pro”的“采购订单”单据中的“金额”栏有分角元等细线?
- 如何实现任意文件的复制?
- 朋友,知道提了问题却没人能够回答是一种什么感觉么?。。。那是一种。。。
- TstoreProc的奇怪问题。
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;