Board index » cppbuilder » MDI-Background and Bitmap::SaveToFile-Problem

MDI-Background and Bitmap::SaveToFile-Problem

Hi,
I've two problems to solve:
1) In my app I'm storing many bitmaps in one file. To achieve this I'm
storing them using TBitmap::SaveToStream(...). Everything works fine,
except for bitmaps with color-depths >8bpp. When storing a file with a
color depth higher than 8bpp, the file is reduced by 2 byte in size!! I
found out that 2 zeroes at the end of the file are deleted by
SaveToStream(...). Seams really strange to me!! Any suggestions??

2) I'd like to draw some background bitmap on a MDI-parent-form (the
main form, which is present without any mdi-children) instead of the
gray background. I've nothing found til now on that topic. I'd like to
do tiled background as well as stretched display of a bitmap as
background.

Thanks alot for any help
Michael Liedlgruber

 

Re:MDI-Background and Bitmap::SaveToFile-Problem


Hi Michael
I can't help you with the first question, but question 2 I can. This will do
a tiled background.

First place TImage on the form and load your desired bitmap into it and size
it accordingly.
Then place these three lines in the private: section of your main form class
definition in the header file:

    TFarProc ClientInstance;
    TFarProc OldClientWindowProc;
    void __fastcall MDIClientWndProc(TMessage &Message);

Add these three lines to the forms constructor:

    ClientInstance = MakeObjectInstance(MDIClientWndProc);
    OldClientWindowProc = (void *)(GetWindowLong(ClientHandle,
GWL_WNDPROC));
    SetWindowLong(ClientHandle, GWL_WNDPROC, (LONG)(ClientInstance));

and add this function:

void __fastcall TForm1::MDIClientWndProc(TMessage &Message)
{
    if (Message.Msg == WM_ERASEBKGND)
      {
        Message.Result = 0;
        HDC DC = (HDC)Message.WParam;
        int W = Image1->Width;
        int H = Image1->Height;
        int Rows = (ClientHeight / Image1->Height)+1;
        int Colms = (ClientWidth / Image1->Width)+1;
        for (int Row=0; Row<Rows; Row++)
          {
            for (int Colm=0; Colm<Colms; Colm++)
              {
                BitBlt(DC, Colm*W, Row*H, W, H, Image1->Canvas->Handle, 0,
0, SRCCOPY);
              }
          }
      }
    else Message.Result = CallWindowProc((FARPROC)OldClientWindowProc,
              ClientHandle, Message.Msg, Message.WParam, Message.LParam);

Quote
}

Hope this helps.

Cliff

Quote
Michael Liedlgruber <hex...@aon.at> wrote in message

news:3A5B9A59.55FD6660@aon.at...
Quote
> Hi,
> I've two problems to solve:
> 1) In my app I'm storing many bitmaps in one file. To achieve this I'm
> storing them using TBitmap::SaveToStream(...). Everything works fine,
> except for bitmaps with color-depths >8bpp. When storing a file with a
> color depth higher than 8bpp, the file is reduced by 2 byte in size!! I
> found out that 2 zeroes at the end of the file are deleted by
> SaveToStream(...). Seams really strange to me!! Any suggestions??

> 2) I'd like to draw some background bitmap on a MDI-parent-form (the
> main form, which is present without any mdi-children) instead of the
> gray background. I've nothing found til now on that topic. I'd like to
> do tiled background as well as stretched display of a bitmap as
> background.

> Thanks alot for any help
> Michael Liedlgruber

Other Threads