AlphaBlend in Windows Mobile / WinCE

AlphaBlend in Windows Mobile / WinCE

Postby Antonio Linares » Sat Apr 11, 2009 9:47 am

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  RUN

#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
 
regards, saludos

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

Re: AlphaBlend in Windows Mobile / WinCE

Postby Antonio Linares » Sat Apr 11, 2009 1:47 pm

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  RUN

#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
regards, saludos

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

Re: AlphaBlend in Windows Mobile / WinCE

Postby Otto » Sun Apr 19, 2009 8:54 pm

Hello Antonio,
which version of FWPPC has ABPaint?
Best regards,
Otto
error LNK2001: unresolved external symbol HB_FUN_ABPAINT
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: AlphaBlend in Windows Mobile / WinCE

Postby Antonio Linares » Tue Apr 21, 2009 7:39 am

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 :-)
regards, saludos

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

Re: AlphaBlend in Windows Mobile / WinCE

Postby Silvio » Fri Aug 28, 2009 12:19 am

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

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: AlphaBlend in Windows Mobile / WinCE

Postby Antonio Linares » Fri Aug 28, 2009 7:53 am

Silvio,

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

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

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

Re: AlphaBlend in Windows Mobile / WinCE

Postby mmercado » Fri Aug 28, 2009 6:36 pm

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
manuelmercado at prodigy dot net dot mx
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: AlphaBlend in Windows Mobile / WinCE

Postby Silvio » Sun Aug 30, 2009 7:09 am

Antonio,
My fwppc not have ABPaint() function!
It is the same of fwh?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: AlphaBlend in Windows Mobile / WinCE

Postby Antonio Linares » Sun Aug 30, 2009 7:44 am

This is the source code for ABPaint() for FWPPC:
Code: Select all  Expand view  RUN

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  RUN

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

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

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

Re: AlphaBlend in Windows Mobile / WinCE

Postby Silvio » Sun Aug 30, 2009 11:03 am

thanks Antonio.
Isee your sample picture...how you made these buttons?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: AlphaBlend in Windows Mobile / WinCE

Postby Antonio Linares » Sun Aug 30, 2009 12:16 pm

Silvio,

A graphics designer did them using photoshop
regards, saludos

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


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 6 guests