在Form中使用image控件的问题!!
我的form的style设置为fsMDIForm,上面的image控件中的图片在运行时就显示不出来,请问怎么办??谢谢
[解决办法]
MDIForm是显示不了背景的,需要自己画。
.h file:
private:// User declarations
virtual void __fastcall CreateWnd();
virtual void __fastcall ClientProc(TMessage &msg);
virtual void __fastcall DrawClientWindow(HDC &dc);
virtual void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Msg);
Pointer Ocp;
Pointer Ccp;
.cpp file
void __fastcall TfrmMain::CreateWnd(void)
{
TForm::CreateWnd();
Ccp=MakeObjectInstance(ClientProc);
Ocp=(Pointer)SetWindowLong(ClientHandle,GWL_WNDPROC,(long)Ccp);
}
void __fastcall TfrmMain::ClientProc(TMessage &msg)
{
switch(msg.Msg)
{
case WM_ERASEBKGND:
DrawClientWindow((HDC)msg.WParam);
msg.Result=true;
return;
case WM_HSCROLL:
case WM_VSCROLL:
msg.Result=CallWindowProc((FARPROC)Ocp,ClientHandle,msg.Msg,msg.WParam,msg.LParam);
InvalidateRect(ClientHandle,0,true);
default:
msg.Result=CallWindowProc((FARPROC)Ocp,ClientHandle,msg.Msg,msg.WParam,msg.LParam);
}
}
void __fastcall TfrmMain::DrawClientWindow(HDC & Hdc)
{
TRect rect;
HDC dc;
dc=GetDC(frmMain-> Canvas-> Handle);
::GetClientRect(ClientHandle,(RECT *)&rect);
//Graphics::TBitmap *BGBitmap=new Graphics::TBitmap();
//BGBitmap-> LoadFromFile( ".\\back.bmp ");
Graphics::TBitmap *BGBitmap= Image2-> Picture-> Bitmap;
::GetClientRect(ClientHandle,(RECT *)&rect);
int left,top;
// 使用Windows API函数BitBlt
for (int i=0;i <ClientHeight/BGBitmap-> Height+1;i++)
for (int j=0;j <ClientWidth/BGBitmap-> Width+1;j++){
left=j*BGBitmap-> Width;
top=i*BGBitmap-> Height;
::BitBlt(Hdc,left,top,left+BGBitmap-> Width,top+BGBitmap-> Height,
BGBitmap-> Canvas-> Handle,0,0,SRCCOPY);
}
}