cPS in bPainted

cPS in bPainted

Postby Enrico Maria Giordano » Sat Aug 24, 2013 8: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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: cPS in bPainted

Postby Antonio Linares » Sat Aug 24, 2013 9:05 pm

Enrico,

It should have it as see how it gets built:

Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: cPS in bPainted

Postby Antonio Linares » Sat Aug 24, 2013 9:06 pm

Enrico,

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

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

Re: cPS in bPainted

Postby Enrico Maria Giordano » Sat Aug 24, 2013 9: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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: cPS in bPainted

Postby Antonio Linares » Sat Aug 24, 2013 9:34 pm

Enrico,

Have you tried to modify DrawGrid() this way ?

Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: cPS in bPainted

Postby Enrico Maria Giordano » Sat Aug 24, 2013 9: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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: cPS in bPainted

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

Re: cPS in bPainted

Postby Antonio Linares » Sun Aug 25, 2013 11:22 am

Enrico,

They are zero but this code seems to work fine:

Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: cPS in bPainted

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: cPS in bPainted

Postby Antonio Linares » Sun Aug 25, 2013 11:51 am

That is what Windows is providing us :-(
regards, saludos

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

Re: cPS in bPainted

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: cPS in bPainted

Postby Antonio Linares » Sun Aug 25, 2013 1:01 pm

Enrico,

cPS is obtained here:
Code: Select all  Expand view
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: Select all  Expand view
     if ValType( ::bPainted ) == "B"
         uVal = Eval( ::bPainted, ::hDC, ::cPS, Self )
      endif
regards, saludos

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

Re: cPS in bPainted

Postby Enrico Maria Giordano » Sun Aug 25, 2013 1:11 pm

Antonio,

Antonio Linares wrote:Enrico,

cPS is obtained here:
Code: Select all  Expand view
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: Select all  Expand view
     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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: cPS in bPainted

Postby Antonio Linares » Sun Aug 25, 2013 1: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: cPS in bPainted

Postby Enrico Maria Giordano » Sun Aug 25, 2013 1: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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

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