核心思想:由于Windows窗体每次城市重绘其窗体配景,所以我们可以通过拦截窗体重绘配景的动静(WM_ERASEBKGND),,并自界说要领来实现重绘窗体配景。通过TImage组件也可以实现,但是重写WM_ERASEBKGND动静的效率更高一些,所以还是保举使用这种要领。
(2)声明重绘配景动静响应函数
void fastcall OnWMEraseBkgnd(TWMEraseBkgnd& Msg);
(3)添加动静映射
BEGIN_MESSAGE_MAP
//拦截重画配景的事件
MESSAGE_HANDLER(WM_ERASEBKGND,TWMEraseBkgnd,OnWMEraseBkgnd);
END_MESSAGE_MAP(TForm);
(4)编写自绘配景动静响应函数的代码
void fastcall TFormMain::OnWMEraseBkgnd(TWMEraseBkgnd& Msg)
{
//重画配景
TCanvas* canvas = new TCanvas;
canvas->Handle = Msg.DC;
int cx = ClientWidth/bmpFormBK->Width + 1;
int cy = ClientHeight/bmpFormBK->Height + 1;
for (int i=0; i<cy; i++)
for (int j=0; j<cx; j++)
{
canvas->Draw(j*bmpFormBK->Width, i*bmpFormBK->Height,bmpFormBK); Msg.Result = true;
}
delete canvas;
}
窗体配景的绘制(Windows窗体每次城市重绘其窗体配景,所以我们可以通过拦截窗体重绘配景的动静(WM_ERASEBKGND),并自界说要领来实现重绘窗体配景)
标签:
原文地点:https://www.cnblogs.com/findumars/p/8447818.html