Brush in 8.12 Window

Brush in 8.12 Window

Postby TimStone » Thu Mar 26, 2009 8: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Brush in 8.12 Window

Postby ukoenig » Thu Mar 26, 2009 9: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: Select all  Expand view

....
....
// 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 :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Brush in 8.12 Window

Postby TimStone » Sun Mar 29, 2009 3: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Brush in 8.12 Window

Postby frose » 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: Select all  Expand view
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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Brush in 8.12 Window

Postby ukoenig » Tue Apr 07, 2009 8:02 pm

Hello Frank,

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

Code: Select all  Expand view

// 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: Select all  Expand view

...
...
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 :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Brush in 8.12 Window

Postby frose » 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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Brush in 8.12 Window

Postby ukoenig » 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: Select all  Expand view

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: Select all  Expand view

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 :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Brush in 8.12 Window

Postby frose » Tue Apr 21, 2009 2: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: Select all  Expand view
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 :D
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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Brush in 8.12 Window

Postby TimStone » Thu May 21, 2009 8: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Brush in 8.12 Window

Postby ukoenig » Thu May 21, 2009 8: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: Select all  Expand view

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 :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Brush in 8.12 Window

Postby TimStone » Fri May 22, 2009 3: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 108 guests