Transparent bitmap on MDI with manifest file

Post Reply
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Transparent bitmap on MDI with manifest file

Post by Marco Turco »

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

Image
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
ukoenig
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by ukoenig »

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

Image

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

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

Save as Premultipled Alpha-Bmp.
Image

...
...
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 :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
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by nageswaragunupudi »

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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by nageswaragunupudi »

Mr Maro

This is a TEMPORARY fix for painting the bitmaps transparently on windows even when application is themed.
In bitmap.prg

Code: Select all | Expand

METHOD Paint() CLASS TBitmap

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

   if .f. //IsAppThemed() .and. Empty( ::oBrush: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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Marco Turco »

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.
Image
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Antonio Linares
Site Admin
Posts: 42521
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 76 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Antonio Linares »

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

#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
 

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Marco Turco »

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
User avatar
Antonio Linares
Site Admin
Posts: 42521
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 76 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Antonio Linares »

Marco,

Try with:

Code: Select all | Expand


oWnd:oWndClient:GetDC()

... painting code using oWnd:oWndClient:hDC

oWnd:oWndClient:ReleaseDC()
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by nageswaragunupudi »

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

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

#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
User avatar
Antonio Linares
Site Admin
Posts: 42521
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 76 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Antonio Linares »

Rao,

Fixed. This little change is required in Class TBitmap Method Paint():

Code: Select all | Expand


   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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Marco Turco »

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)

Image
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Antonio Linares
Site Admin
Posts: 42521
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 76 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Antonio Linares »

Marco,

This line seems to work fine on that case:

Code: Select all | Expand


   if IsAppThemed() .and. Empty( ::oBrush:hBitmap ) .and. ! ::lTransparent .or. ::oWnd:ClassName() == "TDIALOG"
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Marco Turco »

OK. Solved. Thank you very much.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Marco Turco »

:( 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)

Image
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Antonio Linares
Site Admin
Posts: 42521
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 76 times
Contact:

Re: Transparent bitmap on MDI with manifest file

Post by Antonio Linares »

Marco,

This code works fine with or without themes:

Code: Select all | Expand


   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
Post Reply