FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour cPS in bPainted
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
cPS in bPainted
Posted: Sat Aug 24, 2013 08:47 PM

It seems that cPS parameter provided to bPainted doesn't have the expected data. Can you confirm this? If yes, any fix?

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sat Aug 24, 2013 09:05 PM
Enrico,

It should have it as see how it gets built:

Code (fw): Select all Collapse
HB_FUNC( BEGINPAINT ) // ( hWnd, @cPS ) --> hDC
{
   PAINTSTRUCT ps;
   HDC hDC   = BeginPaint( ( HWND ) hb_parnl( 1 ), &ps );

   hb_storclen( ( char * ) &ps, sizeof( PAINTSTRUCT ), 2 );
   hb_retnl( ( LONG ) hDC );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sat Aug 24, 2013 09:06 PM

Enrico,

There is a working example managing cPS at FWH\samples\formdes.prg

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: cPS in bPainted
Posted: Sat Aug 24, 2013 09:19 PM
Antonio,

Antonio Linares wrote:Enrico,

There is a working example managing cPS at FWH\samples\formdes.prg


That's exactly what I was trying to do but unfortunately DrawGrid() makes no use of cPS parameter. :-)

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sat Aug 24, 2013 09:34 PM
Enrico,

Have you tried to modify DrawGrid() this way ?

Code (fw): Select all Collapse
HB_FUNC( DRAWGRID ) // hWnd, hDC, @cPS, wGridX, wGridY
{
   WORD wRow, wCol;
   #ifdef _WIN64
      HDC hDC   = ( HDC ) hb_parnll( 2 );
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #else   
      HDC hDC   = ( HDC ) hb_parnl( 2 );
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #endif
   WORD wGridX = hb_parni( 4 );
   WORD wGridY = hb_parni( 5 );
   RECT rc;
   WORD wWidth, wHeight;
   PAINTSTRUCT ps;
   
   memcpy( &ps, hb_parc( 3 ), sizeof( PAINTSTRUCT ) );

   GetWindowRect( hWnd, &rc );
   wWidth  = rc.right - rc.left + 1;
   wHeight = rc.bottom - rc.top + 1;

   for( wRow = 0; wRow <= wHeight; wRow += wGridX )
      for( wCol = 0; wCol <= wWidth; wCol += wGridY )
         SetPixel( hDC, wCol, wRow, 0 );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: cPS in bPainted
Posted: Sat Aug 24, 2013 09:51 PM
Antonio,

Antonio Linares wrote:Enrico,

Have you tried to modify DrawGrid() this way ?


Yes, but ps.rcPaint.top and ps.rcPaint.left are always zero, unless I'm missing something.

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 11:20 AM

Enrico,

ps.rcPaint.bottom and ps.rcPaint.right are non zero, so they seem valid.

Going to check top and left...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 11:22 AM
Enrico,

They are zero but this code seems to work fine:

Code (fw): Select all Collapse
HB_FUNC( DRAWGRID ) // hWnd, hDC, @cPS, wGridX, wGridY
{
   WORD wRow, wCol;
   #ifdef _WIN64
      HDC hDC   = ( HDC ) hb_parnll( 2 );
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #else   
      HDC hDC   = ( HDC ) hb_parnl( 2 );
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #endif
   WORD wGridX = hb_parni( 4 );
   WORD wGridY = hb_parni( 5 );
   PAINTSTRUCT ps;
   
   memcpy( &ps, hb_parc( 3 ), sizeof( PAINTSTRUCT ) );

   for( wRow = 0; wRow <= ps.rcPaint.bottom; wRow += wGridX )
      for( wCol = 0; wCol <= ps.rcPaint.right; wCol += wGridY )
         SetPixel( hDC, wCol, wRow, 0 );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 11:38 AM
Antonio,

Antonio Linares wrote:Enrico,

They are zero but this code seems to work fine:


Yes, but the benefit is greatly reduced if the area to be repainted always starts from 0, 0... :-)

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 11:51 AM

That is what Windows is providing us :-(

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 12:55 PM
Antonio,

Antonio Linares wrote:That is what Windows is providing us :-)


I'm not so sure... how FWH provides cPS to bPainted codeblock?

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 01:01 PM
Enrico,

cPS is obtained here:
Code (fw): Select all Collapse
METHOD _BeginPaint() CLASS TWindow

   local cPS

   if ::nPaintCount == nil
      ::nPaintCount = 1
   else
      ::nPaintCount++
   endif

   ::hDC = BeginPaint( ::hWnd, @cPS )
   ::cPS = cPS

return nil


and used from bPainted:
Code (fw): Select all Collapse
      if ValType( ::bPainted ) == "B"
         uVal = Eval( ::bPainted, ::hDC, ::cPS, Self )
      endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 01:11 PM
Antonio,

Antonio Linares wrote:Enrico,

cPS is obtained here:
Code (fw): Select all Collapse
METHOD _BeginPaint() CLASS TWindow

   local cPS

   if ::nPaintCount == nil
      ::nPaintCount = 1
   else
      ::nPaintCount++
   endif

   ::hDC = BeginPaint( ::hWnd, @cPS )
   ::cPS = cPS

return nil


and used from bPainted:
Code (fw): Select all Collapse
      if ValType( ::bPainted ) == "B"
         uVal = Eval( ::bPainted, ::hDC, ::cPS, Self )
      endif


It looks correct, thank you. Any ideas on how to speed up DrawGrid() function?

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 01:40 PM

Enrico,

Here it seems fast enough, I am using a Core 2 Duo

It could be speed up using a brush instead of calling SetPixel()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: cPS in bPainted
Posted: Sun Aug 25, 2013 01:48 PM
Antonio,

Antonio Linares wrote:Enrico,

Here it seems fast enough, I am using a Core 2 Duo

It could be speed up using a brush instead of calling SetPixel()


Interesting... any little sample? :-)

EMG