 |
操作系统: Windows98
编程工具: Delphi
问题: 在编写MDI程序时,如何在MDI母窗口中使用背景图片,我在MDI母窗口的ONPAINT事件中已经写了相关画背景图的语句,但没有作用,不知何故?
水平: 中级(韩冰)
|
| |
|
 |
应该响应WM_ERASEBKGND消息。
假设你的Form叫MainForm,其中有一个Image1控件,绘制的背景图片包括在这个控件中。
先在窗体定义中加入如下变量:
FClientInstance : TFarProc;
FPrevClientProc : TFarProc;
procedure ClientWndProc(var Message: TMessage);
然后在implementation部分加上:
procedure TMainForm.ClientWndProc(var Message: TMessage);
var
Dc : hDC;
Row : Integer;
Col : Integer;
bmp: TBitmap;
begin
with Message do
case Msg of
WM_ERASEBKGND:
begin
Dc := TWMEraseBkGnd(Message).Dc;
bmp := TBitmap.Create;
bmp.Assign(Image1.Picture.Graphic);
for Row := 0 to ClientHeight div bmp.Height do
for Col := 0 to ClientWidth div bmp.Width do
BitBlt(Dc,
Col * bmp.Width,
Row * bmp.Height,
bmp.Width,
bmp.Height,
bmp.Canvas.Handle,
0,
0,
SRCCOPY);
Result := 1;
bmp.Free;
end;
else
Result := CallWindowProc(FPrevClientProc,
ClientHandle,
Msg,
wParam,
lParam);
end;
end;
在OnCreate事件加入:
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,
GWL_WNDPROC));
SetWindowLong(ClientHandle,
GWL_WNDPROC, LongInt(FClientInstance));
OnCreate的目的是让Windows把窗口的所有消息发送到ClientWndProc函数。ClientWndProc函数中,在收到WM_ERASEBKGND消息后,在窗口上使用BitBlt复制指定图片。
这里是调试好的程序 q3730.zip。
相关问题:
QA000268 "在MDI父窗口可以增加背景吗"
QA000984 "如何在MDI主框架窗口的客户区中加入背景"
QA000181 "如何在PB的窗口中加入背景图片"
ymkj的意见:
在MDIForm上添加一个Image1控件,绘制的背景图片包括在这个控件中。
procedure TForm1.FormCreate(Sender: TObject);
begin
self.Brush.Bitmap := Image1.Picture.Bitmap;
end;
主持人注:在我们的测试中,某些图显示不正常。
此问题由李海回答。
附加关键字:编程, 源程序, programming, source code, Delphi, VCL, Borland, 窗体与菜单, form, window, tform。
|
| |
|
| |
|
| |
|
|