Page 1 of 1

How can i use the (BITMAP TextOut( hDC, 5, 5, cMsg )) ?

Posted: Tue Apr 01, 2008 4:30 am
by yunbg1
Hi All

Why the execution is not.

Code: Select all

 

#include "FiveWin.ch" 

#define CR chr(13) 

Function main() 

publ oWnd, oField := array(250), count := 1 , oFont 

DEFINE FONT oFont NAME GetSysFont() SIZE 0, -8 

DEFINE WINDOW oWnd 

   for i  := 1 to 50 
       for j := 1 to 5 

          @ (i*26), (j*75)  BITMAP oField[count] FILENAME "test.bmp" NOBORDER  SIZE 70, 24 OF oWnd ADJUST PIXEL 

           oField[count]:bPainted  := { |hDC| OnPaint( hDC, str(count, 3), oFont ) ) } 

           oField[count]:bLClicked := GenBlock(count) 

           count += 1 
      next 
   next 

ACTIVATE WINDOW oWnd 

oFont:End() 

return nil 

//------------------------------------------------ 
func GenBlock( n ) 
RETU { || test_button( n ) } 

//------------------------------------------------ 
FUNC OnPaint( hDC, cMsg, oFont ) 

local hOldFont 

hOldFont := SelectObject( hDC, oFont:hFont ) 
SetBkMode( hDC, TRANSPARENT ) 
TextOut( hDC, 5, 5, cMsg ) 
SelectObject( hDC, hOldFont ) 

RETU NILl 

//------------------------------------------------ 
FUNC test_button(n) 

msginfo(n) 

RETU NIL 


Posted: Tue Apr 01, 2008 8:29 am
by Antonio Linares
Again you have to do it the same way :-)

Code: Select all

#include "FiveWin.ch" 

#define CR chr(13) 

Function main() 

publ oWnd, oField := array(250), count := 1 , oFont 

DEFINE FONT oFont NAME GetSysFont() SIZE 0, -8 

DEFINE WINDOW oWnd 

   for i  := 1 to 50 
       for j := 1 to 5 

          @ (i*26), (j*75)  BITMAP oField[count] FILENAME "test.bmp" NOBORDER  SIZE 70, 24 OF oWnd ADJUST PIXEL 

           oField[count]:bPainted  := GenPaint( count, oFont )

           oField[count]:bLClicked := GenBlock(count) 

           count += 1 
      next 
   next 

ACTIVATE WINDOW oWnd 

oFont:End() 

return nil 

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

function Genpaint( n, oFont )

return { |hDC| OnPaint( hDC, str( n, 3), oFont ) } 
	
//------------------------------------------------ 

func GenBlock( n ) 

RETU { || test_button( n ) } 

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

#define TRANSPARENT 1

FUNC OnPaint( hDC, cMsg, oFont ) 

local hOldFont 

hOldFont := SelectObject( hDC, oFont:hFont ) 
SetBkMode( hDC, TRANSPARENT ) 
TextOut( hDC, 5, 5, cMsg ) 
SelectObject( hDC, hOldFont ) 

RETU NIL 

//------------------------------------------------ 
FUNC test_button(n) 

msginfo(n) 

RETU NIL 
Image

Posted: Tue Apr 01, 2008 10:00 am
by yunbg1
Hi Antonio Linares

The agony is solved and truth it is grateful

Thank you.

Textout

Posted: Wed Apr 02, 2008 10:41 am
by ukoenig
Hello,

TextOut( hDC, 5, 5, cMsg )

Is it possible, to center the text in relation to the
Bitmap-hight and font-size ?

5, 5 is a fixed position.

In the Bitmap-class there is oBmp:nHeight
// It returns the Bitmap-Height in Pixel

When a Font is defined, as a sample TFont:New("Arial", , -20, .F.,.T.)
I use => oFont:nlnpHeight * -1 from the font-class
and get 20 of the font-height.
But this is not the font-pixel-height.

with => ( oBmp:nHeight - < Fontpixelheight > ) / 2
i get the text centered vertical.

I still need the length of a written text in pixel of a defined font,
to make a text centered horizontal, inside of a bitmap.
I don't know, how to calculate this.

Regards

Uwe