Board index » cppbuilder » Background image in normal App (no MDI)

Background image in normal App (no MDI)

For avoiding flickering on painting Images, I have written an own
WndProc:

void __fastcall TForm1::OwnWndProc(TMessage &Msg)
{
  switch (Msg.Msg) {
    case WM_ERASEBKGND:
    {
      HDC dc = (HDC)Msg.WParam;
      ::BitBlt(dc, 0, 0,
               BackgroundBitmap->Width, BackgroundBitmap->Height,
               BackgroundBitmap->Handle, 0, 0, SRCCOPY);
      Msg.Result = 0;
      return;
    }
  ...

Quote
}

Why does 'BitBlt' only work in MDI-Apps and not in normal Apps? How can
I correct it?

Thanks
Claudio

 

Re:Background image in normal App (no MDI)


Hi Claudio,

Quote
>       ::BitBlt(dc, 0, 0,
>                BackgroundBitmap->Width, BackgroundBitmap->Height,
>                BackgroundBitmap->Handle, 0, 0, SRCCOPY);

BitBlt's hdcSrc (sixth) parameter requires a handle to a device context.  You're
passing a handle to a BITMAP.  Trye the following...

::BitBlt(dc, 0, 0,
         BackgroundBitmap->Width, BackgroundBitmap->Height,
         BackgroundBitmap->Canvas->Handle,  // <---
         0, 0,
         SRCCOPY);

Good luck.

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Re:Background image in normal App (no MDI)


Hi Damon

Thanks for your tip. Now it works for MDIForms, but not for normal
Applications! Do you have any suggestions?

Thanks
Claudio

Quote
Damon Chandler wrote:

> Hi Claudio,
> >       ::BitBlt(dc, 0, 0,
> >                BackgroundBitmap->Width, BackgroundBitmap->Height,
> >                BackgroundBitmap->Handle, 0, 0, SRCCOPY);

> BitBlt's hdcSrc (sixth) parameter requires a handle to a device context.  You're
> passing a handle to a BITMAP.  Trye the following...

> ::BitBlt(dc, 0, 0,
>          BackgroundBitmap->Width, BackgroundBitmap->Height,
>          BackgroundBitmap->Canvas->Handle,  // <---
>          0, 0,
>          SRCCOPY);

> Good luck.

> --------------------------------------
> Damon Chandler

> http://bcbcaq.freeservers.com
> Answers to <Commonly Asked Questions>
> 52064929

Re:Background image in normal App (no MDI)


Hi Claudio,

Quote
> Thanks for your tip. Now it works for MDIForms, but not for normal
> Applications! Do you have any suggestions?

Here's a simple example...

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    Bitmap = new Graphics::TBitmap();
    Bitmap->LoadFromFile("C:\\Windows\\Desktop\\SomeBitmap.bmp");

Quote
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
    delete Bitmap;      

Quote
}

void __fastcall TForm1::FormPaint(TObject *Sender)
{
    BitBlt(Canvas->Handle, 0, 0,
           Bitmap->Width, Bitmap->Height,
           Bitmap->Canvas->Handle, 0, 0,
           SRCCOPY);            

Quote
}

Alternatively, why not just drop a TImage on your Form at design time, then load
the TImage with your Bitmap?

Also, ensure that you don't have another windowed control (such as a TPanel)
occupying the client are of your Form.  In such case, the image will not show
through the Windowed control, you will have to draw to it directly.

Good luck!

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Other Threads