Page 1 of 1

AlphaBlend in Windows Mobile / WinCE

PostPosted: Sat Apr 11, 2009 9:47 am
by Antonio Linares
We have found that some versions of Windows Mobile support AlphaBlend().

In order to check if your Windows Mobile or Windows CE supports it, please build and run the following test. A zero means it is not supported

test.prg
Code: Select all  Expand view

#include "FWCE.ch"

function Main()

   MsgInfo( Test() )

return nil

#pragma BEGINDUMP


#include <hbapi.h>
#include <windows.h>

LPWSTR AnsiToWide( char * );

HMODULE GetProcAddressW( HMODULE, LPWSTR );

HB_FUNC( TEST )
{
  LPWSTR pW1 = AnsiToWide( "coredll.dll" );
  LPWSTR pW2 = AnsiToWide( "AlphaBlend" );
  HMODULE hDll = LoadLibrary( pW1 );

  hb_retnl( ( LONG ) GetProcAddressW( hDll, pW2 ) );

  hb_xfree( pW1 );
  hb_xfree( pW2 );
  FreeLibrary( hDll );
}

#pragma ENDDUMP
 

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Sat Apr 11, 2009 1:47 pm
by Antonio Linares
Finally we got AlphaBlend support no matter if it is not supported by Windows Mobile or WinCE ! :-)

FWPPC has FWH ABPaint() too :-)

TestAB.prg
Code: Select all  Expand view

#include "FWCE.ch"

function Main()

   local oWnd, oBmp, oBmp2

   DEFINE BITMAP oBmp FILENAME CurDir() + "\Trash.bmp"

   DEFINE BITMAP oBmp2 FILENAME CurDir() + "\paper2.bmp"
   
   DEFINE WINDOW oWnd
   
   ACTIVATE WINDOW oWnd ;
      ON PAINT ( DrawBitmap( hDC, oBmp2:hBitmap, 0, 0 ), ABPaint( hDC, 10, 10, oBmp:hBitmap, 255 ) )

return nil
 

In Windows Mobile:
Image
In Windows CE:
Image

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Sun Apr 19, 2009 8:54 pm
by Otto
Hello Antonio,
which version of FWPPC has ABPaint?
Best regards,
Otto
error LNK2001: unresolved external symbol HB_FUN_ABPAINT

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Tue Apr 21, 2009 7:39 am
by Antonio Linares
Otto,

We plan to publish a new FWPPC build that will include it :-)

In the meantime, we may provide you the required modules for you to test it :-)

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Fri Aug 28, 2009 12:19 am
by Silvio
Antonio ,
I runned your functio to chech if my smathphone have alpphablend system.
the msginfo return a number:66410360.
If you my smarthphone support alpha blend system?
I think it depend if on our system is loaded microsoft compact framework or not.
On wm 5.0 (on another smarthphone Htc TNT I) there is a net cf 1.0 and the ceck function return 0.
On my smathphone (htc tnt II ) there is now net cf 3.5 and the chech return the number 66410360.

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Fri Aug 28, 2009 7:53 am
by Antonio Linares
Silvio,

FWPPC ABPaint() function runs on all Windows versions :-)

It is a self contained C function, no need for Windows to support it.

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Fri Aug 28, 2009 6:36 pm
by mmercado
Hello Antonio:
Antonio Linares wrote:It is a self contained C function, no need for Windows to support it.


Would you please to send me the required files to test it ?, thanks in advance.

Best regards

Manuel Mercado
my email: manuelmercado @ prodigy.net.mx

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Sun Aug 30, 2009 7:09 am
by Silvio
Antonio,
My fwppc not have ABPaint() function!
It is the same of fwh?

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Sun Aug 30, 2009 7:44 am
by Antonio Linares
This is the source code for ABPaint() for FWPPC:
Code: Select all  Expand view

BOOL AlphaBlendU( HDC dcDest, int x, int y, int cx, int cy,
                             HDC dcSrc, int sx, int sy, int scx, int scy, int alpha )
{
    BITMAPINFOHEADER BMI;
    BYTE * pSrcBits;
    HBITMAP hbmSrc;
    BYTE * pDestBits;
    HBITMAP hbmDest;
    HDC dc;
    HBITMAP dcOld;
    int j, i;

    // Fill in the header info.
    BMI.biSize = sizeof(BITMAPINFOHEADER);
    BMI.biWidth = cx;
    BMI.biHeight = cy;
    BMI.biPlanes = 1;
    BMI.biBitCount = 32;
    BMI.biCompression = BI_RGB;   // No compression
    BMI.biSizeImage = 0;
    BMI.biXPelsPerMeter = 0;
    BMI.biYPelsPerMeter = 0;
    BMI.biClrUsed = 0;           // Always use the whole palette.
    BMI.biClrImportant = 0;

    // Create DIB section in shared memory
    hbmSrc = CreateDIBSection (dcSrc, (BITMAPINFO *)&BMI,
        DIB_RGB_COLORS, (void **)&pSrcBits, 0, 0l);

    // Create DIB section in shared memory
    hbmDest = CreateDIBSection (dcDest, (BITMAPINFO *)&BMI,
        DIB_RGB_COLORS, (void **)&pDestBits, 0, 0l);

    // Copy our source and destination bitmaps onto our DIBSections,
    // so we can get access to their bits using the BYTE *'s we
    // passed into CreateDIBSection
    dc = CreateCompatibleDC(NULL);

    dcOld = (HBITMAP) SelectObject(dc, hbmSrc);

    if (!StretchBlt(dc, 0, 0, cx, cy, dcSrc, sx, sy,
                        scx, scy, SRCCOPY))
        return FALSE;

    SelectObject( dc, hbmDest );

    if(  !StretchBlt( dc, 0, 0, cx, cy, dcDest, x, y, cx, cy, SRCCOPY ) )
       return FALSE;

    SelectObject( dc, dcOld );
    DeleteDC( dc );

    for( j = 0; j < cy; ++j )
    {
       LPBYTE pbDestRGB = (LPBYTE)&((DWORD*)pDestBits)[j * cx];
       LPBYTE pbSrcRGB = (LPBYTE)&((DWORD*)pSrcBits)[j * cx];

       unsigned char a1, a2;

       for( i = 0; i < cx; ++i )
       {
          a1 = pbSrcRGB[ 3 ];

          if( a1 != 0 )
          {
             a1 = alpha * ( ( a1 * 100 ) / 255 ) / 100;
             a2 = 255 - a1;

             pbSrcRGB[ 0 ] = ( ( pbDestRGB[ 0 ] * a2 ) + ( pbSrcRGB[ 0 ] * a1 ) ) >> 8;
             pbSrcRGB[ 1 ] = ( ( pbDestRGB[ 1 ] * a2 ) + ( pbSrcRGB[ 1 ] * a1 ) ) >> 8;
             pbSrcRGB[ 2 ] = ( ( pbDestRGB[ 2 ] * a2 ) + ( pbSrcRGB[ 2 ] * a1 ) ) >> 8;
          }
          else
          {
             pbSrcRGB[ 0 ] = pbDestRGB[ 0 ];
             pbSrcRGB[ 1 ] = pbDestRGB[ 1 ];
             pbSrcRGB[ 2 ] = pbDestRGB[ 2 ];
          }
          pbSrcRGB += 4;
          pbDestRGB += 4;
       }
    }

    dc = CreateCompatibleDC( NULL );

    dcOld = (HBITMAP) SelectObject(dc, hbmSrc);

    if (!BitBlt(dcDest, x, y, cx, cy, dc, 0, 0, SRCCOPY))
        return FALSE;

    DeleteDC(dc);
    DeleteObject(hbmSrc);
    DeleteObject(hbmDest);

    return TRUE;
}

HB_FUNC( ABPAINT )
{
   HDC hDC = ( HDC ) hb_parnl( 1 );
   HDC hDCComp = CreateCompatibleDC( hDC );
   BITMAP bm;
   HGDIOBJ hOldBmp = SelectObject( hDCComp, ( HBITMAP ) hb_parnl( 4 ) );

   GetObject( ( HBITMAP ) hb_parnl( 4 ), sizeof( BITMAP ), ( LPSTR ) &bm );
   AlphaBlendU( hDC, hb_parnl( 2 ), hb_parnl( 3 ), bm.bmWidth, bm.bmHeight, hDCComp,
                0, 0, bm.bmWidth, bm.bmHeight, hb_parnl( 5 ) );

   SelectObject( hDCComp, hOldBmp );
   DeleteDC( hDCComp );
}
 

Example:
Code: Select all  Expand view

ABPaint( hDC, 10, 10, hBitmap, 200 )
 

screenshot using ABPaint() with FWPPC in Windows Mobile:
Image

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Sun Aug 30, 2009 11:03 am
by Silvio
thanks Antonio.
Isee your sample picture...how you made these buttons?

Re: AlphaBlend in Windows Mobile / WinCE

PostPosted: Sun Aug 30, 2009 12:16 pm
by Antonio Linares
Silvio,

A graphics designer did them using photoshop