Remove Back bitmap

Started by Douglas McDonald, March 29, 2011, 05:50:15 PM

Previous topic - Next topic

Douglas McDonald

If I add a bitmap(.bmp) to a form using the FF3 properties (BackBitmap) how can I remove it in code? I don't see any functions to do that.

Thanks
Doug
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

Paul Squires

To do it via code you need to modify the window class that is created when the Form is created. You delete the existing background handle for that class and then assign a new one. You then need to repaint the Form in order to show the new background color.

Here is some code:


'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long

   ' Remove the picture from the background by modifying the background
   ' element of the window class created for this Form. Need to create
   ' a new background brush otherwise the background will be black.
   
   Local hOldBrush As Dword
   
   ' The SetClassLong function returns the existing 32-bit value for the
   ' background brush.
   hOldBrush = SetClassLong( hWndForm, %GCL_HBRBACKGROUND, ByVal GetSysColorBrush(%COLOR_BTNFACE) )
   
   ' Force a repaint of the background
   InvalidateRect hWndForm, ByVal %Null, %TRUE
   UpdateWindow hWndForm
   
   ' Delete the old brush to save us from a GDI leak
   DeleteObject hOldBrush
   
End Function

Paul Squires
PlanetSquires Software

Douglas McDonald

Paul, thanks but I can't seen to get it to work. I've attached the project, I'm sure I an just doing it wrong. I put the code you posted in MAIN_WM_CREATE along with some comments.

Thank you
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

Paul Squires

My Code works when the image is "Tiled". It seems to fail when you set the background image to be "Stretched". I will work up some new code for that situation.

BTW - you have an error in your code:

You used:
DeleteObject hWndForm

When it should be:
DeleteObject hOldBrush

Paul Squires
PlanetSquires Software

Paul Squires

Okay, here is pretty big hack but it works. For Stretched back bitmaps you need to basically replace the current background image with a new image. In this case, I use a 16x16 "gray" bitmap to simulate the button face color that normal dialogs use.

This is the code that you would use:

   Local ff As FLY_DATA Ptr
   Local rc As Rect

   ff = GetProp( hWndForm, "FLY_PTR" )
   If ff Then
      If @ff.hBackBitmap Then DeleteObject @ff.hBackBitmap
      GetClientRect hWndForm, rc
      @ff.hBackBitmap = LoadImage( App.hInstance, "IMAGE_GRAY", %IMAGE_BITMAP, rc.nRight, rc.nBottom, 0 )
      InvalidateRect hWndForm, ByVal %Null, %TRUE
      UpdateWindow hWndForm
   End If


I have attached the 16x16 bitmap to this post. Bring it into FF3's Image Library.
Paul Squires
PlanetSquires Software

Douglas McDonald

Thank you Paul I'll give it a try. Do you think there is a different / better way to do the same thing?

Doug
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

Douglas McDonald

Paul, I tried the code but it does not change. I've attached the project. The code is placed in MAIN_OPTMANUAL_BN_CLICKED

Maybe I'm doing it in correctly.

Thank you
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

Paul Squires

Hi Doug,

This is the part of my above post that you seemed to have overlooked:   :P

Quote
I have attached the 16x16 bitmap to this post. Bring it into FF3's Image Library.

Save the "gray.bmp" graphic from my post. Copy it into the "Images" folder for your project, and then import it into your project via the FF3 Image Manager.

I tried it and it seems to work in your project.
Paul Squires
PlanetSquires Software

Douglas McDonald

Yes your right, I tottaly missed the .bmp. It works great!!

sorry
Doug
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?