FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Transparent bitmap on MDI with manifest file
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Transparent bitmap on MDI with manifest file
Posted: Sat Nov 07, 2009 09:00 PM
Hi all,
there is an annoyant problem affecting FWH since one year.
It is related to a bitmap displayed on a MDI windows. We already made some discussions about this problem some time ago but this problem still remain because any proposed solution acting on the bitmap class produced other problems on the transparent bitmap on folders.

I made this small self-contained sample that show the problem on www.softwarexp.co.uk/beta/imagemdi.zip
and this image show the problem. Is there any solution (Antonio ?). Thanks in advance

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sat Nov 07, 2009 09:42 PM
Marco,

There is no transparent-background, just a white color.
You must convert the BMP to a BMP with AlphaChannel

Pixelformer is doing the Job for You.

1. Select < Import > from the Filemenue
2. Select < Properties > and change to RGB-Color with Alpha-Channel
3. The white Background is not transparent. Replace white with transparent.
4. Select < Export > from the Filemenue and save as Premultiplied Alpha



You can use the magic-wall-tool, to select the white areas. Replace the white Color with transparent


If You like, You can clean the Picture-Border before saving.


Save as Premultipled Alpha-Bmp.


...
...
DEFINE WINDOW oWnd TITLE "TTitle Class Test" MDI

// Wrong
// @ 10,10 BITMAP oImage FILE "SM_1.BMP" OF oWnd:oWndClient noborder PIXEL
// oImage:lTransparent:=.t.

activate window oWnd;
ON INIT ( FOLDER(), Show_Alpha(hDC) )

return nil

// -------

Function Show_Alpha(hDC)
LOCAL oBmp1, oBmp2, oBmp3

cALPHA1 := c_path + "\IMAGES\Image1.BMP"
cALPHA2 := c_path + "\IMAGES\Image2.BMP"
cALPHA3 := c_path + "\IMAGES\Image3.BMP"

// Left / Top
IF File( "&cALPHA1" )
DEFINE BITMAP oBmp1 FILENAME "&cALPHA1"
ABPaint( hDC, 760, 20, oBmp1:hBitmap, 220 )
oBmp1:End()
ENDIF
IF File( "&cALPHA2" )
DEFINE BITMAP oBmp2 FILENAME "&cALPHA2"
ABPaint( hDC, 780, 170, oBmp2:hBitmap, 220 )
oBmp2:End()
ENDIF
IF File( "&cALPHA3" )
DEFINE BITMAP oBmp3 FILENAME "&cALPHA3"
ABPaint( hDC, 780, 310, oBmp3:hBitmap, 220 )
oBmp3:End()
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: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 08, 2009 01:09 AM

It is true that alpha bitmaps are painted correctly with transparency. But that is not the point made by Mr Marco.

Non alpha bitmaps are painted with transparency correctly on WINDOW ( MDI or non MDI) when Themes are not used, but not when themes are used. Why should the behavior be different between using themes and not using themes. We need to find answer for that.

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 08, 2009 01:33 AM
Mr Maro

This is a TEMPORARY fix for painting the bitmaps transparently on windows even when application is themed.
In bitmap.prg
Code (fw): Select all Collapse
METHOD Paint() CLASS TBitmap

   local aInfo := ::DispBegin(), hBmpOld, nZeroZeroClr, nOldClr
   local nAlphaLevel, hBitmap

   if .f. //IsAppThemed() .and. Empty( ::hBitmap )  // temporary fix for transparency on windows when themes are used
      DrawPBack( ::hWnd, ::hDC )
   else
      #ifdef __CLIPPER__
         SetBrushOrgEx( ::hDC, 8 - ::nLeft() % 8, 8 - ::nTop() % 8 )
      #else
         SetBrushOrgEx( ::hDC, nBmpWidth( ::oBrush:hBitmap ) - ::nLeft, nBmpHeight( ::oBrush:hBitmap ) - ::nTop )
      #endif
      FillRect( ::hDC, GetClientRect( ::hWnd ), ::oWnd:oBrush:hBrush )
   endif

Please try this fix even for academic interest and see the result The problem I guess is in DrawPBack function
Regards



G. N. Rao.

Hyderabad, India
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 08, 2009 08:45 AM
Hi Rao,
thank for your suggest.
Unfortunately I already tried this fix but with this solution the transparent clause on the folder doesn't runs anymore.
Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Mon Nov 09, 2009 10:45 AM
Marco,

This is the right way to do it, as you should not place any control on top of a MDI Client window, as they are managers of the MDI child windows:
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "folder.ch"
#include "image.ch"

static ownd

Function main()

    local oBmp

    DEFINE BITMAP oBmp FILENAME "SM_1.bmp"

    DEFINE WINDOW oWnd TITLE "TTitle Class Test" MDI

    ACTIVATE WINDOW oWnd;
       ON INIT FOLDER() ;
       ON PAINT PaintTransparent( hDC, oBmp )

    oBmp:End()

return nil

function PaintTransparent( hDC, oBmp )

   local nZEROCLR := nRGB( 255, 255, 255 ) // GetZeroZeroClr( hDC, oBmp:hBitmap )
   local nOldColor := SetBkColor( hDC, nRGB( 255, 255, 255 ) )
   
   TransBmp( oBmp:hBitmap, oBmp:nWidth, oBmp:nHeight,;
             nZEROCLR, hDC, 10, 10, nBmpWidth( oBmp:hBitmap ), nBmpHeight( oBmp:hBitmap ) )
             
   SetBkColor( hDC, nOldColor )          
             
return nil             

function Folder()

   local oDlg, oFld1, oFld2
   local cItem, oImage

   DEFINE DIALOG oDlg RESOURCE "Test"

   REDEFINE FOLDER oFld1 ID 110 OF oDlg ;
      PROMPT "Folder1","Folder2" ;
      DIALOGS "sub1", "sub2"

   REDEFINE BITMAP oImage FILE "SM_1.BMP" OF oFld1:aDialogs[1] ID 600
   oImage:lTransparent:=.t.

   ACTIVATE DIALOG oDlg CENTERED

return nil

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Mon Nov 09, 2009 03:26 PM

Thanks Antonio,
it runs.

Due to the routine structure I have difficult to pass as paramet the hDC.
Is there a way to obtain the hDC of oWnd:oWndClient directly in the PaintTrasnsparent routine ? I tried with GetDC(oWnd:oWndClient) but it doesn't runs.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Mon Nov 09, 2009 08:51 PM
Marco,

Try with:
Code (fw): Select all Collapse
oWnd:oWndClient:GetDC()

... painting code using oWnd:oWndClient:hDC

oWnd:oWndClient:ReleaseDC()
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Transparent bitmap on MDI with manifest file
Posted: Tue Nov 10, 2009 11:22 AM
Mr Antonio

Thanks for the explanation. We take the advice not to place controls on MDI Client window.

But we can place controls on normal windows and mdi child windows. The problem of transparency is experienced when this control is placed on a normal window or mdi child window, if and only if the application is themed. Without themes, the transparency works correctly.

Here are two examples.
Normal window:
Code (fw): Select all Collapse
#include 'fivewin.ch'

function Main()

   local oWnd, oImage

   DEFINE WINDOW oWnd

   @ 10,10 BITMAP oImage FILE "SM_1.BMP" OF oWnd NOBORDER PIXEL
   oImage:lTransparent:=.t.

   ACTIVATE WINDOW oWnd

return nil

MDI Child
Code (fw): Select all Collapse
#include 'fivewin.ch'

function Main()

   local oWnd

   DEFINE WINDOW oWnd MDI

   ACTIVATE WINDOW oWnd ON INIT WinChild()

return nil

function WinChild()

   local oWnd, oImage

   DEFINE WINDOW oWnd MDICHILD OF WndMain() COLOR CLR_BLACK,CLR_WHITE

   @ 10,10 BITMAP oImage FILE "SM_1.BMP" OF oWnd NOBORDER PIXEL
   oImage:lTransparent:=.t.

   ACTIVATE WINDOW oWnd

return nil

In both the above examples, transparency works perfectly if themes are not used. If themes are used the bitmaps are not transparent.

This is where we need your help.
Regards



G. N. Rao.

Hyderabad, India
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 15, 2009 05:57 AM
Rao,

Fixed. This little change is required in Class TBitmap Method Paint():
Code (fw): Select all Collapse
   if IsAppThemed() .and. Empty( ::oBrush:hBitmap ) .and. ! ::lTransparent

last check was missing. Your both examples are working fine now. Thanks :-)

Fix included for FWH 9.11
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 15, 2009 02:00 PM
Hi Antonio,
I tested your fix but the problem still remains.
With your fix the transparent clause for bitmaps on mdi runs well but the transparent clause doesn't runs anymore for bitmap on folder (created by resources)

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 15, 2009 04:14 PM
Marco,

This line seems to work fine on that case:
Code (fw): Select all Collapse
   if IsAppThemed() .and. Empty( ::oBrush:hBitmap ) .and. ! ::lTransparent .or. ::oWnd:ClassName() == "TDIALOG"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 15, 2009 05:42 PM

OK. Solved. Thank you very much.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 15, 2009 09:42 PM
:-) Unfortunately thera are still problems with transparent clause.
Now with your changes into the bitmap class the transparent clause doesn't runs anymore when the app runs in a non xp-theme context (Windows without theme manager activated, linux with wine, mac with wine)

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Transparent bitmap on MDI with manifest file
Posted: Sun Nov 15, 2009 10:16 PM
Marco,

This code works fine with or without themes:
Code (fw): Select all Collapse
   if IsAppThemed() .and. Empty( ::oBrush:hBitmap ) .and. ::lTransparent
      if ::oWnd:ClassName() == "TDIALOG"
         DrawPBack( ::hWnd, ::hDC )
      else   
         FillRect( ::hDC, GetClientRect( ::hWnd ), ::oWnd:oBrush:hBrush )
      endif   
   else   
      ...
   endif
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion