Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby concentra » Wed Nov 09, 2011 11:13 am

Antonio, when I try to link a program with FW, Harbour and MinGW, it states that the folowing functions are missing :
MoveTo, GetTextExtent, DrawMasked, DrawBitmap and MaskRegion.
Where can I find them ?
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby Antonio Linares » Wed Nov 09, 2011 12:22 pm

Concentra,

Are you calling FWH MoveTo() or directly calling Windows API MoveTo() from C code ?
regards, saludos

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

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby concentra » Wed Nov 09, 2011 12:46 pm

I am trying to compile/link Manuel Mercado's TsBrowse 9 with FW + Harbour + MinGW.
Part of this is compiling a C program that calls MoveTo.
The part of the code that does it is
Code: Select all  Expand view
static void GoToPoint( HDC hDC, int ix, int iy )
{
   #ifdef __FLAT__
      POINT pt;
      MoveToEx( hDC, ix, iy, &pt ) ;
   #else
      MoveTo( hDC, ix, iy );
   #endif
}


[[]]
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby Antonio Linares » Wed Nov 09, 2011 3:32 pm

Add these lines to the top of your code, below #include <Windows.h>

Code: Select all  Expand view

#ifdef __GNUC__
   WINBASEAPI BOOL WINAPI MoveTo( HDC, int, int );
   ... others used
#endif
 
regards, saludos

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

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby concentra » Wed Nov 09, 2011 3:55 pm

Adding that lines i still get:
Code: Select all  Expand view
../TSBFUNCS.o:TSBFUNCS.C:(.text+0x94): undefined reference to `MoveTo(HDC__*, int, int)@12

I managed to add a source code for MoveTo I found in other place and it linked, but I don't know if it works yet.
Code: Select all  Expand view
//----------------------------------------------------------------------------//

DWORD MoveTo( HDC hDC, int x, int y )
{
   POINT pt;
   DWORD dw;

   MoveToEx( hDC, x, y, &pt );

   dw = pt.x + ( pt.y >> 16 );
   return dw;
}

//----------------------------------------------------------------------------//
 

I was unable to test yet because parameters order changed from v7 to v9 and I need to manage this before I can test.
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby Antonio Linares » Wed Nov 09, 2011 5:41 pm

Yes, it is right, as MoveTo() does not exist on Windows 32 and 64 :-)
regards, saludos

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

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby concentra » Wed Nov 09, 2011 6:06 pm

Antonio, In order to link, I also needed to include the source of DrawMasked(), DrawBitmap() from \FWH\source\winapi\bmpdraw.c and MaskRegion() from \FWH\source\function\fwbmp.c.

Wasn't this to be in fivehg or fivehgc libs ?
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby Antonio Linares » Wed Nov 09, 2011 7:29 pm

What errors do you get from the linker ?
regards, saludos

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

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby concentra » Thu Nov 10, 2011 12:18 pm

Code: Select all  Expand view
../TSBFUNCS.o:TSBFUNCS.C:(.text+0x251): undefined reference to `MoveTo(HDC__*, int, int)'
../TSBFUNCS.o:TSBFUNCS.C:(.text+0x105e): undefined reference to `GetTextExtent(HDC__*, char const*, int)'

../TSBFUNCS.o:TSBFUNCS.C:(.text+0x144a): undefined reference to `DrawMasked(HDC__*, HBITMAP__*, unsigned short, unsigned short)'
../TSBFUNCS.o:TSBFUNCS.C:(.text+0x1d9d): undefined reference to `DrawBitmap(HDC__*, HBITMAP__*, unsigned short, unsigned short, unsigned short, unsigned short, unsigned long)'

../TSBFUNCS.o:TSBFUNCS.C:(.text+0x1f2f): undefined reference to `DrawBitmap(HDC__*, HBITMAP__*, unsigned short, unsigned short, unsigned short, unsigned short, unsigned long)'
../TSBFUNCS.o:TSBFUNCS.C:(.text+0x22a1): undefined reference to `DrawBitmap(HDC__*, HBITMAP__*, unsigned short, unsigned short, unsigned short, unsigned short, unsigned long)'

../TSBFUNCS.o:TSBFUNCS.C:(.text+0x22f4): undefined reference to `MaskRegion(HDC__*, tagRECT*, unsigned long, unsigned long)'
../TSBFUNCS.o:TSBFUNCS.C:(.text+0x235e): undefined reference to `DrawBitmap(HDC__*, HBITMAP__*, unsigned short, unsigned short, unsigned short, unsigned short, unsigned long)'

../TSBFUNCS.o:TSBFUNCS.C:(.text+0x23af): undefined reference to `MaskRegion(HDC__*, tagRECT*, unsigned long, unsigned long)'
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby Antonio Linares » Thu Nov 10, 2011 1:53 pm

Please post the complete source code of TSBFUNCS.C
regards, saludos

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

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby concentra » Thu Nov 10, 2011 4:44 pm

Antonio, this a modified version of TsBrowse 9 that is in http://code.google.com/p/fivewin-contributions/downloads/list
In the end, the functions I copied from other source files are commented.
If I uncomment that functions the application links and TsBrowse runs, apparently Ok.

Code: Select all  Expand view
/***************************************************************

This file contains the special painting routines used by TSBrowse Class
Last update: November 30th, 2009

***************************************************************/


#include <hbApi.h>    /* set your own path if needed */
#include <WinTen.h>   /* set your own path if needed */
#include <Windows.h>
#include <shellapi.h>
#include <StdLib.h>
/*
#ifdef __GNUC__
   WINBASEAPI BOOL WINAPI MoveTo( HDC, int, int );
   WINBASEAPI BOOL WINAPI GetTextExtent( HDC, LPCSTR, int ) ;
   WINBASEAPI BOOL WINAPI DrawBitmap( HDC, HBITMAP, WORD wCol, WORD wRow, WORD wWidth, WORD wHeight, DWORD dwRaster ) ;
   WINBASEAPI BOOL WINAPI DrawMasked( HDC hdc, HBITMAP hbm, WORD y, WORD x ) ;
   WINBASEAPI BOOL WINAPI MaskRegion( HDC hDC, RECT * rct, COLORREF cTransparent, COLORREF cBackground ) ;
#endif
*/

void WndBoxDraw( HDC, LPRECT, HPEN, HPEN, int, BOOL ) ;
void cDrawCursor( HWND, LPRECT, long, COLORREF ) ;
void DrawCheck( HDC, LPRECT, HPEN, int, BOOL ) ;
DWORD GetTextExtent( HDC, LPCSTR, int ) ;
DWORD MoveTo( HDC hDC, int x, int y );
void DrawBitmap( HDC, HBITMAP, WORD wCol, WORD wRow, WORD wWidth, WORD wHeight, DWORD dwRaster ) ;
void DrawMasked( HDC hdc, HBITMAP hbm, WORD y, WORD x ) ;
void MaskRegion( HDC hDC, RECT * rct, COLORREF cTransparent, COLORREF cBackground ) ;
static void GoToPoint( HDC, int, int ) ;
static void DegradColor( HDC, RECT *, COLORREF, signed long ) ;

//---------------------------------------------------------------------------//

HB_FUNC( TSDRAWCELL )
{
   HWND hWnd        = (HWND) hb_parni( 1 ) ;
   HDC  hDC         = (HDC) hb_parni( 2 ) ;
   int  nRow        = hb_parni( 3 ) ;
   int  nColumn     = hb_parni( 4 ) ;
   int  nWidth      = hb_parni( 5 ) ;
   LPSTR cData      = (LPSTR) hb_parc( 6 )  ;
   int  nLen        = hb_parclen( 6 ) ;
   DWORD nAlign     = hb_parnl( 7 ) ;
   COLORREF clrFore = hb_parnl( 8 ) ;
   COLORREF clrBack = hb_parnl( 9 ) ;
   HFONT hFont      = (HFONT) hb_parni( 10 ) ;
   HBITMAP hBitMap  = (HBITMAP) hb_parni( 11 ) ;
   int nHeightCell  = hb_parni( 12 ) ;
   BOOL b3DLook     = hb_parl( 13 ) ;
   int nLineStyle   = hb_parni( 14 ) ;
   COLORREF clrLine = hb_parnl( 15 ) ;
   int nHeadFoot    = hb_parni( 16 ) ;
   int nHeightHead  = hb_parni( 17 ) ;
   int nHeightFoot  = hb_parni( 18 ) ;
   int nHeightSuper = hb_parni( 19 ) ;
   BOOL bAdjBmp     = hb_parl( 20 ) ;
   BOOL bMultiLine  = hb_parl( 21 ) ;
   int nVAlign      = hb_parni( 22 ) ;
   int nVertText    = hb_parni( 23 ) ;
   COLORREF clrTo   = hb_parnl( 24 ) ;
   BOOL bOpaque     = hb_parl( 25 ) ;
   HBRUSH wBrush    = (HBRUSH) hb_parnl( 26 ) ;

   #define S_LOG          0x0080
   #define ISLOGICAL( s ) ( hb_param( s, S_LOG )    != NULL )

   BOOL b3DInv      = ( ISLOGICAL( 27 ) ? ! hb_parl( 27 ) : FALSE ) ;
   BOOL b3D         = ( ISLOGICAL( 27 ) ? TRUE : FALSE ) ;
   COLORREF nClr3DL = hb_parnl( 28 ) ;
   COLORREF nClr3DS = hb_parnl( 29 ) ;
   long lCursor     = hb_parnl( 30 ) ;

   int ixLayOut     = HIWORD( nAlign ) ;
   int iAlign       = LOWORD( nAlign ) ;
   int iTxtW        = LOWORD( GetTextExtent( hDC, cData, nLen ) ) ;
   BOOL bGrid       = ( nLineStyle > 0 ? TRUE : FALSE ) ;
   BOOL bHeader     = ( nHeadFoot == 1 ? TRUE : FALSE ) ;
   BOOL bFooter     = ( nHeadFoot == 2 ? TRUE : FALSE ) ;
   BOOL bSuper      = ( nHeadFoot == 3 ? TRUE : FALSE ) ;
   BOOL bChecked    = ( nVertText == 3 ? TRUE : FALSE ) ;
   BOOL bBrush      = ( wBrush ? TRUE : FALSE ) ;
   BOOL bDegrad     = ( bBrush || clrTo == clrBack ? FALSE : TRUE ) ;
   HFONT hOldFont ;
   BOOL bDestroyDC  = FALSE ;
   HPEN hGrayPen    = CreatePen( PS_SOLID, 1, clrLine );
   HPEN hWhitePen   = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) ) ;

   RECT rct ;
   BITMAP bm ;
   int nTop, nLeft, nBkOld, iFlags ;

   if( ! hDC )
   {
      bDestroyDC = TRUE ;
      hDC = GetDC( hWnd ) ;
   }

   if( hFont )
      hOldFont = (HFONT) SelectObject( hDC, hFont ) ;

   GetClientRect( hWnd, &rct ) ;
   SetTextColor( hDC, clrFore ) ;
   SetBkColor( hDC, clrBack ) ;

   if( nRow == 0 )
      rct.top = ( bHeader ? nHeightSuper - ( nHeightSuper ? 1 : 0 ) : 0 ) ;
   else
      rct.top = ( bFooter ? rct.bottom - nHeightFoot + 1 : nHeightHead + nHeightSuper - ( nHeightSuper ? 1 : 0 ) +
                  ( nHeightCell * ( nRow - 1 ) ) ) ;

   rct.bottom = rct.top + ( bHeader ? nHeightHead :( bSuper ? nHeightSuper : nHeightCell ) - 1 ) ;

   /* Don't let left side go beyond rct.right of Client Rect. */
   if( nColumn - ( rct.right - rct.left ) <= 0 )
   {
      rct.left = nColumn ;

        /* if nWidth == -1 or -2, it indicates the last column so go to limit,
         Don't let right side go beyond rct.right of Client Rect. */

      if( ( nWidth >= 0 ) && ((rct.left + nWidth - rct.right) <= 0) )  // negative values have different meanings
         rct.right = rct.left + nWidth ;

      if( ! bDegrad )
      {
         rct.bottom += ( bHeader ? 0 : 1 ) ;
         rct.right += 1 ;

         if( ! bBrush )
            ExtTextOut( hDC, rct.left, rct.top, ETO_OPAQUE | ETO_CLIPPED, &rct, "", 0, 0  ) ;
         else
            FillRect( hDC, &rct, wBrush ) ;

         rct.bottom -= ( bHeader ? 0 : 1 ) ;
         rct.right -= 1 ;
      }
      else
         DegradColor( hDC, &rct, clrBack, clrTo  ) ;

      if( hBitMap )
      {

         if( ! bAdjBmp )
         {
             GetObject( hBitMap, sizeof( BITMAP ), ( LPSTR ) &bm ) ;
             nTop = rct.top + ( ( rct.bottom - rct.top + 1 ) / 2 ) - ( bm.bmHeight / 2 ) ;

             switch( ixLayOut ) // bitmap layout x coordinate
             {
               case 0: // column left
                  nLeft = rct.left ;
                  break ;
               case 1: // column center (text -if any- may overwrite the bitmap)
                  nLeft = rct.left + ( ( rct.right - rct.left + 1 ) / 2 ) -
                          ( bm.bmWidth / 2 ) - 1 ;
                  break ;
               case 2: // column right
                  nLeft = rct.right - ( bm.bmWidth + 1 ) ;
                  break ;
               case 3: // left of centered text
                  nLeft = max( rct.left, rct.left + ( ( rct.right - rct.left + 1 ) / 2 ) -
                          ( iTxtW / 2 ) - bm.bmWidth - 2 ) ;
                  break ;
               case 4: // right of centered text
                  nLeft = rct.left + ( ( rct.right - rct.left + 1 ) / 2 ) + ( iTxtW / 2 ) + 2 ;
                  break ;
               default: // a value > 4 means specific pixel location from column left
                  nLeft = rct.left + ixLayOut ;
                  break ;
             }
         }
         else
         {
            nTop  = rct.top ;
            nLeft = rct.left ;
         }

         if( b3DLook )
         {
            if( bAdjBmp )
            {
               nTop  = rct.top + 1 ;
               DrawBitmap( hDC, hBitMap,  nTop, rct.left - 1, rct.right - rct.left + 1,
                           rct.bottom - rct.top - 1, 0 ) ;
               hBitMap = 0 ;

               if( ! bOpaque )
                  MaskRegion( hDC, &rct, GetPixel( hDC, nLeft, nTop ), GetBkColor( hDC ) ) ;
            }
            else
               if( bOpaque )
                  DrawBitmap( hDC, hBitMap, nTop, nLeft, 0, 0, 0 ) ;
               else
                  DrawMasked( hDC, hBitMap, nTop, nLeft ) ;
         }
         else
         {
            if( bAdjBmp)
            {
               DrawBitmap( hDC, hBitMap,  rct.top, rct.left - 2, rct.right - rct.left + 3,
                           rct.bottom - rct.top - 1, 0 ) ;
               hBitMap = 0 ;

               if( ! bOpaque )
                  MaskRegion( hDC, &rct, GetPixel( hDC, nLeft, nTop ), GetBkColor( hDC ) ) ;
            }
            else
               if( bOpaque )
                  DrawBitmap( hDC, hBitMap, nTop, nLeft, 0, 0, 0 ) ;
               else
                  DrawMasked( hDC, hBitMap, nTop, nLeft ) ;
         }
      }

      if( nLen )
      {
         if( iAlign == DT_LEFT )
            rct.left += ( 2 + ( hBitMap && ixLayOut == 0 ? bm.bmWidth + 1 : 0 ) ) ;

         if( iAlign == DT_RIGHT )
            rct.right -= ( 2 + ( hBitMap && ixLayOut == 2 ? bm.bmWidth + 1 : 0 ) ) ;

         if( nVertText == 1 )
         {
            rct.right  += ( 4 * nLen ) ;
            rct.bottom += 10 ;
         }

         iFlags = iAlign | DT_NOPREFIX | nVAlign * 4 | ( bMultiLine && nVAlign < 2 ? 0 : DT_SINGLELINE ) ;

         if( ( nVertText == 3 || nVertText == 4 ) )
            DrawCheck( hDC, &rct, hWhitePen, iAlign, bChecked ) ;
         else
         {
            nBkOld = SetBkMode( hDC, TRANSPARENT ) ;

            if( b3D )
            {
               rct.top    -= 1 ;
               rct.left   -= 1 ;
               rct.bottom -= 1 ;
               rct.right  -= 1 ;
               SetTextColor( hDC, b3DInv ? nClr3DS : nClr3DL ) ;
               DrawTextEx( hDC, cData, nLen, &rct, iFlags, NULL ) ;

               rct.top    += 2 ;
               rct.left   += 2 ;
               rct.bottom += 2 ;
               rct.right  += 2 ;
               SetTextColor( hDC, b3DInv ? nClr3DL : nClr3DS ) ;
               DrawTextEx( hDC, cData, nLen, &rct, iFlags, NULL ) ;

               rct.top    -= 1 ;
               rct.left   -= 1 ;
               rct.bottom -= 1 ;
               rct.right  -= 1 ;
               SetTextColor( hDC, clrFore ) ;
            }

            DrawTextEx( hDC, cData, nLen, &rct, iFlags, NULL ) ;
            SetBkMode( hDC, nBkOld ) ;
         }

         if( iAlign == DT_LEFT )
            rct.left -= ( 2 + ( hBitMap && ixLayOut == 0 ? bm.bmWidth + 1 : 0 ) ) ;

         if( iAlign == DT_RIGHT )
            rct.right += ( 2 + ( hBitMap && ixLayOut == 2 ? bm.bmWidth + 1 : 0 ) ) ;

         if( nVertText == 1 )
         {
            rct.right -= ( 4 * nLen ) ;
            rct.bottom -= 10 ;
         }
      }

      if( b3DLook )
      {
         bHeader = ( bSuper ? bSuper : bHeader ) ;

         if( ( nWidth != -2 ) && bGrid )   // -1 draw gridline in phantom column; -2 don't draw gridline in phantom column
            WndBoxDraw( hDC, &rct, hWhitePen, hGrayPen, b3DLook ? 4 : nLineStyle, bHeader ) ;

         if( lCursor )
            cDrawCursor( hWnd, &rct, lCursor, clrFore ) ;

      }
      else
      {
         bHeader = ( bFooter ? bFooter : ( bHeader || bSuper ) ) ;

         if( ( nWidth != -2 ) && bGrid )   // -1 draw gridline in phantom column; -2 don't draw gridline in phantom column
               WndBoxDraw( hDC, &rct, hGrayPen, hGrayPen, nLineStyle, bHeader ) ;

         if( lCursor )
            cDrawCursor( hWnd, &rct, lCursor, clrFore ) ;
      }

   }

   DeleteObject( hGrayPen ) ;
   DeleteObject( hWhitePen ) ;
   if( hFont )
      SelectObject( hDC, hOldFont ) ;

   if( bDestroyDC )
      ReleaseDC( hWnd, hDC ) ;
}

//--------------------------------------------------------------------------------------------------------------------//

void WndBoxDraw( HDC hDC, RECT * rct, HPEN hPUpLeft, HPEN hPBotRit, int nLineStyle, \
                 BOOL bHeader )

{
   HPEN hOldPen  = (HPEN) SelectObject( hDC, hPUpLeft ) ;
   HPEN hBlack   = CreatePen( PS_SOLID, 1, 0 ) ;

   switch( nLineStyle )
   {
      case 0 :
         break ;
      case 1 :
         SelectObject( hDC, hPBotRit ) ;
         GoToPoint( hDC, rct->left, rct->bottom - ( bHeader ? 1 : 0 ) ) ;
         LineTo( hDC, rct->right - 1, rct->bottom - ( bHeader ? 1 : 0 ) ) ;
         LineTo( hDC, rct->right - 1, rct->top - 1 ) ;
         if( bHeader )
            LineTo( hDC, rct->left - 1, rct->top - 1 ) ;
         break ;
      case 2 :
         SelectObject( hDC, hPBotRit ) ;
         GoToPoint( hDC, rct->right - 1, rct->bottom ) ;
         LineTo( hDC, rct->right - 1, rct->top - 1 ) ;
         break ;
      case 3 :
         SelectObject( hDC, hPBotRit ) ;
         GoToPoint( hDC, rct->left, rct->bottom ) ;
         LineTo( hDC, rct->right, rct->bottom ) ;
         break ;
      case 4 :
         SelectObject( hDC, hPUpLeft ) ;
         GoToPoint( hDC, rct->left, rct->bottom ) ;
         LineTo( hDC, rct->left, rct->top ) ;
         LineTo( hDC, rct->right , rct->top ) ;
         SelectObject( hDC, hPBotRit ) ;
         GoToPoint( hDC, rct->left, rct->bottom - ( bHeader ? 1 : 0 ) ) ;
         LineTo( hDC, rct->right - 1, rct->bottom - ( bHeader ? 1 : 0 ) ) ;
         LineTo( hDC, rct->right - 1, rct->top - 1 ) ;
         break ;
      case 5 :
         rct->top += 1 ;
         rct->left += 1 ;
         rct->bottom -= 1 ;
         rct->right -= 1 ;
         DrawFocusRect( hDC, rct );
         break ;
   }

   SelectObject( hDC, hOldPen );
   DeleteObject( hBlack );
}

//---------------------------------------------------------------------------//

HB_FUNC( TSBRWSCROLL )
{
   HWND hWnd        = (HWND) hb_parni( 1 ) ;
   int iRows        = hb_parni( 2 ) ;
   HFONT hFont      = (HFONT) hb_parni( 3 ) ;
   int nHeightCell  = hb_parni( 4 ) ;
   int nHeightHead  = hb_parni( 5 ) ;
   int nHeightFoot  = hb_parni( 6 ) ;
   int nHeightSuper = hb_parni( 7 ) ;

   HFONT hOldFont ;
   HDC hDC = GetDC( hWnd ) ;
   RECT rct;

   if( hFont )
      hOldFont = (HFONT) SelectObject( hDC, hFont ) ;

   GetClientRect( hWnd, &rct ) ;

   rct.top    += ( nHeightHead + nHeightSuper - ( nHeightSuper ? 1 : 0 ) ) ;  // exclude heading from scrolling
   rct.bottom -= nHeightFoot ;                     // exclude footing from scrolling
   rct.bottom -= ( ( rct.bottom - rct.top + 1 ) % nHeightCell );  // exclude unused portion at bottom
   ScrollWindowEx( hWnd, 0, (int) -( nHeightCell * iRows ), 0, &rct, 0, 0, 0 );

   if( hFont )
      SelectObject( hDC, hOldFont );

   ReleaseDC( hWnd, hDC );
}

//----------------------------------------------------------------------------//

HB_FUNC( TSBRWHSCROLL )
{
   HWND hWnd  = (HWND) hb_parni( 1 ) ;
   WORD wCols = hb_parni( 2 ) ;
   int nLeft  = hb_parni( 3 ) ;
   int nRight = hb_parni( 4 ) ;

   HDC hDC    = GetDC( hWnd ) ;
   RECT rct;

   GetClientRect( hWnd, &rct ) ;

   if ( nLeft )
      rct.left = nLeft ;

   if ( nRight )
      rct.right = nRight ;

   ScrollWindowEx( hWnd, wCols, 0, 0, &rct, 0, 0, 0 ) ;

   ReleaseDC( hWnd, hDC ) ;
}


//---------------------------------------------------------------------------//

HB_FUNC( ROWFROMPIX )
{
   HWND hWnd = ( HWND ) hb_parni( 1 ) ;
   int iPixR = hb_parni( 2 ) ;
   int iCell = hb_parni( 3 ) ;
   int iHead = hb_parni( 4 ) ;
   int iFoot = hb_parni( 5 ) ;
   int iSupH = hb_parni( 6 ) ;

   RECT rct ;
   int iRow ;

   GetClientRect( hWnd, &rct ) ;

   if( iPixR <= ( rct.top + iHead + iSupH ) )
      iRow = 0 ;
   else
      if( iPixR >= ( rct.bottom - iFoot ) )
         iRow = -1 ;
      else
      {
         rct.top += ( iHead + iSupH ) ;
         iRow = ( ( iPixR - rct.top ) / iCell ) + 1 ;
      }

   hb_retni( iRow ) ;
}

//---------------------------------------------------------------------------//

HB_FUNC( SBGETHEIGHT )
{
   HWND  hWnd  = (HWND) hb_parni( 1 ) ;
   HFONT hFont = (HFONT) hb_parni( 2 ) ;
   int  iTotal = hb_parni( 3 )  ;

   TEXTMETRIC tm ;

   RECT  rct ;
   HDC   hDC = GetDC( hWnd ) ;
   HFONT hOldFont ;
   LONG  lTotHeight, lReturn ;

   if( iTotal < 2 )
   {
      if( hFont )
         hOldFont = (HFONT) SelectObject( hDC, hFont ) ;
      GetTextMetrics( hDC, &tm ) ;
      if( hFont )
         SelectObject( hDC, hOldFont ) ;
      ReleaseDC( hWnd, hDC ) ;
      lReturn = ( iTotal == 1 ? tm.tmAveCharWidth : tm.tmHeight ) ;
      hb_retnl( lReturn ) ;
   }
   else
   {
      GetWindowRect( hWnd, &rct ) ;
      lTotHeight = rct.bottom - rct.top + 1 ;
      ReleaseDC( hWnd, hDC ) ;
      hb_retnl( lTotHeight ) ;
   }
}

//----------------------------------------------------------------------------//

HB_FUNC( COUNTROWS )
{
   HWND hWnd = ( HWND ) hb_parni( 1 ) ;
   int iCell = hb_parni( 2 ) ;
   int iHead = hb_parni( 3 ) ;
   int iFoot = hb_parni( 4 ) ;
   int iSupH = hb_parni( 5 ) ;

   RECT rct ;
   int iRows, iFree ;

   GetClientRect( hWnd, &rct ) ;

   iFree = rct.bottom - rct.top + 1 - iSupH - iHead - iFoot ;
   iRows = iFree / iCell ;

   hb_retni( iRows ) ;
}

//---------------------------------------------------------------------------//

HB_FUNC( SBMPHEIGHT ) // ( hBmp )
{
   HBITMAP hBmp  = (HBITMAP) hb_parni( 1 ) ;
   BITMAP bm ;

   GetObject( hBmp, sizeof( BITMAP ), ( LPSTR ) &bm ) ;

   hb_retni( bm.bmHeight ) ;
}

//---------------------------------------------------------------------------//

HB_FUNC( SBMPWIDTH )
{
   HBITMAP hBmp  = (HBITMAP) hb_parni( 1 ) ;
   BITMAP bm ;

   GetObject( hBmp, sizeof( BITMAP ), ( LPSTR ) &bm ) ;

   hb_retni( bm.bmWidth ) ;
}

//---------------------------------------------------------------------------//

void DrawCheck( HDC hDC, LPRECT rct, HPEN hWhitePen, int nAlign, BOOL bChecked )
{
   RECT lrct ;
   HPEN hOldPen ;
   HBRUSH hOldBrush ;

   HBRUSH hGrayBrush  = CreateSolidBrush( RGB( 192, 192, 192 ) ) ;
   HBRUSH hWhiteBrush = CreateSolidBrush( RGB( 255, 255, 255 ) ) ;
   HPEN hBlackPen     = CreatePen( PS_SOLID, 1, RGB( 0, 0, 0 ) ) ;
   HPEN hLGrayPen     = CreatePen( PS_SOLID, 1, RGB( 192, 192, 192 ) ) ;
   HPEN hGrayPen      = CreatePen( PS_SOLID, 1, RGB( 128, 128, 128 ) ) ;

   hOldBrush = (HBRUSH) SelectObject( hDC, hGrayBrush ) ;

   lrct.top = rct->top + ( ( ( rct->bottom - rct->top + 1 ) / 2 ) - 8 );

   switch( nAlign )
   {
      case 0:
         lrct.left = rct->left ;
         break ;
      case 1:
         lrct.left = rct->left + ( ( rct->right - rct->left + 1 ) / 2 ) - 8 ;
         break ;
      case 2:
         lrct.left = rct->right - 16 ;
         break ;
   }

   lrct.bottom = lrct.top + 16 ;
   lrct.right  = lrct.left + 16 ;

   lrct.left   -= 1 ;
   lrct.top    -= 1 ;
   lrct.right  += 1 ;
   lrct.bottom += 1 ;

   hOldPen = (HPEN) SelectObject( hDC, hBlackPen ) ;
   Rectangle( hDC, lrct.left, lrct.top, lrct.right, lrct.bottom ) ;

   lrct.left   += 1 ;
   lrct.top    += 1 ;
   lrct.right  -= 1 ;
   lrct.bottom -= 1 ;

   FillRect( hDC, &lrct, hGrayBrush ) ;

   lrct.top    += 2 ;
   lrct.left   += 2 ;
   lrct.right  -= 1 ;
   lrct.bottom -= 1 ;

   FillRect( hDC, &lrct, hWhiteBrush ) ;

   SelectObject( hDC, hOldBrush ) ;
   DeleteObject( hGrayBrush ) ;
   DeleteObject( hWhiteBrush ) ;

   lrct.right  -= 1 ;
   lrct.bottom -= 1 ;

   SelectObject( hDC, hGrayPen ) ;
   Rectangle( hDC, lrct.left, lrct.top, lrct.right, lrct.bottom ) ;

   lrct.top    += 1 ;
   lrct.left   += 1 ;
   lrct.right  -= 1 ;
   lrct.bottom -= 1 ;

   SelectObject( hDC, hBlackPen ) ;
   Rectangle( hDC, lrct.left, lrct.top, lrct.right, lrct.bottom ) ;

   lrct.top  += 1 ;
   lrct.left += 1 ;

   SelectObject( hDC, hWhitePen ) ;
   Rectangle( hDC, lrct.left, lrct.top, lrct.right, lrct.bottom ) ;

   lrct.top    += 1 ;
   lrct.right  -= 2 ;
   lrct.bottom -= 1 ;

   if( bChecked )
   {
      GoToPoint( hDC, lrct.right, lrct.top ) ;

      SelectObject( hDC, hBlackPen ) ;

      LineTo( hDC, lrct.right - 4 , lrct.bottom - 3 ) ;
      LineTo( hDC, lrct.right - 6, lrct.bottom - 5 ) ;

      GoToPoint( hDC, lrct.right, lrct.top + 1) ;
      LineTo( hDC, lrct.right - 4 , lrct.bottom - 2 ) ;
      LineTo( hDC, lrct.right - 6, lrct.bottom - 4 ) ;

      GoToPoint( hDC, lrct.right, lrct.top + 2) ;
      LineTo( hDC, lrct.right - 4 , lrct.bottom - 1 ) ;
      LineTo( hDC, lrct.right - 6, lrct.bottom - 3 ) ;
   }

   SelectObject( hDC, hOldPen ) ;
   DeleteObject( hGrayPen ) ;
   DeleteObject( hLGrayPen ) ;
   DeleteObject( hBlackPen ) ;
}

//----------------------------------------------------------------------------//

static void GoToPoint( HDC hDC, int ix, int iy )
{

   #ifdef __FLAT__
      POINT pt;
      MoveToEx( hDC, ix, iy, &pt ) ;
   #else
      MoveTo( hDC, ix, iy );
   #endif
}

//--------------------------------------------------------------------------------------------------------------------//

static void DegradColor( HDC hDC, RECT * rori, COLORREF cFrom, signed long cTo )
{
   float clr1r, clr1g, clr1b, clr2r, clr2g, clr2b ;
   float iEle, iRed, iGreen, iBlue ;
   BOOL bDir, bHoriz = cTo < 0 ;
   float iTot = ( ! bHoriz ? ( rori->bottom + 2 - rori->top ) : ( rori->right + 2 - rori->left ) ) ;
   RECT rct ;
   HBRUSH hOldBrush, hBrush ;

   rct.top = rori->top ;
   rct.left = rori->left ;
   rct.bottom = rori->bottom ;
   rct.right = rori->right ;

   clr1r = GetRValue( cFrom ) ;
   clr1g = GetGValue( cFrom ) ;
   clr1b = GetBValue( cFrom ) ;

   cTo   = ( cTo < 0 ? -cTo : cTo ) ;
   clr2r = GetRValue( cTo ) ;
   clr2g = GetGValue( cTo ) ;
   clr2b = GetBValue( cTo ) ;

   iRed   =  clr2r - clr1r ;
   iGreen =  clr2g - clr1g ;
   iBlue  =  clr2b - clr1b ;

   iRed   = ( iRed / iTot ) ;
   iGreen = ( iGreen / iTot ) ;
   iBlue  = ( iBlue / iTot ) ;

   iRed   = ( iRed < 0 ? -iRed : iRed ) ;
   iGreen = ( iGreen < 0 ? -iGreen : iGreen ) ;
   iBlue  = ( iBlue < 0 ? -iBlue : iBlue ) ;

   if( ! bHoriz )
      rct.bottom = rct.top + 1 ;
   else
      rct.right = rct.left + 1 ;

   hBrush = CreateSolidBrush( RGB( clr1r, clr1g, clr1b ) ) ;
   hOldBrush = (HBRUSH) SelectObject( hDC, hBrush ) ;
   FillRect( hDC, &rct, hBrush ) ;

   for( iEle = 1; iEle < iTot; iEle++ )
   {
         bDir = ( clr2r >= clr1r ? TRUE : FALSE ) ;
         if( bDir )
            clr1r += iRed ;
         else
            clr1r -= iRed ;

         clr1r = ( clr1r < 0 ? 0 : clr1r > 255 ? 255 : clr1r ) ;

         bDir = ( clr2g >= clr1g ? TRUE : FALSE  ) ;
         if( bDir )
            clr1g += iGreen ;
         else
            clr1g -= iGreen ;
         clr1g = ( clr1g < 0 ? 0 : clr1g > 255 ? 255 : clr1g ) ;

         bDir = ( clr2b >= clr1b ? TRUE : FALSE  ) ;
         if( bDir )
            clr1b += iBlue ;
         else
            clr1b -= iBlue ;
         clr1b = ( clr1b < 0 ? 0 : clr1b > 255 ? 255 : clr1b ) ;

      SelectObject( hDC, hOldBrush ) ;
      DeleteObject( hBrush ) ;
      hBrush = CreateSolidBrush( RGB( clr1r, clr1g, clr1b ) ) ;
      SelectObject( hDC, hBrush ) ;
      FillRect( hDC, &rct, hBrush ) ;

      if( ! bHoriz )
      {
         rct.top++ ;
         rct.bottom++ ;
      }
      else
      {
         rct.left++ ;
         rct.right++ ;
      }
   }
   SelectObject( hDC, hOldBrush ) ;
   DeleteObject( hBrush ) ;
}

//---------------------------------------------------------------------------//
/*
HB_FUNC( CHANGESYSCOLORS )
{
   int iEle, iItems = hb_parni( 1 ) ;
   int aiElemen[ 28 ] ;
   COLORREF alColors[ 28 ] ;

   for( iEle = 0 ; iEle <= ( iItems - 1 ) ; iEle++ )
   {
      aiElemen[ iEle ] = hb_parni( 2, ( iEle + 1 ) ) ;
      alColors[ iEle ] = hb_parnl( 3, ( iEle + 1 ) ) ;
   }

   SetSysColors( iItems, aiElemen, alColors ) ;
}
*/

//----------------------------------------------------------------------------//

void cDrawCursor( HWND hWnd, RECT * rctc, long lCursor, COLORREF nClr )
{
   HDC hDC;
   HRGN hReg;
   COLORREF lclr = ( lCursor == 1 ? RGB( 5, 5, 5 ) : lCursor == 2 ? nClr : lCursor );
   HBRUSH hBr ;
   RECT rct ;

   if( lCursor != 3 )
   {
      hBr = CreateSolidBrush( lclr ) ;
      hReg = CreateRectRgn( rctc->left, rctc->top, rctc->right - 1, rctc->bottom );
      hDC  = GetDCEx( hWnd, hReg, DCX_CACHE );

      FrameRgn( hDC, hReg, hBr, 2, 2 );

      ReleaseDC( hWnd, hDC );
      DeleteObject( hReg ) ;
      DeleteObject( hBr ) ;
   }
   else
   {
      rct.top    = rctc->top + 1 ;
      rct.left   = rctc->left + 1 ;
      rct.bottom = rctc->bottom - 1 ;
      rct.right  = rctc->right - 1 ;

      hDC  = GetDC( hWnd ) ;
      DrawFocusRect( hDC, &rct ) ;
      ReleaseDC( hWnd, hDC ) ;
   }
}
//----------------------------------------------------------------------------//
/*
void DrawMasked( HDC hdc, HBITMAP hbm, WORD y, WORD x )
{
   HDC         hdcMask, hdcBmp;
   HBITMAP     hbOld, hbOld1, hbMask, hbmp;
   BITMAP      bm;
   COLORREF    bBack, bFore;

   hdcMask  = CreateCompatibleDC( hdc );
   hdcBmp   = CreateCompatibleDC( hdc );
   GetObject( hbm, sizeof( BITMAP ), ( LPSTR ) &bm );

   hbmp     = CreateCompatibleBitmap( hdc, bm.bmWidth, bm.bmHeight );
   hbMask   = CreateBitmap( bm.bmWidth, bm.bmHeight, 1, 1, NULL );

   hbOld  = ( HBITMAP ) SelectObject( hdcBmp, hbmp );
   hbOld1 = ( HBITMAP ) SelectObject( hdcMask, hbm );
   BitBlt( hdcBmp, 0, 0, bm.bmWidth, bm.bmHeight, hdcMask, 0, 0, SRCCOPY );
   SelectObject( hdcMask, hbMask );

   SetBkColor( hdcBmp, GetPixel( hdcBmp, 0, 0 ) );
   BitBlt( hdcMask, 0, 0, bm.bmWidth, bm.bmHeight, hdcBmp, 0, 0, SRCCOPY );
   BitBlt( hdcBmp, 0, 0, bm.bmWidth, bm.bmHeight, hdcMask, 0, 0, 0x220326 );
   bBack = SetBkColor( hdc, RGB( 255, 255, 255 ) );
   bFore = SetTextColor( hdc, 0 );
   BitBlt( hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMask, 0, 0, SRCAND );
   BitBlt( hdc, x, y, bm.bmWidth, bm.bmHeight, hdcBmp, 0, 0, SRCPAINT );
   SetBkColor( hdc, bBack );
   SetTextColor( hdc, bFore );

   SelectObject( hdcBmp, hbOld );
   SelectObject( hdcMask, hbOld1 );
   DeleteObject( hbmp );
   DeleteObject( hbMask );
   DeleteDC( hdcMask );
   DeleteDC( hdcBmp );
}
//----------------------------------------------------------------------------//

void DrawBitmap( HDC hdc, HBITMAP hbm, WORD wCol, WORD wRow, WORD wWidth,
                 WORD wHeight, DWORD dwRaster )
{
    HDC       hDcMem, hDcMemX;
    BITMAP    bm, bmx;
    HBITMAP   hBmpOld, hbmx, hBmpOldX;

    if( !hdc || !hbm )
       return;

    hDcMem  = CreateCompatibleDC( hdc );
    hBmpOld = ( HBITMAP ) SelectObject( hDcMem, hbm );

    if( ! dwRaster )
       dwRaster = SRCCOPY;

    GetObject( hbm, sizeof( BITMAP ), ( LPSTR ) &bm );

    if( ! wWidth || ! wHeight )
       BitBlt( hdc, wRow, wCol, bm.bmWidth, bm.bmHeight, hDcMem, 0, 0, dwRaster );
    else
    {
       hDcMemX          = CreateCompatibleDC( hdc );
       bmx              = bm;
       bmx.bmWidth      = wWidth;
       bmx.bmHeight     = wHeight;

       bmx.bmWidthBytes = ( bmx.bmWidth * bmx.bmBitsPixel + 15 ) / 16 * 2;

       hbmx = CreateBitmapIndirect( &bmx );

       hBmpOldX = ( HBITMAP ) SelectObject( hDcMemX, hbmx );
       StretchBlt( hDcMemX, 0, 0, wWidth, wHeight, hDcMem, 0, 0,
                   bm.bmWidth, bm.bmHeight, dwRaster );
       BitBlt( hdc, wRow, wCol, wWidth, wHeight, hDcMemX, 0, 0, dwRaster );
       SelectObject( hDcMemX, hBmpOldX );
       DeleteDC( hDcMemX );
       DeleteObject( hbmx );
    }

    SelectObject( hDcMem, hBmpOld );
    DeleteDC( hDcMem );
}

//---------------------------------------------------------------------------//

void MaskRegion(HDC hdc, RECT * rct,
                       COLORREF cTransparentColor,
                       COLORREF cBackgroundColor)

{
   HDC        hdcTemp, hdcObject, hdcBack, hdcMem;
   POINT      ptSize;
   COLORREF   cColor;
   HBITMAP    bmAndObject, bmAndBack, bmBackOld, bmObjectOld,
              bmAndTemp, bmTempOld, bmAndMem, bmMemOld;
   HBRUSH     hBrush, hBrOld;

   ptSize.x = rct->right - rct->left + 1;
   ptSize.y = rct->bottom - rct->top + 1;

   hBrush      = CreateSolidBrush(cBackgroundColor);

   hdcTemp     = CreateCompatibleDC(hdc);
   hdcObject   = CreateCompatibleDC(hdc);
   hdcBack     = CreateCompatibleDC(hdc);
   hdcMem      = CreateCompatibleDC(hdc);

   bmAndTemp   = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
   bmAndMem    = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
   bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
   bmAndBack   = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

   bmTempOld   = ( HBITMAP ) SelectObject(hdcTemp, bmAndTemp);
   bmMemOld    = ( HBITMAP ) SelectObject(hdcMem, bmAndMem);
   bmBackOld   = ( HBITMAP ) SelectObject(hdcBack, bmAndBack);
   bmObjectOld = ( HBITMAP ) SelectObject(hdcObject, bmAndObject);

   hBrOld      = ( HBRUSH ) SelectObject(hdcMem, hBrush);

   BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdc, rct->left, rct->top, SRCCOPY);

   SetMapMode(hdcTemp, GetMapMode(hdc));

   cColor = SetBkColor(hdcTemp, cTransparentColor);

   BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

   SetBkColor(hdcTemp, cColor);

   BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
   PatBlt(hdcMem, 0,0, ptSize.x, ptSize.y, PATCOPY);
   BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
   BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
   BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
   BitBlt(hdc, rct->left, rct->top, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);

   DeleteObject(SelectObject(hdcMem, hBrOld));
   DeleteObject(SelectObject(hdcTemp, bmTempOld));
   DeleteObject(SelectObject(hdcMem, bmMemOld));
   DeleteObject(SelectObject(hdcBack, bmBackOld));
   DeleteObject(SelectObject(hdcObject, bmObjectOld));
   DeleteDC(hdcMem);
   DeleteDC(hdcBack);
   DeleteDC(hdcObject);
   DeleteDC(hdcTemp);
}

//----------------------------------------------------------------------------//

DWORD MoveTo( HDC hDC, int x, int y )
{
   POINT pt;
   DWORD dw;

   MoveToEx( hDC, x, y, &pt );

   dw = pt.x + ( pt.y >> 16 );
   return dw;
}

//----------------------------------------------------------------------------//

DWORD GetTextExtent( HDC hdc, LPCSTR lpszString, int cbString )
{
   SIZE pt;

   GetTextExtentPoint( hdc, lpszString, cbString, &pt );

   return pt.cx;
}
*/
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Where are MoveTo, GetTextExtent, DrawMasked, DrawBitmap ?

Postby concentra » Thu Nov 10, 2011 4:47 pm

And the software versions are :
Code: Select all  Expand view
Harbour 3.1.0dev (Rev. 17102)
gcc version 4.5.2-dw2 (tdm-1)
FWH October 2011
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

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