Main Window background

Main Window background

Postby TimStone » Sun Oct 11, 2009 11:03 pm

On my main application window, I'm using a bitmap to provide an image in the background. I tried using a brush, but it tiles the image which does not look good. I want it to stretch the image so I use:

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

DEFINE IMAGE oImage RESOURCE "WINBACK"
PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , nWIDTH, nHEIGHT, , .T. )

RETURN NIL

This works fine. However, I want to also impose another bitmap in the center of the window. It is a transparent bitmap ( Alpha ), and should exist on top of the main background, centered.

I thought this was addressed previously, but I can't find it. Again, the problem with the brush it that it tiles on a window that is maximized, and looks bad.

The background bitmap is a scenery image. The other bitmap is the logo.

Any ideas would be appreciated.
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: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Main Window background

Postby ukoenig » Sun Oct 11, 2009 11:48 pm

Hello Tim,
Adding a Alpha-Logo to the Background :

Image

Code: Select all  Expand view

...
STATIC oWnd, nWidth := GetSysMetrics(0), nHeight := GetSysMetrics(1)

FUNCTION MAIN()
Local oBmp1
...
...
c_path := CURDRIVE() + ":\" + GETCURDIR()
...
DEFINE WINDOW  oWnd  TITLE "
VTitle Painter"
...
DEFINE IMAGE oBmp1 FILENAME c_path + "
\Images\BACKGRD.JPG"
...
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON PAINT ( DRAWBITMAP( hdc, oBmp1:hbitmap, 0, 0,;
                    nWidth, nHeight ), W_ALPHA( hDC ) )

// --------- W-ALPHA-BMP  --------------------------------------

FUNCTION W_ALPHA( hDC )
LOCAL oBmp2

cALPHA :=  c_path + "
\IMAGES\Flower.BMP"
IF File( "
&cALPHA" )
   DEFINE BITMAP oBmp2 FILENAME "
&cALPHA"
 
   // Centered
   ABPaint( hDC, ( nWidth / 2 ) - ( oBmp2:nWidth / 2 ), ;
      ( nHeight / 2 ) - ( oBmp2:nHeight / 2), oBmp2:hBitmap, 220 )

  // Left / Top
   ABPaint( hDC, 650, 70, oBmp2:hBitmap, 220 )

ELSE
   MsgAlert( "
Cannot load : " + CRLF + ;
   cALPHA, "
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: Main Window background

Postby Antonio Linares » Mon Oct 12, 2009 6:23 am

Uwe,

You have to destroy oBmp2 after using it:

oBmp2:End()

Better if you keep it in a static variable and only load it once.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41406
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Main Window background

Postby TimStone » Mon Oct 12, 2009 6:18 pm

What did you use to associate the image to the window ? Is there a full code sample ?
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: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Main Window background

Postby ukoenig » Mon Oct 12, 2009 9:30 pm

Hello Tim,

have a look at the Alpa-Function above :

DEFINE BITMAP oBmp1 FILENAME "Logo.bmp"

nBMPWidth := oBmp1:nWidth
nBMPHeight := oBmp1:nHeight
// Centered Logo
// ----------------
ABPaint( hDC, ( oWnd:nWidth() / 2 ) - ( nBMPWidth / 2 ), ;
( oWnd:nHeight() / 2 ) - (nBMPHeight / 2), oBmp1:hBitmap, 220 )

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: Main Window background

Postby TimStone » Tue Oct 13, 2009 2:41 pm

I resolved the problem, but my question was about the first image you were using as the background. I asked how you were applying that to the window.

It would be nice if a window brush had a stretch feature.
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: 2909
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Main Window background

Postby ukoenig » Tue Oct 13, 2009 4:21 pm

Tim,

that includes all possible Backgrounds :

Code: Select all  Expand view

// ------- WINDOW - PREVIEW --------------------------
// ----- Color, Gradient, Predefined Brush, BMP-Brush, Image

FUNCTION W_PREVIEW()
LOCAL oWnd, oBrush

IF W_STYLE = 1 // Color
   DEFINE BRUSH oBrush  COLOR W_COLOR1
ENDIF
IF W_STYLE = 2 // Predefined Brush
   DEFINE BRUSH oBrush  STYLE "BORLAND"
ENDIF

DEFINE WINDOW oWnd TITLE "Background for Windows"  

IF W_STYLE = 1 .or. W_STYLE = 2
   SET BRUSH OF oWnd TO oBrush
   RELEASE BRUSH oBrush
ENDIF

ACTIVATE WINDOW oWnd1 MAXIMIZED ;
ON PAINT ( IIF( W_STYLE = 3, W_GRAD( oWnd, hDC, .T. ), NIL ), ;
      IIF( W_STYLE = 4, W_BRUSH( oWnd ), NIL ), ;
      IIF( W_STYLE = 5, W_MAGE( oWnd, hDC ), NIL ), ;
      W_ALPHA( oWnd,hDC ), NIL ) )

RETURN NIL

// --------- GRADIENT  --------------------------------------

STATIC FUNCTION W_GRAD( oWnd, hDC, lDirect )
local aGrad := { { W_MOVE, W_COLOR1, W_COLOR2 }, ;
      { W_MOVE, W_COLOR2, W_COLOR1 } }        

IF lDIRECT = .T.
   GradientFill( hDC,  0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, .T. )
ELSE
   GradientFill( hDC,  0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, .F. )
ENDIF

RETURN NIL

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

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

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

RETURN NIL

//--------- BRUSH ( MBP ) Background ------------------------

STATIC FUNCTION W_BRUSH( oWnd )
LOCAL oImage

cNEWLOGO := "
&c_path\IMAGES\Sky.bmp"
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

// --------- W-ALPHA-BMP  --------------------------------------

FUNCTION W_ALPHA( oWnd,hDC )
LOCAL oBmp1

cALPHA :=  c_path + "
\IMAGES\" + ALLTRIM(W_C_ALPHA)
IF File( "
&cALPHA" )
   DEFINE BITMAP oBmp1 FILENAME "
&cALPHA"
   // Centered
   ABPaint( hDC, ( oWnd:nWidth / 2 ) - ( oBmp2:nWidth / 2 ), ;
      ( oWnd:nHeight / 2 ) - ( oBmp2:nHeight / 2), oBmp2:hBitmap, 220 )
*   ABPaint( hDC, 50, 50, oBmp1:hBitmap, 220 )
   oBmp1:End()
ELSE
   MsgAlert( "
Cannot load : " + CRLF + ;
   cALPHA, "
Error" )  
ENDIF

RETURN NIL





Best Regards
Uwe :lol:
Last edited by ukoenig on Tue Oct 13, 2009 4:29 pm, edited 2 times in total.
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: Main Window background

Postby nageswaragunupudi » Tue Oct 13, 2009 4:26 pm

This is the simple code I use in my applications
Code: Select all  Expand view
#include 'fivewin.ch'

#define BRUSH_TILED     0
#define BRUSH_STRETCH   1
#define BRUSH_FILL      2

function Main()

   local oWnd, oBar, oBrush

   DEFINE BRUSH oBrush FILE 'c:\fwh\bitmaps\olga1.jpg' // use the image of your choice
   DEFINE WINDOW ownd BRUSH oBrush MDI
   DEFINE BUTTONBAR oBar OF oWnd 2007
   SET MESSAGE OF oWnd TO '' 2007

   ACTIVATE WINDOW oWnd ;
      ON RESIZE ResizeBrush( oWnd )

return nil

function ResizeBrush( oWnd )

   local aRect    := GetClientRect( If( oWnd:ClassName == 'TMDIFRAME', ;
                        oWnd:oWndClient:hWnd, oWnd:hWnd ) )
   local hBmp     := ResizeBitmap( oWnd:oBrush:hBitmap, ;
                              aRect[ 4 ], aRect[ 3 ], BRUSH_STRETCH )

   DeleteObject( oWnd:oBrush:hBrush )
   oWnd:oBrush:hBrush   := CreatePatternBrush( hBmp )
   DeleteObject( hBmp )

return nil
 

I keep the function ResizeBrush in my library, This function works well both for MDI and non MDI windows.

You may decide the stretch-mode of the background image, STRECTH or FILL according your or your user's taste.

Note: Brushes can be used for resizable backgrounds in the above manner. Using brush has many advantages over painting the image directly,
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Main Window background

Postby Enrico Maria Giordano » Tue Oct 13, 2009 7:19 pm

nageswaragunupudi wrote:Using brush has many advantages over painting the image directly,


Can you list some of the advantages?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Main Window background

Postby ukoenig » Mon Feb 01, 2010 1:41 pm

I wanted to test the new fifth parameter of TBrush but it didn't work. There is no Image.
I want to use it, to show Transparent Buttons ( TBtnBMP ) on a Image Background, because it only works with brushes.
I tested some combinations but < TBrush():New(... > shows allways a transparnt Background.
Somebody got a working example ?

Enhancements: Class TBrush
a. Now any image file ( jpg, png, etc. ) can be used to create a Brush.
b. Brush can also be created from a bitmap handle by
specifying the handle as the fifth parameter of TBrush():New() method.


FUNCTION DB_IMAGE( oDlg )
LOCAL oBrush

// W_BRUSH = "test.jpg"

cFile := c_path + "\IMAGES\" + ALLTRIM(W_BRUSH)
IF ! Empty( W_BRUSH ) .and. File( "&cFile" )
*oBrush := TBrush():New( , ,"&cFile", ,1)
*oDlg:SetBrush( oBrush )
*RELEASE BRUSH oBrush


// That works :
DEFINE BRUSH oBrush FILE "&cFile"
SET BRUSH OF oDlg TO oBrush
ELSE
MsgAlert("No file selected !","Attention" )
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: Main Window background

Postby nageswaragunupudi » Mon Feb 01, 2010 3:30 pm

>>
I wanted to test the new fifth parameter of TBrush but it didn't work.
>>
it works. If you have a bitmap handle like hBmp, you can specify it as 5th parameter, leaving all the first 4 parameters as nil. It did not work in the above example, because (1) usage is not correct and (2) you have not provided bitmap handle as the 5th parameter. You provided both file name and also an unknown number 1 which is not a bitmap handle as 5th parameter.

You can examine xbrowse.prg for its usage.

>>
// That works :
DEFINE BRUSH oBrush FILE "&cFile"
>>
Obviously this works. By the way "&cFile" is not necessary and involves unnecessary macro expansion.

DEFINE BRUSH oBrush FILE cFile
is enough
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Main Window background

Postby ukoenig » Tue Feb 02, 2010 10:15 am

Thank You very much,

I finished the new Tool-Part ( Buttonbar- and TBtnBMP - painting )
but anyhow I don't get the Image ( brush ) resized to Dialog-Size.
Do You have any working example, to get this part finished as well,
to make the Tools ready for Download ?

Image

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: Main Window background

Postby nageswaragunupudi » Tue Feb 02, 2010 11:59 am

This is the safest way to set resized brush:
Code: Select all  Expand view
#include 'fivewin.ch'

function main()

   local oDlg, otmp, oBrush
   local nWidth := 400, nHeight := 300

   DEFINE BRUSH oTmp FILE '\fwh\bitmaps\olga1.jpg'
   oBrush   := oTmp:Resized( nWidth, nHeight, 1 )  // 1 = stretch, 2 : fitoutside, 3:fitinside
   RELEASE BRUSH oTmp

   DEFINE DIALOG oDlg SIZE nWidth, nHeight PIXEL BRUSH oBrush
   ACTIVATE DIALOG oDlg

   RELEASE BRUSH oBrush

return nil
 

Please compile this code and see that it works.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Main Window background

Postby ukoenig » Tue Feb 02, 2010 3:00 pm

Thank You very much,

The resizing works fine now.
I had to do a little change, because of different Previews with one Dialog
and to get the Dialog-Size :

Image

#include "FiveWin.ch"

// ---------------- TBtnBMP ---------------------------

FUNCTION DLG_BTN3()
LOCAL oDlg

DEFINE DIALOG oDlg RESOURCE "DlgBtn" ;
TITLE "ButtonBar- and BtnBMP - Preview" TRANSPARENT
...
...
...
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT DL_IMAGE( oDlg )

RETURN NIL

//----------- Dialog IMAGE-Brush ----------------------

FUNCTION DL_IMAGE( oDlg )
LOCAL oBrush, oTmp
LOCAL aRect := GETCLIENTRECT( oDlg:hWnd )

cFile := c_path + "\IMAGES\" + ALLTRIM(W_IMAGE)
DEFINE BRUSH oTmp FILE cFile
// 1 = stretch, 2 : fitoutside, 3:fitinside
oBrush := oTmp:Resized( aRect[4], aRect[3], 1 )
RELEASE BRUSH oTmp
SET BRUSH OF oDlg TO oBrush
RELEASE BRUSH oBrush

RETURN NIL
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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 35 guests