Transparent bitmap on MDI with manifest file

Transparent bitmap on MDI with manifest file

Postby Marco Turco » Sat Nov 07, 2009 9: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

Image
Best Regards,

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

Re: Transparent bitmap on MDI with manifest file

Postby ukoenig » Sat Nov 07, 2009 9: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

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

Re: Transparent bitmap on MDI with manifest file

Postby nageswaragunupudi » Sun Nov 08, 2009 1: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
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Transparent bitmap on MDI with manifest file

Postby nageswaragunupudi » Sun Nov 08, 2009 1: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: Select all  Expand view
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
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Transparent bitmap on MDI with manifest file

Postby Marco Turco » Sun Nov 08, 2009 8: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.
Image
Best Regards,

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

Re: Transparent bitmap on MDI with manifest file

Postby Antonio Linares » 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: Select all  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Transparent bitmap on MDI with manifest file

Postby Marco Turco » Mon Nov 09, 2009 3: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Transparent bitmap on MDI with manifest file

Postby Antonio Linares » Mon Nov 09, 2009 8:51 pm

Marco,

Try with:
Code: Select all  Expand view

oWnd:oWndClient:GetDC()

... painting code using oWnd:oWndClient:hDC

oWnd:oWndClient:ReleaseDC()
 
regards, saludos

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

Re: Transparent bitmap on MDI with manifest file

Postby nageswaragunupudi » 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: Select all  Expand view
#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 view
#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
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Transparent bitmap on MDI with manifest file

Postby Antonio Linares » Sun Nov 15, 2009 5:57 am

Rao,

Fixed. This little change is required in Class TBitmap Method Paint():
Code: Select all  Expand view

   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
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Transparent bitmap on MDI with manifest file

Postby Marco Turco » Sun Nov 15, 2009 2: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)

Image
Best Regards,

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

Re: Transparent bitmap on MDI with manifest file

Postby Antonio Linares » Sun Nov 15, 2009 4:14 pm

Marco,

This line seems to work fine on that case:
Code: Select all  Expand view

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

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

Re: Transparent bitmap on MDI with manifest file

Postby Marco Turco » Sun Nov 15, 2009 5:42 pm

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

Re: Transparent bitmap on MDI with manifest file

Postby Marco Turco » Sun Nov 15, 2009 9: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)

Image
Best Regards,

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

Re: Transparent bitmap on MDI with manifest file

Postby Antonio Linares » Sun Nov 15, 2009 10:16 pm

Marco,

This code works fine with or without themes:
Code: Select all  Expand view

   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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 99 guests