有段C++代码供你参考,在MDI背景上绘图片,写字。很容易能改成Pascal.
代码中用两个TImage控件分别存放背景图片和标题图片,放在MDI主窗体上。
//---------------------------------------------------------------------------
// 窗口背景
//---------------------------------------------------------------------------
void __fastcall TSemMainForm::CreateWnd()
{
// let the base class CreateWnd do what it needs to do to
// create a main window for the program.
TForm::CreateWnd();
// subclass the MDI client window so we can replace its default
// message handler with our own. MakeObjectInstance transposes
// the ClientProc function into a form that the API likes.
// SetWindowLong then subclass the MDI client (ClientHandle)
// using the return value from MakeObjectInstance.
ClientObjectInstance = MakeObjectInstance (ClientProc) ;
OriginalClientProc = (Pointer) SetWindowLong (ClientHandle,
GWL_WNDPROC,
(long) ClientObjectInstance);
}
//---------------------------------------------------------------------------
void __fastcall TSemMainForm::ClientProc (TMessage &Msg)
{
switch(Msg.Msg)
{
case WM_ERASEBKGND:
// intercept the message for painting the background and
// draw the background ourself
DrawClientWindow ((HDC) Msg.WParam) ;
Msg.Result = true;
return;
case WM_HSCROLL:
case WM_VSCROLL:
//scrolling the client area can goof up our drawing. if the user scrolls
//the client area, pass the message on to the original procedure and
//then request a complete repaint of the background.
Msg.Result = CallWindowProc ((FARPROC)OriginalClientProc, ClientHandle,
Msg.Msg, Msg.WParam, Msg.LParam);
InvalidateRect (ClientHandle, 0, true) ;
break ;
default:
// pass all other messages on to the original window procedure
// stored in OriginalClientProc
Msg.Result = CallWindowProc ((FARPROC)OriginalClientProc, ClientHandle,
Msg.Msg, Msg.WParam, Msg.LParam);
}
}
//---------------------------------------------------------------------------
void __fastcall TSemMainForm:
rawClientWindow (HDC &Hdc)
{
if( ClientHandle == 0 )
return;
TRect rect ; // calculate size of backgnd
::GetClientRect (ClientHandle, (RECT *) &rect) ;
// painting a shaded gradient is slow, and can cause flickering
// eliminate flicker by using memory bitmaps and BitBlit
Graphics::TBitmap *MemBitmap = new Graphics::TBitmap;
MemBitmap->Width = rect.Right - rect.Left;
MemBitmap->Height= rect.Bottom- rect.Top;
// Gradient fill background
// GradientFillRect(MemBitmap->Canvas, rect, clBlue, clBlack, fdTopToBottom, 255);
// 用图片填充背景
// imgBkGrd是TImage控件,存放背景图片
for( int x = 0; x < ClientWidth; x += imgBkGrd->Picture->Width )
for( int y = 0; y < ClientHeight; y += imgBkGrd->Picture->Height )
MemBitmap->Canvas->Draw( x, y, imgBkGrd->Picture->Graphic );
// 标题图片
// imgTitle是TImage控件,存放标题
MemBitmap->Canvas->Draw( 14, 20, imgTitle->Picture->Graphic );
MemBitmap->Canvas->Font->Name = "宋体";
MemBitmap->Canvas->Font->Size = 11;
MemBitmap->Canvas->Brush->Style = bsClear;
AnsiString str = String("授权用户:") + FUserOrgn;
int y = 24 + imgTitle->Picture->Graphic->Height;
MemBitmap->Canvas->Font->Color = TColor(0xC7B6A8);
MemBitmap->Canvas->TextOut( 17, y + 2, str );
MemBitmap->Canvas->Font->Color = cl3DDkShadow;
MemBitmap->Canvas->TextOut( 18, y, str );
MemBitmap->Canvas->Font->Color = clAqua;
MemBitmap->Canvas->TextOut( 20, y, str );
MemBitmap->Canvas->Font->Color = clBlue;
MemBitmap->Canvas->TextOut( 19, y, str );
// Use API BitBlt to copy pixels to the screen.
::BitBlt(Hdc,0,0,MemBitmap->Width, MemBitmap->Height,
MemBitmap->Canvas->Handle,0,0,SRCCOPY);
delete MemBitmap; // delete the temporary bitmap.
}
//---------------------------------------------------------------------------
void __fastcall TSemMainForm:
estroyWnd ()
{
SetWindowLong(ClientHandle, GWL_WNDPROC, (long) OriginalClientProc);
FreeObjectInstance(ClientObjectInstance);
TForm:
estroyWnd();
}
//---------------------------------------------------------------------------
void __fastcall TSemMainForm::WMEraseBkgnd(TWMEraseBkgnd &Msg)
{
// tell Windows to forget about the
Msg.Result = false; // background. MDI client will draw
} // it later
//---------------------------------------------------------------------------
头文件申明:
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)