I have a dialog where i paint a diagram with fillrect() and textout() commands.
I put a button on it to print this diagram.
But the printer just ejects an empty page.
Here my code. Perhaps someone solved the same problem?.
Thanks and regards,
Detlef
- Code: Select all Expand view RUN
- //////////////////////////
PROCEDURE Diagramm( oWnd )
//////////////////////////
LOCAL aLabel := aLast13Month( date(), .t. )
LOCAL aVal := array( 13 )
LOCAL cTitle := OemToAnsi( alltrim( tmp->artnr ) + " has been sold " + XTRIM( tmp->vk_total ) + " times" )
LOCAL nMonth := tmp->( fieldpos( "VK00M" ) )
LOCAL oDlg, oFnt, n
for n := 1 to 13
aVal [ n ] := tmp->( fieldget( n - 1 + nMonth ) )
next
aVal := aRevertArr( aVal )
DEFINE FONT oFnt NAME "Ms Sans Serif" SIZE 0, -8
DEFINE DIALOG oDlg NAME "GraphWin" ;
TITLE cTitle;
COLOR GetSysColor( COLOR_BTNTEXT ),;
GetSysColor( COLOR_BTNFACE ) FONT oFnt of oWnd
REDEFINE BUTTON ID 10 OF oDlg ACTION oDlg:End()
REDEFINE BUTTON ID 20 OF oDlg ACTION oDlg:hardcopy( 1 )
ACTIVATE DIALOG oDlg CENTERED ON PAINT GraphWnd( aVal, aLabel, .f. )
RELEASE FONT oFnt
RETURN
///////////////////////////////////////////
FUNCTION GraphWnd( aVal, aLabel, lNegativ )
///////////////////////////////////////////
LOCAL aRect, hWnd, hDC, oBrush, n, nVal
LOCAL nYDim, nXDim, nYStart, nXStart, nYEnd, nXEnd, nXStep, nYStep, nYMax
DEFAULT lNegativ := .t.
DEFAULT aVal := { 30, 25, 42, 75, 37, 2, 68, 54, 46, 27, 61, 112 }
DEFAULT aLabel := { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec" }
hWnd := GetActiveWindow()
hDC := GetDC( hWnd )
// get coordinates of actual window
// --------------------------------
aRect := GetClientRect( hWnd )
// making the drawing-window a bit smaller
// ---------------------------------------
nYStart := aRect[ 1 ] + 10
nXStart := aRect[ 2 ] + 50
nYEnd := aRect[ 3 ] - 80
nXEnd := aRect[ 4 ] - 10
// valid X- and Y-Dimensions
// -------------------------
nYDim := nYEnd - nYStart + 1
nXDim := nXEnd - nXStart + 1
// searching maximum Y-Value
// -------------------------
nYMax := 0
for n := 1 to len( aVal )
nYMax := max( nYMax, aVal[n] )
next
// Scaling Factors for X and Y-Axes
// --------------------------------
nXStep := nXDim / ( len( aVal ) * 2 )
nYStep := ( nYDim - 20 ) / nYMax
// | this is only for NOT hitting exactly
// +- the top of the output-window
// drawing the output-window
// -------------------------
WndBoxRaised( hDC, nYStart - 2, nXStart, nYEnd + 2, nXEnd )
SetTextColor( hDC, CLR_BLACK )
SetBkColor ( hDC, GetSysColor( COLOR_BTNFACE ) )
DEFINE BRUSH oBrush COLOR CLR_R_YELLOW
// drawing the bars for all values
// -------------------------------
for n := 1 to len( aVal )
nVal := aVal[ n ]
FillRect( hDC, { if ( !lNegativ .and. nVal < 0, nYEnd + 1, nYEnd + 1 - ( nVal * nYStep ) ),; // top-Y-Value
nXStart + ( ( n - 1 ) * nXStep * 2 ) + ( ( nXStep - 1 ) / 2 ),;
nYEnd + 1,; // bottom-Y-Value
nXStart + ( ( n - 1 ) * nXStep * 2 ) + ( ( nXStep - 1 ) / 2 )+ nXStep;
},;
oBrush:hBrush )
// drawing numeric Y-values to the bars
// ------------------------------------
TextOut( hDC,;
if ( !lNegativ .and. nVal < 0, nYEnd + 1 - 20, nYEnd + 1 - ( aVal[ n ] * nYStep ) - 20 ),;
nXStart + ( ( n - 1 ) * nXStep * 2 ) + ( ( nXStep - 1 ) / 2 ) - 2,;
padl( XTRIM( aVal[ n ] ), 3 ) )
// drawing the labels for X-Axes
// -----------------------------
TextOut( hDC, nYEnd + 4,;
nXStart + ( ( n - 1 ) * nXStep * 2 ) + ( ( nXStep - 1 ) / 2 ) - 2,;
aLabel[ n ] )
next
// show Label with years at bottom line
// ------------------------------------
TextOut( hDC, nYEnd + 25, nXStart + ( ( nXStep - 1 ) / 2 ) - 2 , str( year( date() ) - 1, 4, 0 ) )
TextOut( hDC, nYEnd + 25, nXEnd - 35, str( year( date() ), 4, 0 ) )
RELEASE BRUSH oBrush
ReleaseDc( hWnd, hDC )
RETURN NIL
///////////////////////////////////////
FUNCTION aLast13Month( dStart, lLabel )
///////////////////////////////////////
LOCAL nMonth := month( dStart )
LOCAL nYear := year( dStart )
LOCAL n := 0
LOCAL aRet := {}
LOCAL aMonth := { "Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez" }
LOCAL cBuf := ""
DEFAULT lLabel := .f.
cBuf := cYearMonth( dStart )
aadd( aRet, if( lLabel, aMonth[ val( right( cBuf, 2 ) ) ], cBuf ) )
for n := 1 to 12
if ( --nMonth < 1 )
--nYear
nMonth := 12
endif
cBuf := cYearMonth( ctod( "01." + strzero( nMonth, 2, 0 ) + "." + strzero( nYear, 4, 0 ) ) )
aadd( aRet, if( lLabel, aMonth[ val( right(cBuf, 2 ) ) ], cBuf ) )
next
if lLabel
aRet := aRevertArr( aRet )
endif
RETURN( aRet )