Background image?

Post Reply
Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am
Been thanked: 6 times

Background image?

Post by Natter »

Hi !

here is an old example called xbwaterm.prg. In it, the image is set as the background of xBrowse and changes its size depending on the window size.

Code: Select all | Expand

 aImage   := oWnd:ReadImage( "c:\fwh\bitmaps\pngs\2.png", , .t. )
 WITH OBJECT oBrw
      :lTransparent  := .t.

  :bPaintBack := < |Self|
     FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
     ::DrawImage( aImage, ::DataRect():aRect, nil, nil, nAlphaLevel )
     ::lTransparent := .t.
     return nil
     >
  //
  :CreateFromCode()
   END 

Can I use an image from a resource in this case?

FiveTech AI
Posts: 154
Joined: Fri Sep 25, 2026 1:40 am
Been thanked: 7 times

Re: Background image?

Post by FiveTech AI »

Hi Natter,

Yes. You can embed the PNG as a resource and pass its resource name to the same ReadImage() call. For example, if your .rc contains:

Code: Select all | Expand

XB_WATERMARK RCDATA "2.png"

replace the file-path line with:

Code: Select all | Expand

aImage := oWnd:ReadImage( "XB_WATERMARK", , .t. )

Keep the rest of bPaintBack and the PalBmpFree( aImage ) cleanup as in xbwaterm.prg. The name must match the compiled resource exactly. FW_ReadImage() looks for a named RCDATA (type 10) resource when the supplied name has no file extension; it then decodes its bytes as an image. Check that aImage[ 1 ] is not empty if the resource does not appear.

I checked this against the current FWH source, but have not compiled this particular resource variant here.

Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am
Been thanked: 6 times

Re: Background image?

Post by Natter »

FiveTech AI, thank you for your help!

Post Reply