我列出我的程序
//MAINFORM.h
class TMainForm1 : public TForm
{
__published: // IDE-managed Components
protected:
private:
Graphics::TBitmap * BGBitmap;
TFarProc OldProc;
TFarProc NewProc;
void __fastcall ClientProc(TMessage &
Msg);
__fastcall ~TMainForm1();
void __fastcall WMEraseBkgnd(TWMEraseBkgnd &
Msg);
public: // User declarations
__fastcall TMainForm1(TComponent* Owner);
};
//MAINFORM.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm1 *MainForm1;
//---------------------------------------------------------------------------
__fastcall TMainForm1::TMainForm1(TComponent* Owner)
: TForm(Owner)
{
BGBitmap = new Graphics::TBitmap;
BGBitmap->LoadFromFile("mainform.bmg")
NewProc=MakeObjectInstance(ClientProc);
OldProc=(TFarProc)::SetWindowLong(Handle,GWL_WNDPROC,(LONG)NewProc);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm1::Button_EXITClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm1::ClientProc(TMessage &
Msg)
{
if (Msg.Msg==WM_ERASEBKGND)
{RECT r;
HDC hdc1,hdc;
hdc1=GetDC(ClientHandle);
::GetClientRect(ClientHandle, &r);
hdc = (HDC)Msg.WParam;
BitBlt(hdc,(r.right-BGBitmap->Width)/2,(r.bottom-BGBitmap->Height)/2, BGBitmap->Width, BGBitmap->Height,BGBitmap->Canvas->Handle, 0,0, SRCCOPY);
//如果用BitBle(HDC, ....)的话,BitBlt执行后,屏幕没变化,
//但如果改成BitBle(HDC1,...)的话,看到是写到屏幕了,
//但无论何种方式,退出过程后,窗口就恢复回原来form的底色
Msg.Result = true;
return;
}
Msg.Result = CallWindowProc((FARPROC)OldProc,ClientHandle,Msg.Msg,Msg.WParam,Msg.LParam);
}
__fastcall TMainForm1::~TMainForm1()
{
SetWindowLong(Handle,GWL_WNDPROC,(long)OldProc);
FreeObjectInstance(NewProc);
//删除位图。
delete BGBitmap;
}
void __fastcall TMainForm1::WMEraseBkgnd(TWMEraseBkgnd &
Msg)
{
Msg.Result = false;
//TODO: Add your source code here
}