FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Brush in 8.12 Window
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Brush in 8.12 Window
Posted: Thu Mar 26, 2009 08:12 PM

I assign a Brush to the main window of my application. The window is opened to a defined size. If my client clicked on the Maximize button, in the past the BMP would simply stretch to the size of the window as displayed on the full monitor. In 8.12, it now gets a "tiled" look where the original brush covers about 60% of the window, and then paints a second copy in the remainder.

The code to apply the brush is:

DEFINE BRUSH owBrush RESOURCE "WINBACK"
...
oWnd:oBrush := owBrush

WINBACK is a .bmp file in the resource.

Is there a way to get the stretched bitmap back ?

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Brush in 8.12 Window
Posted: Thu Mar 26, 2009 09:26 PM
Hello Tim,

I understand, that You are using a Image as a Background.
It doesn't matter, if it comes as a file from disk, or from resource.
Both solutions : Fill background with a Image or Tiled.

Code (fw): Select all Collapse
....
....
// Brush Image
// --------------
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT WL_IMAGE( hDC, oWnd )

// Brush Image Tiled
// ---------------------
ACTIVATE WINDOW oWnd1 MAXIMIZED ;
ON PAINT WB_IMAGE( oWnd )

RETURN( NIL )

//--------- IMAGE - Background ------------------------ 

STATIC FUNCTION WL_IMAGE(  hDC, oWnd ) 
LOCAL oImage
LOCAL nWidth  := oWnd:nWidth()
LOCAL nHeight := oWnd:nHeight()

// Selected Image ( W_LOGO is a BMP-file from disk )
// ------------------------------------------------------------
cNEWLOGO := "&c_pfad\IMAGES\" + ALLTRIM(W_LOGO)
IF File( "&cNEWLOGO" )
   DEFINE IMAGE oImage FILENAME "&cNEWLOGO" 
   PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , nWIDTH, nHEIGHT, , .T. ) 
ELSE
   MsgAlert( "Cannot load : " + CRLF + ;
   cNEWLOGO, "Error" )             
ENDIF

RETURN NIL

//--------- IMAGE - BRUSH ------------------------ 

STATIC FUNCTION WB_IMAGE( oWnd ) 
LOCAL oImage

cNEWLOGO := "&c_pfad\IMAGES\" + ALLTRIM(B_LOGO) // small BMP 32 x 32
IF File( "&cNEWLOGO" )
   DEFINE BRUSH oImage FILE "&cNEWLOGO"
   SET BRUSH OF oWnd TO oImage
   RELEASE BRUSH oImage
ELSE
   MsgAlert( "Cannot load : " + CRLF + ;
   cNEWLOGO, "Error" )   
ENDIF

RETURN NIL


Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Brush in 8.12 Window
Posted: Sun Mar 29, 2009 03:58 PM

Thank You.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: Brush in 8.12 Window
Posted: Mon Mar 30, 2009 11:57 AM
Hello Uwe,

trying hard to reconstruct your example, but something is wrong, the background is always grey. Here is the source:

Code (fw): Select all Collapse
FUNCTION Main()
    //
    // Testen von Hintergrundbildern
    //
   LOCAL oWnd
   LOCAL oFont
   LOCAL cLogo := "five.bmp"
   //
   DEFINE FONT oFont NAME "TAHOMA" SIZE 0, - 12
   DEFINE WINDOW oWnd MDI TITLE "Testen von Hintergrundbildern"
   //
   // Schriftart setzen
   //
   oWnd:setFont( oFont )
   //
   // Filename in der Messagebar anzeigen
   //
   SET MESSAGE OF oWnd TO cLogo
   //
   // Brush Image
   // --------------
   ACTIVATE WINDOW oWnd MAXIMIZED ON PAINT WL_IMAGE( oWnd, cLogo )
   //
   // Brush Image Tiled
   // ---------------------
   //ACTIVATE WINDOW oWnd1 MAXIMIZED ON PAINT WB_IMAGE( oWnd )
   //
   // Aufr„umen
   //
   RELEASE FONT oFont
RETURN( NIL )

//--------- IMAGE - Background ------------------------

STATIC FUNCTION WL_IMAGE( oWnd, cLogo )
   LOCAL oImage
   LOCAL nWidth  := oWnd:nWidth()
   LOCAL nHeight := oWnd:nHeight()
   
   LOCAL hDC := oWnd:GetDC()

   // Selected Image ( W_LOGO is a BMP-file from disk )
   // ------------------------------------------------------------
   IF File( cLogo )
      DEFINE IMAGE oImage FILENAME cLogo
      PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , nWIDTH, nHEIGHT, , .T. )
   ELSE
      MsgAlert( "Cannot load : " + CRLF + cLogo, "Error" )            
   ENDIF
RETURN NIL


Can you help?
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Brush in 8.12 Window
Posted: Tue Apr 07, 2009 08:02 PM
Hello Frank,

another way to display a Background-Image without extra Function :
( Freeimage.dll is used )

Code (fw): Select all Collapse
// SIZE can be any value, because it will be adjusted to Window-Size

IF File( "FANTASY1.jpg" )
   @ 0, 0 IMAGE oImage SIZE 150, 150 OF oWnd ADJUST
   oImage:Progress( .f. )
   oImage:LoadBmp( "FANTASY1.JPG" ) // Your Image
ELSE
   MsgAlert( "Cannot load : " + CRLF + ;
       "FANTASY1.jpg", "Error" )        
ENDIF

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT DRAWBITMAP( hDC, oImage:hbitmap, 0, 0,; 
      oWnd:nWidth(), oWnd:nHeight() )


Another Solution :
Code (fw): Select all Collapse
...
...
IF File( "FANTASY1.jpg" )
   DEFINE IMAGE oImage FILENAME "FANTASY1.jpg"
ELSE
   MsgAlert( "Cannot load : " + CRLF + ;
       "FANTASY1.jpg", "Error" )        
ENDIF

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT PalBmpDraw( hDC, 0, 0, oImage1:hBitmap, , oWnd:nWidth(), oWnd:nHeight(), , .T. ) 

RETURN ( NIL )


Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: Brush in 8.12 Window
Posted: Fri Apr 17, 2009 10:19 AM

Uwe,

thank you very much for the help, both methods are working for me :D

Do you have an explanation why it doesn't work with the function WL_IMAGE()?

Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Brush in 8.12 Window
Posted: Fri Apr 17, 2009 12:25 PM
Hello Frank,

Background-defines are working different with MDI-Windows.
If You use MDI, the used Function from above shows a Grey background.

Code (fw): Select all Collapse
 
LOCAL hDC  // don't forget !
...
...
DEFINE WINDOW oWnd TITLE "Image-Test"  // MDI ;

SET MESSAGE OF oWnd TO "Image-Test" ;
CENTERED CLOCK KEYBOARD 2007

// WL_IMAGE - Function works on non MDI-Windows
// ----------------------------------------------------------
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT WL_IMAGE( oWnd, hDC, "FANTASY1.jpg" )

RETURN NIL

//--------- IMAGE - Background ------------------------

STATIC FUNCTION WL_IMAGE( oWnd, hDC, cLogo )
LOCAL oImage

// Selected Image a BMP-file from disk )
// ---------------------------------------------
IF File( cLogo )
      DEFINE IMAGE oImage FILENAME cLogo
      PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , oWnd:nWidth(), oWnd:nHeight(), , .T. )
ELSE
      MsgAlert( "Cannot load : " + CRLF + cLogo, "Error" )            
ENDIF

RETURN NIL


Using a Background-Function in MDI-Window :

Code (fw): Select all Collapse
LOCAL hDC, oImage // !!!!!
...
DEFINE WINDOW oWnd TITLE "Image-Test"  MDI  // !!!!!

// the difference, the Image must be defined here !!!!!!!!
DEFINE IMAGE oImage FILENAME "FANTASY1.jpg"

SET MESSAGE OF oWnd TO "Image-Test" ;
CENTERED CLOCK KEYBOARD 2007

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT WL_IMAGE( oWnd, hDC, oImage, "FANTASY1.jpg" )

RETURN ( NIL )

//--------- IMAGE - Background =>> MDI ------------------------

STATIC FUNCTION WL_IMAGE( oWnd, hDC, oImage, cLogo )

// Selected Image a BMP-file from disk 
// -------------------------------------------
IF File( cLogo )
      PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , oWnd:nWidth(), oWnd:nHeight(), , .T. )
ELSE
      MsgAlert( "Cannot load : " + CRLF + cLogo, "Error" )            
ENDIF

RETURN NIL


Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: Brush in 8.12 Window
Posted: Tue Apr 21, 2009 02:36 PM
Hello Uwe,

THX for your assistance. :-)

I've made some more testing and here is the working sample for both SDI and MDI:

Code (fw): Select all Collapse
FUNCTION Main()
   //
   // Testing background pictures
   //
   LOCAL oWnd
   LOCAL oFont
   LOCAL cLogo := "C:\xHarbour\FiveWin\my_source\five.bmp"
   LOCAL oImage
   LOCAL oBrush
   LOCAL hDC
   //
   // Background color is white
   //
   DEFINE BRUSH oBrush COLOR CLR_WHITE
   DEFINE FONT oFont NAME "TAHOMA" SIZE 0, - 12
   DEFINE WINDOW oWnd MDI TITLE "Testing background pictures" BRUSH oBrush
   //DEFINE WINDOW oWnd TITLE "Testing background pictures" BRUSH oBrush
   //
   // Font
   //
   oWnd:setFont( oFont )
   //
   // Show file name in the Messagebar
   //
   SET MESSAGE OF oWnd TO cLogo
   //
   // Returns the current device context, if any or request a new one
   //
   hDC := oWnd:GetDC()
   //
   // Activate the window
   //
   ACTIVATE WINDOW oWnd MAXIMIZED ON PAINT WL_IMAGE( oWnd, hDC, cLogo )
   //ACTIVATE WINDOW oWnd MAXIMIZED ON PAINT WL_IMAGE( oWnd, cLogo )
RETURN ( NIL )

STATIC FUNCTION WL_IMAGE( oWnd, hDC, cLogo )
//STATIC FUNCTION WL_IMAGE( oWnd, cLogo )
   //
   // Displays centerd background bitmap with scaling factor
   //
   //LOCAL hDC
   LOCAL oImage
   LOCAL nScaleFactor := 2
   LOCAL nHeightBitmap
   LOCAL nWidthBitmap
   LOCAL nHeightBitmapNew
   LOCAL nWidthBitmapNew
   LOCAL oRect
   LOCAL nRow
   LOCAL nCol
   //
   //hDC := oWnd:GetDC()
   //
   IF File( cLogo )
      //
      // Doesn't work in MDI
      //
      //oImage := TBitmap():New(,,,,, cLogo, .T., oWnd,,, .F., .T.,,, .F.,, .F.,, .F. )
      DEFINE IMAGE oImage FILENAME cLogo
      //
      // Original size of the bitmap
      //
      nHeightBitmap := nBmpHeight( oImage:hBitmap )
      nWidthBitmap := nBmpWidth( oImage:hBitmap )
      //
      // Window size
      //
      oRect := oWnd:GetRect()
      //
      // Calculate new bitmap size in relation to the window height
      //
      nHeightBitmapNew := ( oRect:nBottom - oRect:nTop ) / nScaleFactor
      nWidthBitmapNew  := nWidthBitmap * nHeightBitmapNew / nHeightBitmap
      //
      // Control the new bitmap size in relation to the window width
      //
      IF nWidthBitmapNew > ( oRect:nRight - oRect:nLeft ) / nScaleFactor
        //
         // Calculate new bitmap size in relation to the window width
        //
         nWidthBitmapNew  := ( oRect:nRight - oRect:nLeft ) / nScaleFactor
         nHeightBitmapNew := nHeightBitmap * nWidthBitmapNew / nWidthBitmap
      ENDIF
      //
      // Calculate the position for centered output
      //
      nRow  := ( oRect:nBottom - oRect:nTop ) / 2 - nHeightBitmapNew / 2
      nCol  := ( oRect:nRight - oRect:nLeft ) / 2 - nWidthBitmapNew / 2
      //
      // Display bitmap
      //
      PalBmpDraw( hDC, nRow, nCol, oImage:hBitmap,, nWidthBitmapNew, nHeightBitmapNew,, .F., )
   ELSE
      MsgAlert( "Cannot load : " + CRLF + cLogo, "Error" )
   ENDIF
RETURN NIL


You are right, SDI and MDI are working differently:
- In SDI the background color is white (Default?). In MDI a grey background color comes up, which can be avoided with 'DEFINE BRUSH oBrush COLOR CLR_WHITE'
- In MDI <hDC> must be passed from the calling function, in SDI <hDC> a local call of 'oWnd:GetDC()' is also working
- In SDI you can paint the bitmap by using TBitmap(). I think there is no need to use PalBmpDraw() anymore, but havn't done further tests because I want to use MDI

That's very strange, it seems to be not very consistantly :-)

But the main thing is, that the task is solved and I have a working peace of source code :-)
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Brush in 8.12 Window
Posted: Thu May 21, 2009 08:35 PM

A strange thing has been happening.

I'm using your original solution ( top of thread ) and it seems to work. However, after awhile using the program, which is all SDI ( Dialogs ), when someone returns to the MAIN( ) window, the background disappears.

There is no persistant pattern that I can identify.

Any thoughts ?

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Brush in 8.12 Window
Posted: Thu May 21, 2009 08:56 PM
Hello Tim,

I think maybe hDC is defined a few times without a Release.

You don't need hDC := oWnd:GetDC() to define inside the main-Window

Is that the source, how Your background is defined, calling the Paint-function ?
Code (fw): Select all Collapse
LOCAL hDC  // don't forget !
...
...
DEFINE WINDOW oWnd TITLE "Image-Test" ;

SET MESSAGE OF oWnd TO "Image-Test" ;
CENTERED CLOCK KEYBOARD 2007

// WL_IMAGE - Function works on non MDI-Windows
// ----------------------------------------------------------
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT WL_IMAGE( oWnd, hDC, "FANTASY1.jpg" )

RETURN NIL

//--------- IMAGE - Background ------------------------

STATIC FUNCTION WL_IMAGE( oWnd, hDC, cLogo )
LOCAL oImage

// Selected Image a BMP-file from disk )
// ---------------------------------------------
IF File( cLogo )
      DEFINE IMAGE oImage FILENAME cLogo
      PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , oWnd:nWidth(), oWnd:nHeight(), , .T. )
ELSE
      MsgAlert( "Cannot load : " + CRLF + cLogo, "Error" )            
ENDIF

RETURN NIL


Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Brush in 8.12 Window
Posted: Fri May 22, 2009 03:11 PM

LOCAL hDC was not included... we'll see if that improves the situation. Thank you.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit

Continue the discussion