//---------------------------------------------------------------------------//
void SBtnRoundBox( HDC hDC, RECT * rct, COLORREF lColor, BOOL bPressed, BOOL bBlack )
{
HPEN hGray = CreatePen( PS_SOLID, 1, bBlack ? 0 : MakeDarker( lColor, 64 ) );
HPEN hWhite = CreatePen( PS_SOLID, 1, MakeDarker( lColor, -64 ) );
HPEN hOldPen ;
RECT brct ;
LOGBRUSH lb ;
HBRUSH hNull, hbrOld ;
POINT pO, pD ;
lb.lbStyle = BS_NULL ;
hNull = CreateBrushIndirect(&lb);
hbrOld = SelectObject(hDC, hNull);
hOldPen = SelectObject( hDC, hGray );
brct.top = rct->top ;
brct.left = rct->left ;
brct.bottom = rct->bottom ;
brct.right = rct->right ;
pO.x = brct.left + ( ( brct.right - brct.left ) / 4 * 3 );
pO.y = brct.top ;
pD.x = brct.left + ( ( brct.right - brct.left ) / 4 );
pD.y = brct.bottom ;
if( ! bBlack )
SelectObject( hDC, bPressed ? hWhite : hGray );
Ellipse( hDC, brct.left, brct.top, brct.right, brct.bottom );
if( ! bBlack )
{
SelectObject( hDC, bPressed ? hGray : hWhite );
Arc( hDC, brct.left, brct.top, brct.right, brct.bottom, pO.x, pO.y, pD.x, pD.y );
}
SelectObject( hDC, hOldPen );
SelectObject( hDC, hbrOld );
DeleteObject( hGray );
DeleteObject( hWhite );
DeleteObject( hNull );
}
//--------------------------------------------------------------------------------------------------------------------//
// ( hDC, nTop, nLeft, cText, hFont, lChecked, nClrBtn,
// nClrText, nClrLight, nClrDark, lDisable, l3D,
// lFocused, nStyle, lDrawFocus, lTwice, hBitMap )
HB_FUNC( DRAWRADIO )
{
HDC hDC = ( HDC ) hb_parnl( 1 );
int iTop = hb_parni( 2 );
int iLeft = hb_parni( 3 );
LPSTR cText = ( LPSTR ) hb_parc( 4 );
HFONT hFont = ( HFONT ) hb_parnl( 5 );
BOOL bSelect = hb_parl( 6 );
COLORREF nClrBtn = ( COLORREF ) hb_parnl( 7 );
COLORREF nClrText = ( COLORREF ) hb_parnl( 8 );
COLORREF nClrLight = ( COLORREF ) hb_parnl( 9 );
COLORREF nClrDark = ( COLORREF ) hb_parnl( 10 );
BOOL bDisable = hb_parl( 11 );
BOOL b3DInv = ( ISLOG( 12 ) ? ! hb_parl( 12 ) : FALSE );
BOOL b3D = ( ISLOG( 12 ) ? TRUE : FALSE );
BOOL bFocus = ( ISLOG( 13 ) ? hb_parl( 13 ) : FALSE );
int iStyle = hb_parni( 14 );
BOOL bDraw = hb_parl( 15 );
BOOL bTwice = hb_parl( 16 );
HBITMAP hBitMap = (HBITMAP) hb_parnl( 17 );
int iBmpW = hb_parni( 18 ) + 2 ;
int iBmpH = hb_parni( 19 );
HFONT hOldFont = SelectObject( hDC, hFont );
COLORREF nClr2 = MakeDarker( nClrBtn, 48 );
COLORREF nClr3 = MakeDarker( nClrBtn, -48 );
HPEN hPDark = CreatePen( PS_SOLID, 1, nClr2 );
HPEN hPNull = CreatePen( PS_NULL, 0, 0 );
HPEN hPLight = CreatePen( PS_SOLID, 1, nClr3 );
HPEN hPWhite = CreatePen( PS_SOLID, 1, RGB( 221, 221, 221 ) );
HPEN hPGray = CreatePen( PS_SOLID, 1, RGB( 128, 128, 128 ) );
HPEN hPNegra = CreatePen( PS_SOLID, 1, 0 );
HPEN hPHGray = CreatePen( PS_SOLID, 1, RGB( 192, 192, 192 ) );
HPEN hPBlack = CreatePen( PS_SOLID, 1, bDisable ? GetSysColor( COLOR_BTNSHADOW ) : 0 );
HPEN hPOld = SelectObject( hDC, iStyle == 3 || iStyle != 4 ? hPBlack : hPDark );
LOGBRUSH lb ;
HBRUSH hBNull ;
HBRUSH hBBlack = CreateSolidBrush( bDisable ? GetSysColor( COLOR_BTNSHADOW ) : 0 );
HBRUSH hBGray = CreateSolidBrush( bDisable ? GetSysColor( COLOR_BTNFACE ) : nClrBtn );
HBRUSH hBDisab = CreateSolidBrush( GetSysColor( COLOR_BTNSHADOW ) );
HBRUSH hBWhite = CreateSolidBrush( RGB( 241, 241, 241 ) );
HBRUSH hBOld = SelectObject( hDC, hBGray );
POINT aB[ 4 ] ;
POINT aP[ 7 ] ;
RECT rct ;
int iBkOld, iExt, iLen = hb_parclen( 4 );
TEXTMETRIC tm ;
GetTextMetrics( hDC, &tm );
lb.lbStyle = BS_NULL ;
hBNull = CreateBrushIndirect( &lb );
iExt = LOWORD( GetTextExtent( hDC, cText, iLen ) );
rct.top = iTop ;
rct.left = iLeft ;
rct.bottom = rct.top + max( tm.tmHeight, iBmpH );
rct.right = rct.left + iExt - tm.tmOverhang ;
if( iStyle == 3 )
{
aP[ 0 ].x = 4 + iLeft ;
aP[ 0 ].y = iTop + 2;
aP[ 1 ].x = 9 + iLeft ;
aP[ 1 ].y = 5 + iTop + 2 ;
aP[ 2 ].x = 4 + iLeft ;
aP[ 2 ].y = 10 + iTop + 2 ;
aP[ 3 ].x = 4 + iLeft ;
aP[ 3 ].y = 7 + iTop + 2 ;
aP[ 4 ].x = 0 + iLeft ;
aP[ 4 ].y = 7 + iTop + 2 ;
aP[ 5 ].x = 0 + iLeft ;
aP[ 5 ].y = 3 + iTop + 2 ;
aP[ 6 ].x = 4 + iLeft ;
aP[ 6 ].y = 3 + iTop + 2 ;
}
else
{
aB[ 0 ].x = 6 + iLeft ;
aB[ 0 ].y = iTop ;
aB[ 1 ].x = 12 + iLeft ;
aB[ 1 ].y = 6 + iTop ;
aB[ 2 ].x = 6 + iLeft ;
aB[ 2 ].y = 12 + iTop ;
aB[ 3 ].x = iLeft ;
aB[ 3 ].y = 6 + iTop ;
}
switch( iStyle )
{
case 3 : // Pointer arrow
if( ! hBitMap && bSelect )
{
SelectObject( hDC, hPBlack );
SelectObject( hDC, hBGray );
Polygon( hDC, aP, sizeof( aP ) / sizeof( POINT ) );
}
else
if( bSelect )
{
DrawMasked( hDC, hBitMap, rct.top, rct.left );
}
break ;
case 4 : // Check Box
if( ! bDisable || ( bDisable && bSelect ) )
{
SelectObject( hDC, hPDark );
Rectangle( hDC, rct.left, rct.top, rct.left + 13, rct.top + 13 );
SelectObject( hDC, hPLight );
GoPoint( hDC, rct.left + 12, rct.top );
LineTo( hDC, rct.left, rct.top );
LineTo( hDC, rct.left, rct.top + 12 );
if( bSelect )
{
SelectObject( hDC, hPBlack );
GoPoint( hDC, rct.left + 9, rct.top + 3 );
LineTo( hDC, rct.left + 2, rct.top + 10 );
LineTo( hDC, rct.left + 2, rct.top + 6 );
LineTo( hDC, rct.left + 3, rct.top + 5 );
LineTo( hDC, rct.left + 3, rct.top + 10 );
LineTo( hDC, rct.left + 10, rct.top + 3 );
}
}
break ;
case 5 : // bitmap
if( hBitMap && ( ! bDisable || ( bDisable && bSelect ) ) )
{
DrawMasked( hDC, hBitMap, rct.top, rct.left );
}
break ;
case 6 : // pressed rhombus
if( ! bDisable || ( bDisable && bSelect ) )
{
SelectObject( hDC, hBNull );
Polygon( hDC, aB, sizeof( aB ) / sizeof( POINT ) );
SelectObject( hDC, hBGray );
}
break ;
case 8 : // pressed arrow pointer
if( ! hBitMap && ! bDisable && bSelect )
{
SelectObject( hDC, hPLight );
SelectObject( hDC, hBGray );
Polygon( hDC, aP, sizeof( aP ) / sizeof( POINT ) );
}
else
{
if( ! bDisable && bSelect )
{
DrawMasked( hDC, hBitMap, rct.top, rct.left );
}
}
break ;
case 9 : // pressed check box
if( ! bDisable || ( bDisable && bSelect ) )
{
SelectObject( hDC, hBNull );
SelectObject( hDC, hPBlack );
Rectangle( hDC, rct.left, rct.top, rct.left + 13, rct.top + 13 );
SelectObject( hDC, hBGray );
}
break ;
default : // rhombus
SelectObject( hDC, hPDark );
if( ! bDisable || ( bDisable && bSelect ) )
{
Polygon( hDC, aB, sizeof( aB ) / sizeof( POINT ) );
}
if( ! bDisable || ( bDisable && bSelect ) )
{
if( iStyle != 1 )
{
aB[ 0 ].y += 1 ;
aB[ 1 ].x -= 1 ;
aB[ 2 ].y -= 1 ;
aB[ 3 ].x += 1 ;
SelectObject( hDC, hPDark );
Polygon( hDC, aB, sizeof( aB ) / sizeof( POINT ) );
aB[ 0 ].y -= 1 ;
aB[ 1 ].x += 1 ;
aB[ 2 ].y += 1 ;
aB[ 3 ].x -= 1 ;
}
SelectObject( hDC, hPLight );
switch( bSelect )
{
case FALSE :
GoPoint( hDC, aB[ 0 ].x, aB[ 0 ].y );
LineTo( hDC, aB[ 3 ].x, aB[ 3 ].y );
LineTo( hDC, aB[ 2 ].x, aB[ 2 ].y );
if( iStyle != 1 )
{
GoPoint( hDC, aB[ 0 ].x, aB[ 0 ].y + 1 );
LineTo( hDC, aB[ 3 ].x + 1, aB[ 3 ].y );
LineTo( hDC, aB[ 2 ].x, aB[ 2 ].y - 1 );
}
break ;
case TRUE :
GoPoint( hDC, aB[ 0 ].x + 1, aB[ 0 ].y + 1);
LineTo( hDC, aB[ 1 ].x, aB[ 1 ].y );
LineTo( hDC, aB[ 2 ].x - 1, aB[ 2 ].y + 1 );
if( iStyle != 1 )
{
GoPoint( hDC, aB[ 0 ].x + 1 , aB[ 0 ].y + 2 );
LineTo( hDC, aB[ 1 ].x - 1, aB[ 1 ].y );
LineTo( hDC, aB[ 2 ].x - 1, aB[ 2 ].y );
}
aB[ 0 ].y += 4 ;
aB[ 1 ].x -= 4 ;
aB[ 2 ].y -= 4 ;
aB[ 3 ].x += 4 ;
SelectObject( hDC, hPBlack );
SelectObject( hDC, hBBlack );
Polygon( hDC, aB, sizeof( aB ) / sizeof( POINT ) );
break ;
}
}
break ;
}
if( iStyle < 6 )
{
rct.top += 1 ;
rct.left += max( 16, iBmpW );
rct.right += max( 16, iBmpW );
rct.bottom += 1 ;
iBkOld = SetBkMode( hDC, TRANSPARENT );
if( b3D )
{
rct.top -= 1 ;
rct.left -= 1 ;
rct.bottom -= 1 ;
rct.right -= 1 ;
SetTextColor( hDC, b3DInv ? nClrDark : nClrLight );
DrawText( hDC, cText, -1, &rct, DT_LEFT );
rct.top += 2 ;
rct.left += 2 ;
rct.bottom += 2 ;
rct.right += 2 ;
SetTextColor( hDC, b3DInv ? nClrLight : nClrDark );
DrawText( hDC, cText, -1, &rct, DT_LEFT );
rct.top -= 1 ;
rct.left -= 1 ;
rct.bottom -= 1 ;
rct.right -= 1 ;
SetTextColor( hDC, nClrText );
DrawText( hDC, cText, -1, &rct, DT_LEFT );
}
else
{
SetTextColor( hDC, nClrText );
DrawText( hDC, cText, -1, &rct, DT_LEFT );
}
if( ( bFocus && ! bDisable && iStyle < 6 && bSelect ) || ( bFocus && bDraw ) )
{
rct.top -= 1 ;
rct.left -= 1 ;
rct.bottom += 1 ;
rct.right += 1 ;
DrawFocusRect( hDC, &rct );
if( bFocus && bDraw && bTwice )
{
DrawFocusRect( hDC, &rct );
}
}
}
SetBkMode( hDC, iBkOld );
SelectObject( hDC, hOldFont );
SelectObject( hDC, hPOld );
SelectObject( hDC, hBOld );
DeleteObject( hPDark );
DeleteObject( hPLight );
DeleteObject( hPBlack );
DeleteObject( hPNegra );
DeleteObject( hPWhite );
DeleteObject( hPHGray );
DeleteObject( hPNull );
DeleteObject( hPGray );
DeleteObject( hBWhite );
DeleteObject( hBBlack );
DeleteObject( hBGray );
DeleteObject( hBDisab );
DeleteObject( hBNull );
}
//---------------------------------------------------------------------------//
HB_FUNC( DRAWBOXES ) // ( hDC, hWnd, nType, cText, hFont, nAlign, nClrLight,nClrDark, nClrLabel
{
HDC hDC = ( HDC ) hb_parnl( 1 );
HWND hWnd = ( HWND ) hb_parnl( 2 );
int iType = hb_parni( 3 );
LPSTR cLabel = ( LPSTR ) hb_parc( 4 );
HFONT hFont = ( HFONT ) hb_parnl( 5 );
int iAlign = ( ISNUM( 6 ) ? hb_parni( 6 ) : 0 );
COLORREF nClrLight = ( COLORREF ) ( ISNUM( 7 ) ? hb_parnl( 7 ) : MakeDarker( GetSysColor( COLOR_BTNFACE ), -48 ) );
COLORREF nClrDark = ( COLORREF ) ( ISNUM( 8 ) ? hb_parnl( 8 ) : MakeDarker( GetSysColor( COLOR_BTNFACE ), 48 ) );
COLORREF nClrLabel = ( COLORREF ) ( ISNUM( 9 ) ? hb_parnl( 9 ) : GetSysColor( COLOR_BTNTEXT ) );
BOOL bLabel = ( ISCHAR( 4 ) && hb_parclen( 4 ) > 0 ? TRUE : FALSE );
RECT rct ;
GetClientRect( hWnd, &rct );
cDrawBoxes( hDC, &rct, iType, cLabel, hFont, iAlign, nClrLight, nClrDark, nClrLabel, bLabel, 0 );
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( DARKCOLOR ) // ( nColor, nIncrement ) --> New Color
{
hb_retnl( MakeDarker( ( COLORREF ) hb_parnl( 1 ), hb_parni( 2 ) ) );
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( GETFONTHEIGHT ) //( hDC, hFont ) --> Font Height
{
HDC hDC = ( HDC ) hb_parnl( 1 );
HFONT hFont = ( HFONT ) hb_parnl( 2 );
TEXTMETRIC tm ;
HFONT hOldFont = SelectObject( hDC, hFont );
GetTextMetrics( hDC, &tm );
SelectObject( hDC, hOldFont );
hb_retni( tm.tmHeight );
}
//---------------------------------------------------------------------------//
HB_FUNC( DRAWRECTDOTTED ) //( hDC, nTop, nLeft, nBottom, nRight )
{
HDC hDC = ( HDC ) hb_parnl( 1 );
int iTop = hb_parni( 2 );
int iLeft = hb_parni( 3 );
int iBottom = hb_parni( 4 );
int iRight = hb_parni( 5 );
RECT rct ;
rct.top = iTop ;
rct.left = iLeft ;
rct.bottom = iBottom ;
rct.right = iRight ;
DrawFocusRect( hDC, &rct );
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( SBARNEW ) // ( hWnd, hDC )
{
HWND hWnd = ( HWND ) hb_parnl( 1 );
HDC hDC = ( HDC ) hb_parnl( 2 );
COLORREF ClrBack = hb_parnl( 3 );
COLORREF nClrTo = hb_parnl( 4 );
int iBottom, iShape = hb_parni( 5 );
RECT rct ;
HRGN hRgn, hOldRgn ;
GetClientRect( hWnd, &rct );
hRgn = CreateRectRgn( rct.left, rct.top, rct.right - rct.left + 1, rct.bottom - rct.top + 1 );
hOldRgn = SelectObject( hDC, hRgn );
switch( iShape )
{
case 1 :
{
iBottom = rct.bottom ;
rct.bottom = rct.bottom / 4 ;
DegradColor( hDC, &rct, nClrTo, ClrBack );
rct.top = rct.bottom ;
rct.bottom = iBottom ;
DegradColor( hDC, &rct, ClrBack, nClrTo );
break ;
}
case 2 :
{
iBottom = rct.bottom ;
rct.bottom = rct.bottom / 4 ;
DegradColor( hDC, &rct, nClrTo, MakeDarker( ClrBack, -40 ) );
rct.top = rct.bottom ;
rct.bottom = iBottom;
DegradColor( hDC, &rct, ClrBack, MakeDarker( ClrBack, -10 ) );
break ;
}
}
DeleteObject( hRgn );
GetClientRect( hWnd, &rct );
hRgn = CreateRectRgn( rct.left, rct.top, rct.right, rct.bottom );
SelectObject( hDC, hRgn );
SelectObject( hDC, hOldRgn );
DeleteObject( hRgn );
DeleteObject( hOldRgn );
}
//---------------------------------------------------------------------------//
void cDrawBoxes( HDC hDC, RECT * rrct, int iType, LPSTR cLabel, HFONT hFont, int iAlign, COLORREF nClrLight,
COLORREF nClrDark, COLORREF nClrLabel, BOOL bLabel, int iCorner )
{
RECT rct, rctt ;
TEXTMETRIC tm ;
int iBkOld, iWidth, iLen = hb_parclen( 4 );
HFONT hFOld ;
HRGN hRgn, hOldRgn ;
POINT aP[ 3 ] ;
HPEN hPDark = CreatePen( PS_SOLID, 1, nClrDark );
HPEN hPLight = CreatePen( PS_SOLID, 1, nClrLight );
HPEN hPBlack = CreatePen( PS_SOLID, .5, 0 );
HPEN hPOld = SelectObject( hDC, iType == 1 || iType == 4 ? hPDark : hPLight );
LOGBRUSH lb ;
HBRUSH hBNull, hBOld ;
if( ! iCorner )
{
iCorner = 5 ;
}
if( bLabel )
{
hFOld = SelectObject( hDC, hFont );
}
lb.lbStyle = BS_NULL ;
hBNull = CreateBrushIndirect( &lb );
GetTextMetrics( hDC, &tm );
rct.top = rrct->top ;
rct.left = rrct->left ;
rct.bottom = rrct->bottom ;
rct.right = rrct->right ;
rct.right -= ( iType == 2 || iType == 5 || iType == 4 ? 1 : 0 );
rct.bottom -= ( iType == 2 || iType == 5 || iType == 4 ? 1 : 0 );
rctt.top = rct.top ;
rctt.bottom = rctt.top + tm.tmHeight ;
iWidth = LOWORD( GetTextExtent( hDC, cLabel, iLen ) );
if( bLabel )
{
switch( iAlign )
{
case 0 : // left aligned label
rctt.left = rct.left + 9 ;
rctt.right = rctt.left + iWidth ;
break ;
case 1 : // centered label
rctt.left = rct.right - ( rct.right / 2 ) - ( iWidth / 2 );
rctt.right = rctt.left + iWidth ;
break ;
case 2 : // right aligned label
rctt.right = rct.right - 9 ;
rctt.left = rctt.right - iWidth ;
break ;
}
}
rct.top += ( bLabel ? ( tm.tmHeight / 2 ) : 0 );
aP[ 0 ].x = rct.left ;
aP[ 0 ].y = rct.top ;
aP[ 1 ].x = rct.right ;
aP[ 1 ].y = rct.top ;
aP[ 2 ].x = rct.left ;
aP[ 2 ].y = rct.bottom - 1 ;
if( bLabel )
{
iBkOld = SetBkMode( hDC, TRANSPARENT );
SetTextColor( hDC, nClrLabel );
DrawText( hDC, cLabel, -1, &rctt, DT_LEFT | DT_TOP | DT_SINGLELINE );
SetBkMode( hDC, iBkOld );
ExcludeClipRect( hDC, rctt.left, rct.top, rctt.right, rctt.bottom );
}
if( iType == 1 || iType == 3 || iType == 4 || iType == 6 )
{
hRgn = CreatePolygonRgn( aP, sizeof( aP ) / sizeof( POINT ), ALTERNATE );
}
hBOld = SelectObject( hDC, hBNull );
switch( iType )
{
case 1 : // white box
SelectObject( hDC, hPDark );
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
hOldRgn = SelectObject( hDC, hRgn );
SelectObject( hDC, hPLight );
if( bLabel )
{
ExcludeClipRect( hDC, rctt.left, rct.top, rctt.right, rctt.bottom );
}
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
break ;
case 2 : // gray box
rct.top += 1 ;
rct.left += 1 ;
rct.bottom += 1 ;
rct.right += 1 ;
SelectObject( hDC, hPLight );
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
rct.top -= 1 ;
rct.left -= 1 ;
rct.bottom -= 1 ;
rct.right -= 1 ;
SelectObject( hDC, hPDark );
if( bLabel )
{
ExcludeClipRect( hDC, rctt.left, rct.top, rctt.right, rctt.bottom );
}
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
break ;
case 3 : // black box
SelectObject( hDC, hPLight );
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
hOldRgn = SelectObject( hDC, hRgn );
SelectObject( hDC, hPDark );
if( bLabel )
{
ExcludeClipRect( hDC, rctt.left, rct.top, rctt.right, rctt.bottom );
}
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
break ;
case 4 : // white round rect box
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, iCorner, iCorner );
hOldRgn = SelectObject( hDC, hRgn );
SelectObject( hDC, hPLight );
if( bLabel )
{
ExcludeClipRect( hDC, rctt.left, rct.top, rctt.right, rctt.bottom );
}
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, 5, 5 );
break ;
case 5 : // gray round rect box
rct.top += 1 ;
rct.left += 1 ;
rct.bottom += 1 ;
rct.right += 1 ;
SelectObject( hDC, hPLight );
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, iCorner, iCorner );
rct.top -= 1 ;
rct.left -= 1 ;
rct.bottom -= 1 ;
rct.right -= 1 ;
SelectObject( hDC, hPDark );
if( bLabel )
{
ExcludeClipRect( hDC, rctt.left, rct.top, rctt.right, rctt.bottom );
}
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, iCorner, iCorner );
break ;
case 6 : // black Round box
SelectObject( hDC, hPLight );
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, iCorner, iCorner );
hOldRgn = SelectObject( hDC, hRgn );
SelectObject( hDC, hPDark );
if( bLabel )
{
ExcludeClipRect( hDC, rctt.left, rct.top, rctt.right, rctt.bottom );
}
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, iCorner, iCorner );
break ;
case 7 : // horizontal line
SelectObject( hDC, hPDark );
GoPoint( hDC, rct.left, rct.top );
LineTo( hDC, rct.right + 1, rct.top );
SelectObject( hDC, hPLight );
GoPoint( hDC, rct.left, rct.top + 1 );
LineTo( hDC, rct.right + 1, rct.top + 1 );
break ;
case 8 : // vertical line
SelectObject( hDC, hPDark );
GoPoint( hDC, rct.left, rct.top );
LineTo( hDC, rct.left, rct.bottom + 1 );
SelectObject( hDC, hPLight );
GoPoint( hDC, rct.left + 1 , rct.top );
LineTo( hDC, rct.left + 1, rct.bottom + 1 );
break ;
case 9 : // black rect
SelectObject( hDC, hPBlack );
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
break ;
case 10 : // black Round rect
SelectObject( hDC, hPBlack );
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, iCorner, iCorner );
break ;
case 11 : // dark Round rect
SelectObject( hDC, hPDark );
RoundRect( hDC, rct.left, rct.top, rct.right, rct.bottom, iCorner, iCorner );
break ;
case 12 : // dark Round rect
SelectObject( hDC, hPDark );
Rectangle( hDC, rct.left, rct.top, rct.right, rct.bottom );
break ;
}
if( iType == 1 || iType == 3 || iType == 4 || iType == 6 )
{
DeleteObject( hRgn );
hRgn = CreateRectRgn( rct.left, rct.top, rct.right, rct.bottom );
SelectObject( hDC, hRgn );
SelectObject( hDC, hOldRgn );
DeleteObject( hRgn );
DeleteObject( hOldRgn );
}
SelectObject( hDC, hPOld );
SelectObject( hDC, hBOld );
if( bLabel )
{
SelectObject( hDC, hFOld );
}
DeleteObject( hPLight );
DeleteObject( hPDark );
DeleteObject( hPBlack );
DeleteObject( hBNull );
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( DRAWLIMIT ) // ( hDC, aPoint, nPenWidth )
{
HDC hDC = ( HDC ) hb_parnl( 1 );
int iYo = hb_parvni( 2, 1 );
int iXo = hb_parvni( 2, 2 );
int iYd = hb_parvni( 2, 3 );
int iXd = hb_parvni( 2, 4 );
int iPenWidth = ( hb_parni( 3 ) ? hb_parni( 3 ) : 3 );
int iROP = SetROP2( hDC, R2_NOT );
HPEN hPen = CreatePen( PS_SOLID, iPenWidth, RGB( 128, 128, 128 ) );
HPEN hPOld = SelectObject( hDC, hPen );
GoPoint( hDC, iXo, iYo );
LineTo( hDC, iXd, iYd );
SetROP2( hDC, iROP );
SelectObject( hDC, hPOld );
DeleteObject( hPen );
}
//---------------------------------------------------------------------------//
static void DegradColor( HDC hDC, RECT * rori, COLORREF cFrom, COLORREF cTo )
{
float clr1r, clr1g, clr1b, clr2r, clr2g, clr2b ;
float iEle, iRed, iGreen, iBlue ;
float iTot = ( rori->bottom + 2 - rori->top );
BOOL bDir ;
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 );
clr2r = GetRValue( cTo );
clr2g = GetGValue( cTo );
clr2b = GetBValue( cTo );
iRed = abs( clr2r - clr1r );
iGreen = abs( clr2g - clr1g );
iBlue = abs( clr2b - clr1b );
iRed = iRed / iTot ;
iGreen = iGreen / iTot ;
iBlue = iBlue / iTot ;
rct.bottom = rct.top + 1 ;
hBrush = CreateSolidBrush( RGB( clr1r, clr1g, clr1b ) );
hOldBrush = 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 );
rct.top++ ;
rct.bottom++ ;
}
SelectObject( hDC, hOldBrush );
DeleteObject( hBrush );
}
//----------------------------------------------------------------------------//
static void DrawMasked( HDC hdc, HBITMAP hbm, signed int y, signed int 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, NOTSRCAND );
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 );
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( GRADCOLOR ) // ( hDC, aRect, nClrFrom, nClrTo, nDegType )
{
HDC hDC = ( HDC ) hb_parnl( 1 );
int iTop = hb_parvni( 2, 1 );
int iLeft = hb_parvni( 2, 2 );
int iBottom = hb_parvni( 2, 3 );
int iRight = hb_parvni( 2, 4 );
COLORREF ClrFrom = hb_parnl( 3 );
COLORREF ClrTo = hb_parnl( 4 );
int iDegType = ISNUM( 5 ) ? hb_parni( 5 ) : 1 ; // default = vertical gradient
RECT rct ;
rct.top = iTop ;
rct.left = iLeft ;
rct.bottom = iBottom ;
rct.right = iRight ;
ColorDegrad( hDC, &rct, ClrFrom, ClrTo, iDegType, 0, 0 );
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( LIGHTCOLOR )
{
LONG lScale = hb_parnl( 1 );
COLORREF ColorFrom = hb_parnl( 2 );
long R = MulDiv( 255 - GetRValue( ColorFrom ), lScale, 255 ) + GetRValue( ColorFrom );
long G = MulDiv( 255 - GetGValue( ColorFrom ), lScale, 255 ) + GetGValue( ColorFrom );
long B = MulDiv( 255 - GetBValue( ColorFrom ), lScale, 255 ) + GetBValue( ColorFrom );
hb_retnl( RGB( R, G, B ) );
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( SGRADIENT )
{
HWND hWnd = ( HWND ) hb_parnl( 1 );
HDC hDC = ( HDC ) hb_parnl( 2 );
COLORREF ColorFrom = ( COLORREF ) hb_parnl( 3 );
COLORREF ColorTo = ( COLORREF ) hb_parnl( 4 );
int iDegType = hb_parni( 5 );
int iShape = hb_parni( 6 );
int iCorner = hb_parni( 7 );
RECT rct ;
POINT pO[ 4 ] ;
HRGN hRgn, hOldRgn ;
GetClientRect( hWnd, &rct );
switch( iShape )
{
case 1 : // rectangle
hRgn = CreateRectRgn( rct.left, rct.top, rct.right - rct.left + 1, rct.bottom - rct.top + 1 );
break ;
case 2 : // round rectangle
hRgn = CreateRoundRectRgn( rct.left, rct.top, rct.right - rct.left + 1, rct.bottom - rct.top + 1, iCorner,
iCorner );
break ;
case 3 : // ellipse
hRgn = CreateEllipticRgn( rct.left, rct.top, rct.right - rct.left + 1, rct.bottom - rct.top + 1 );
break ;
case 4 : // right shade
rct.left = rct.right ;
rct.bottom += iCorner ;
rct.right += iCorner ;
pO[ 0 ].y = rct.top + iCorner ;
pO[ 0 ].x = rct.right - iCorner ;
pO[ 1 ].y = rct.top + iCorner ;
pO[ 1 ].x = rct.right ;
pO[ 2 ].y = rct.bottom ;
pO[ 2 ].x = rct.right ;
pO[ 3 ].y = rct.bottom - iCorner ;
pO[ 3 ].x = rct.right - iCorner ;
hRgn = CreatePolygonRgn( pO, 4, WINDING );
break ;
case 5 : // bottom shade
rct.top = rct.bottom ;
rct.bottom = rct.top + iCorner ;
rct.right += iCorner ;
pO[ 0 ].y = rct.bottom - iCorner ;
pO[ 0 ].x = rct.left + iCorner ;
pO[ 1 ].y = rct.bottom ;
pO[ 1 ].x = rct.left + iCorner ;
pO[ 2 ].y = rct.bottom ;
pO[ 2 ].x = rct.right ;
pO[ 3 ].y = rct.bottom - iCorner ;
pO[ 3 ].x = rct.right - iCorner ;
hRgn = CreatePolygonRgn( pO, 4, WINDING );
break ;
case 6 : // right frame
rct.left = rct.right ;
rct.top -= iCorner ;
rct.bottom += iCorner ;
rct.right += iCorner ;
pO[ 0 ].y = rct.top + iCorner ;
pO[ 0 ].x = rct.left ;
pO[ 1 ].y = rct.top ;
pO[ 1 ].x = rct.right ;
pO[ 2 ].y = rct.bottom ;
pO[ 2 ].x = rct.right ;
pO[ 3 ].y = rct.bottom - iCorner ;
pO[ 3 ].x = rct.right - iCorner ;
hRgn = CreatePolygonRgn( pO, 4, WINDING );
break ;
case 7 : // bottom frame
rct.top = rct.bottom ;
rct.bottom = rct.top + iCorner ;
rct.right += iCorner ;
rct.left -= iCorner ;
pO[ 0 ].y = rct.bottom - iCorner ;
pO[ 0 ].x = rct.left + iCorner ;
pO[ 1 ].y = rct.bottom ;
pO[ 1 ].x = rct.left ;
pO[ 2 ].y = rct.bottom ;
pO[ 2 ].x = rct.right ;
pO[ 3 ].y = rct.bottom - iCorner ;
pO[ 3 ].x = rct.right - iCorner ;
hRgn = CreatePolygonRgn( pO, 4, WINDING );
break ;
case 8 : // left frame
rct.right = rct.left ;
rct.left -= iCorner ;
rct.top -= iCorner ;
rct.bottom += iCorner ;
pO[ 0 ].y = rct.top + iCorner ;
pO[ 0 ].x = rct.right ;
pO[ 1 ].y = rct.top ;
pO[ 1 ].x = rct.left ;
pO[ 2 ].y = rct.bottom ;
pO[ 2 ].x = rct.left ;
pO[ 3 ].y = rct.bottom - iCorner ;
pO[ 3 ].x = rct.right ;
hRgn = CreatePolygonRgn( pO, 4, WINDING );
break ;
case 9 : // top frame
rct.top -= iCorner ;
rct.bottom = rct.top + iCorner ;
rct.right += iCorner ;
rct.left -= iCorner ;
pO[ 0 ].y = rct.top ;
pO[ 0 ].x = rct.left ;
pO[ 1 ].y = rct.top ;
pO[ 1 ].x = rct.right ;
pO[ 2 ].y = rct.bottom ;
pO[ 2 ].x = rct.right - iCorner ;
pO[ 3 ].y = rct.bottom ;
pO[ 3 ].x = rct.left + iCorner ;
hRgn = CreatePolygonRgn( pO, 4, WINDING );
break ;
default : // rectangle
hRgn = CreateRectRgn( rct.left, rct.top, rct.right - rct.left + 1, rct.bottom - rct.top + 1 );
break ;
}
hOldRgn = SelectObject( hDC, hRgn );
ColorDegrad( hDC, &rct, ColorFrom, ColorTo, iDegType, 0, iCorner );
SelectObject( hDC, hOldRgn );
DeleteObject( hRgn );
DeleteObject( hOldRgn );
}
//--------------------------------------------------------------------------------------------------------------------//
static void DrawGrayed( HDC hdc, HBITMAP hbm, signed int y, signed int x )
{
HDC hdcMask, hdcBmp;
HBITMAP hbOld, hbOld1, hbMask, hbmp, hbmpChecker;
BITMAP bm;
HBRUSH hbr, hbrOld;
COLORREF bBack, bFore;
USHORT aChecker[] = { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 };
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 );
hbmpChecker = CreateBitmap( 8, 8, 1, 1, aChecker );
hbr = CreatePatternBrush( hbmpChecker );
GetObject( hbmp, sizeof( BITMAP ), ( LPSTR ) &bm );
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, GetSysColor( COLOR_BTNHIGHLIGHT ) );
bFore = SetTextColor( hdc, GetSysColor( COLOR_BTNFACE ) );
hbrOld = (HBRUSH) SelectObject( hdc, hbr );
BitBlt( hdc, x, y, bm.bmWidth, bm.bmHeight, NULL, 0, 0, PATCOPY );
SetBkColor( hdc, RGB( 255, 255, 255 ) );
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 );
SelectObject( hdc, hbrOld );
DeleteObject( hbmpChecker );
DeleteObject( hbMask );
DeleteObject( hbmp );
DeleteObject( hbr );
DeleteDC( hdcMask );
DeleteDC( hdcBmp );
}
//--------------------------------------------------------------------------------------------------------------------//
BOOL AlphaPaint( 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 ;
BMI.biSize = sizeof( BITMAPINFOHEADER );
BMI.biWidth = cx ;
BMI.biHeight = cy ;
BMI.biPlanes = 1 ;
BMI.biBitCount = 32 ;
BMI.biCompression = BI_RGB ;
BMI.biSizeImage = 0 ;
BMI.biXPelsPerMeter = 0 ;
BMI.biYPelsPerMeter = 0 ;
BMI.biClrUsed = 0 ;
BMI.biClrImportant = 0 ;
hbmSrc = CreateDIBSection ( dcSrc, ( BITMAPINFO * ) &BMI, DIB_RGB_COLORS, ( void ** ) &pSrcBits, 0, 0l );
hbmDest = CreateDIBSection ( dcDest, ( BITMAPINFO * ) &BMI, DIB_RGB_COLORS, ( void ** ) &pDestBits, 0, 0l );
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 ;
}
SelectObject( dc, dcOld );
DeleteDC( dc );
DeleteObject( hbmSrc );
DeleteObject( hbmDest );
return TRUE ;
}
//--------------------------------------------------------------------------------------------------------------------//
HB_FUNC( ISALPHABITMAP )
{
HDC hdcBmp, hDC ;
BOOL bIsAlpha ;
BITMAP bm ;
HBITMAP hbmOld ;
HWND hWnd = GetActiveWindow();
hDC = GetDC( hWnd );
hdcBmp = CreateCompatibleDC( hDC );
hbmOld = SelectObject( hdcBmp, ( HBITMAP ) hb_parnl( 1 ) );
GetObject( ( HBITMAP ) hb_parnl( 1 ), sizeof( BITMAP ), ( LPSTR ) &bm );
bIsAlpha = DetectAlpha( hdcBmp, 0, 0, bm.bmWidth, bm.bmHeight );
ReleaseDC( hWnd, hDC );
SelectObject( hdcBmp, hbmOld );
DeleteObject( hdcBmp );
DeleteObject( hbmOld );
hb_retl( bIsAlpha );
}
//--------------------------------------------------------------------------------------------------------------------//
BOOL DetectAlpha( HDC dcSrc, int sx, int sy, int scx, int scy )
{
BITMAPINFOHEADER BMI ;
BYTE * pSrcBits ;
HBITMAP hbmSrc ;
HDC dc ;
HBITMAP dcOld ;
int j, i ;
BOOL bIsAlpha ;
LPBYTE pbSrcRGB ;
BMI.biSize = sizeof( BITMAPINFOHEADER );
BMI.biWidth = scx ;
BMI.biHeight = scy ;
BMI.biPlanes = 1 ;
BMI.biBitCount = 32 ;
BMI.biCompression = BI_RGB ;
BMI.biSizeImage = 0;
BMI.biXPelsPerMeter = 0 ;
BMI.biYPelsPerMeter = 0 ;
BMI.biClrUsed = 0 ;
BMI.biClrImportant = 0 ;
hbmSrc = CreateDIBSection ( dcSrc, ( BITMAPINFO * ) &BMI, DIB_RGB_COLORS, ( void ** ) &pSrcBits, 0, 0l );
dc = CreateCompatibleDC( NULL );
dcOld = ( HBITMAP ) SelectObject( dc, hbmSrc );
bIsAlpha = StretchBlt( dc, 0, 0, scx, scy, dcSrc, sx, sy, scx, scy, SRCCOPY );
if( bIsAlpha )
{
bIsAlpha = FALSE ;
for( j = 0; j < scy && ! bIsAlpha; ++j )
{
pbSrcRGB = ( LPBYTE ) &( ( DWORD* ) pSrcBits )[ j * scx ];
for( i = 0; i < scx && ! bIsAlpha; ++i )
{
bIsAlpha = pbSrcRGB[ 3 ] != 0;
pbSrcRGB += 4;
}
}
}
SelectObject( dc, dcOld );
DeleteDC( dc );
DeleteObject( hbmSrc );
DeleteObject( dcOld );
return bIsAlpha;
}
/*-----------------------------------------------------------------------------------------------------------*/
/*EOF*/
/*-----------------------------------------------------------------------------------------------------------*/