AndreyZh пишет:
цитата: |
Всем спасибо! Но хотелось пример сложнее "Hello World" и по xHarbour более подробных объяснений: |
|
Самый простой и , наверное , информативный пройтись по форуму. Там и тексты и картинки...
Ну вот Вам примерчик посложнее ( с картинкой :) ) . Попутно здесь можно увидеть , как в исходник вставляются сишные модули ( при необходимости)
Извините, не знаю как делать скрытый текст поэтому все подряд....
#include "FIVEWIN.ch"
#include 'xbrowse.ch'
REQUEST DBFCDX
function main()
local oWnd, hBmp
define window oWnd menu Menu()
activate window oWnd on paint( CircleGradient( hDC, { 0, 0, oWnd:nHeight, oWnd:nWidth } , nRGB( 255, 0, 0 ), nRGB( 0, 0, 255 ) ) )//
return nil
//----------------------------------------------------------------------------//
Function Menu()
local oMenu
menu oMenu
menuitem "Test1" action Test( )
menuitem "Test2" action Test( 180, 180 )
menuitem "Test3" action Test2()
endmenu
return oMenu
//----------------------------------------------------------------------------//
function Test( nOffX, nOffY )
local oDlg
local oBrushDlg := TBrush():New()
local oGrp
default nOffX := 0, nOffY := 0
DeleteObject( oBrushDlg:hBrush )
oBrushDlg:hBrush = CircleGradient( 0, { 0, 0, 400, 400 } , nRGB( 254, 154, 128 ), nRGB( 181, 61, 29 ), nOffX, nOffY, 1 )
define dialog oDlg title "Circle Gradient - Brushes" size 400,400 BRUSH oBrushDlg
@ 0, 1 GROUP oGrp TO 4, 21.5 PROMPT "Test" transparent
activate dialog oDlg centered
return nil
function test2()
local oWnd, oBrw
local hBmp := CircleGradient( 0, { 0, 0, 400, 400 } , nRGB( 212, 219, 237 ), nRGB( 132, 179, 249 ), -190, -190, 2 )
USE CUSTOMER SHARED
DEFINE WINDOW oWnd TITLE 'XBrowse Circle Gradient BackGrounds'
@ 0, 0 XBROWSE oBrw OF oWnd ;
ALIAS 'CUSTOMER' AUTOCOLS ;
CELL LINES ;
COLOR CLR_WHITE, CLR_BLUE
SET MESSAGE OF oWnd TO FWVERSION 2007
oBrw:SetBackGround( hBmp, BCK_STRETCH )
DeleteObject( hBmp )
oBrw:CreateFromCode()
oWnd:oClient := oBrw
ACTIVATE WINDOW oWnd
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <math.h>
#define PI 3.14159265
#define BRUSH 1
#define BITMAP 2
#ifdef __XHARBOUR__
int hb_parvni( int iParam, int iIndex );
#endif
HGDIOBJ CircleGradient( HDC hDC, RECT * rect, COLORREF startColor, COLORREF endColor, INT iOffSetX, INT iOffSetY, int iOutPut );
HGDIOBJ CircleGradient( HDC hDC, RECT * rect, COLORREF startColor, COLORREF endColor, INT iOffSetX, INT iOffSetY, int iOutPut )
{
int i, j;
float fRadio;
HBITMAP hBitmap;
HBITMAP hOldBitmap;
HBRUSH hBrush;
HDC hMemDC;
// Calculate image size
int width;
int height;
int isize;
double radius, diameterx, diametery;
char *m_Data;
int icenterx, icentery;
diameterx = ( rect->right - rect->left);
diametery = ( rect->bottom - rect->top);
icentery = diametery * 0.5 ;
icenterx = diameterx * 0.5 ;
width = rect->right - rect->left;
height = rect->bottom - rect->top;
radius = sqrt( pow( icenterx, 2 ) + pow( icentery, 2 ) ) ;
isize = height * width * 4;
// Create data buffer
m_Data = hb_xgrab( isize );
// Create gradient
for ( i = 0; i < height; i++ )
{
for ( j = 0; j < width; j++ )
{
LONG lRed, lBlue, lGreen;
fRadio = sqrt( pow( ( j - icenterx - iOffSetX ), 2 ) + ( pow( ( i - icentery - iOffSetY ), 2 ) ) ) / radius * 100.0;
if ( fRadio > 0.0 )
{
if( fRadio > 100.0 )
{
lRed = GetBValue( endColor );
lGreen = GetGValue( endColor );
lBlue = GetRValue( endColor );
}else
{
lRed = GetBValue( startColor ) + ( fRadio * 0.01 * ( GetBValue( endColor ) - GetBValue( startColor ) ) );
lGreen = GetGValue( startColor ) + ( fRadio * 0.01 * ( GetGValue( endColor ) - GetGValue( startColor ) ) );
lBlue = GetRValue( startColor ) + ( fRadio * 0.01 * ( GetRValue( endColor ) - GetRValue( startColor ) ) );
}
}
else
{
lRed = GetBValue( startColor );
lGreen = GetGValue( startColor );
lBlue = GetRValue( startColor );
}
m_Data[ i * width * 4 + j * 4 ] = lRed;
m_Data[ i * width * 4 + j * 4 + 1] = lGreen;
m_Data[ i * width * 4 + j * 4 + 2] = lBlue;
}
}
hBitmap = CreateBitmap( width, height, 1, 32, m_Data );
// Free memory
SelectObject( hMemDC, hOldBitmap );
DeleteDC(hMemDC);
hb_xfree( m_Data );
if( iOutPut == BRUSH )
{
hBrush = CreatePatternBrush( hBitmap );
DeleteObject( hBitmap );
return hBrush;
}
else if( iOutPut == BITMAP ) return hBitmap;
else if( hDC != 0 )
{
hBrush = CreatePatternBrush( hBitmap );
FillRect( hDC, rect, hBrush );
DeleteObject( hBrush );
}
DeleteObject( hBitmap );
return 0;
}
HB_FUNC( CIRCLEGRADIENT ) // hDC, { nTop, nLeft, nBottom, nRight },
// startColor, endColor, nOffserX,
// nOffserY, lBrush --> hBitmap / hBrush ( GDI OBJECT )
{
RECT rct;
INT iOffX = 0, iOffY = 0;
INT iOutPut = 3;
rct.top = hb_parvni( 2, 1 );
rct.left = hb_parvni( 2, 2 );
rct.bottom = hb_parvni( 2, 3 );
rct.right = hb_parvni( 2, 4 );
if( hb_pcount() > 4 )
iOffX = hb_parni( 5 );
if( hb_pcount() > 5 )
iOffY = hb_parni( 6 );
if( hb_pcount() > 6 )
iOutPut = hb_parni( 7 );
hb_retnl( ( LONG ) CircleGradient( ( HDC ) hb_parnl( 1 ),
&rct,
( COLORREF ) hb_parnl( 3 ),
( COLORREF ) hb_parnl( 4 ),
iOffX,
iOffY,
iOutPut ) );
}
#pragma ENDDUMP