如何在多文档程序的父窗口画图(100分)

  • 主题发起人 主题发起人 Jack.yang
  • 开始时间 开始时间
J

Jack.yang

Unregistered / Unconfirmed
GUEST, unregistred user!
我在写一个多文档程序时,想在父窗口显示一个图形,但放上的TImage控件就是不显示图形.我需要能在C++Build中能实现的代码.
 
FormCreate中加入:
Form1.Brush.Bitmap := Image1.Picture.Bitmap;
BCB应该类似吧。
 
其实只需要给你的Form加上一个 WM_EraseBKGnd消息处理,里面绘制背景图像即可
C++Build中不知是否可行;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FClientInstance,FPrevClientProc: TFarProc;
procedure ClientWndProc(Var Message: TMessage);
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ClientWndProc(var Message: TMessage);
var MyDC: hDC;
Ro,Co: Word;
begin
with Messagedo
begin
case Msg of
WM_ERASEBKGND: begin
MyDC := TWMEraseBkGnd(Message).DC;
for Ro := 0 to ClientHeight div Image1.Picture.Heightdo
for Co := 0 to ClientWidth Div Image1.Picture.Widthdo
BitBlt(MyDC, Co*Image1.Picture.Width,Ro*Image1.Picture.Height,
Image1.Picture.Width,Image1.Picture.Height,
Image1.Picture.Bitmap.Canvas.Handle,0,0,SRCCOPY);
Result := 1;
end;
else
Result := CallWindowProc(FPrevClientProc,ClientHandle,Msg,wParam,lParam);
end;
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC,LongInt(FClientInstance));
end;

end.
 
ZW84611的方法简单有效加80分,卡色的方法也可以加20分
 
后退
顶部