Page 2 of 3

Re: Print Windows Form

Posted: Sat Oct 15, 2016 10:06 am
by bpd2000
Thank you Esgici for your modification

Re: Print Windows Form

Posted: Thu Mar 30, 2017 12:48 pm
by mol
Rathinagiri wrote:
Sat Oct 15, 2016 3:42 am
mol wrote:Nice work, thanks for sharing!

I don't know if it's good place to ask my question:

Is it the way to print bitmap created in memory without saving it to temporary file?

I need to generate labels for range of goods with barcodes.
These are the new functions we have:

Code: Select all

New Functions:

OpenPrinterGetDC()             -->   hDC of the current Open Printer

OpenPrinterGetPageDC()         -->   hDC of the current Page being printed

And you can use the following BosTaurus function to draw a bitmap in memory to the PageDC as above.

Code: Select all

BT_DrawBitmap (hDC, Row, Col, Width, Height, Mode_Stretch, hBitmap)

Draws a bitmap in the Device Context (DC) specified.

hDC: is a handle to the device context.

Row, Col, Width, Height: specifies the size of the rectangle in pixels in the DC where you will draw the bitmap. For default: Row = 0, Col = 0, Width = BT_BitmapWidth(hBitmap), Height = BT_BitmapHeight(hBitmap).

Mode_Stretch: sets the mode as the bitmap is adjusts (is stretches or compresses) in the specified rectangle in the DC, it is one of the constants: BT_SCALE, BT_STRETCH or BT_COPY (defined in BosTaurus.CH).

hBitmap: is a handle to the bitmap.

I want to refresh this topic. I need to create codebars and print them without saving to temporary file.
Have you working sample to place here?

Re: Print Windows Form

Posted: Thu Mar 30, 2017 1:44 pm
by Rathinagiri
Try this Marek.

Code: Select all

#include <hmg.ch>

Function Main
   define window main at 0, 0 width 200 height 200 main
      define button click
         row 10
         col 10
         caption 'Click me!'
         action barcodeprint()
      end button   
   end window
   main.center
   main.activate
Return

function barcodeprint
   local hDC, hBitmap
   select printer default preview
   start printdoc
   start printpage
   hDC := OpenPrinterGetPageDC()
   hBitmap := HMG_CreateBarCode( "http://harbour-project.org/",;
                   "QRCODE",;
                   2,;
                   110,;
                   .f.,;
                   '',;
                   { 0, 0, 0 },;
                   { 255, 255, 255 },;
                   .t.,;  // checksum
                   .f.,;  // wide2_5
                   .f. )  // wide3   

   BT_DrawBitmap ( hDC, ;
               150, ;
               150, ;
               600, 600, BT_STRETCH, hBitmap )   
   end printpage
   end printdoc   
return nil   

Re: Print Windows Form

Posted: Thu Mar 30, 2017 3:05 pm
by mol
thank you very much!

Re: Print Windows Form

Posted: Thu Mar 30, 2017 6:39 pm
by mol
How can I convert pixels to millimeters depend of printer selection?
From where can I get selected printer resolution to enumerate right scale for printing generated image?
Now I took 600 dpi for laser printers, but it can be 1200, too.

Re: Print Windows Form

Posted: Thu Dec 14, 2017 9:39 am
by mol
Hi guys!
I need to return to this topic.
I need to know printer resolution to print image directly from memory without using temporary file.

My code prints graph on whole page:

Code: Select all

	local i
	local nScale := 1
	local DPM := 600/25.4   // Dots per millimeter, for laser printers with 600 dpi resolution
	
	select printer default ;
			ORIENTATION	PRINTER_ORIENT_LANDSCAPE ;
			preview
		
	nWidth:= (GetPrintableAreaWidth()-20)*DPM

	start printdoc
	start printpage
	
	hDC := OpenPrinterGetPageDC()
	nScale := nWidth / BT_BitMapWidth(hGraphToPrint)
	
	// 25,10 - position on the page

	BT_DrawBitmap ( hDC, 25*DPM,  10*DPM,;
			nSkala* BT_BitMapWidth(hGraphToPrint),;
			nSkala* BT_BitMapHeight(hGraphToPrint),;
			BT_STRETCH,;
			hGraphToPrint)   
	end printpage
	end printdoc

Re: Print Windows Form

Posted: Thu Dec 14, 2017 12:22 pm
by mol
TaDa!

Some searching, some thinking and solution is ready!
I've prepared function
HMG_GetPrinterResolution( hDC) => { nResX, nRexY }

where you can get hDC after selecting printer and starting printdoc

This function return array of horizontal and vertical resolution in DPI (dot per inch) of selected printer in pixels.

Code: Select all

hDC := OpenPrinterGetDC()
aRes := HMG_GetPrinterResolution(  hDC)
msgdebug( aRes )


#pragma begindump
#include <windows.h>
#include <hbapi.h>

HB_FUNC ( HMG_GETPRINTERRESOLUTION )
{
	hb_reta (2);
	hb_storvni ( GetDeviceCaps( (HDC) hb_parnl (1), LOGPIXELSX ),         -1, 1 ); 
	hb_storvni ( GetDeviceCaps( (HDC) hb_parnl (1), LOGPIXELSY ),         -1, 2 ); 
} 
#pragma ENDDUMP

Re: Print Windows Form

Posted: Thu Jan 11, 2018 9:39 pm
by BeGeS
Hello friends! :)

The question seems to me a bit silly, but... :roll:

How can I print suspension points to a particular column?

Example:

Code.............: 000001
Description......: PEPPER MARMALADE
Price............: 2.35
:cry: :cry:


I want the next result without having to do several tests placing dots or spaces in one and another row until it fits.

Code .................: 000001
Description..........: PEPPER MARMALADE
Price .................: 2.35


PS: By printer. In screen solves quickly.

Re: Print Windows Form

Posted: Thu Jan 11, 2018 11:51 pm
by andyglezl
Hola BeGes

Deberás usar un Font de ancho fijo. ( Times New, Consolas, etc )

Ejemplo: PADR( "Price", 15, "." ) + ":"


NOTA:

Trata de hacer tu pregunta en un nuevo Post para que no se confundan o pierdan las respuestas...

Re: Print Windows Form

Posted: Fri Jan 12, 2018 6:30 am
by mol
andyglezl wrote:
Thu Jan 11, 2018 11:51 pm
Hola BeGes

Deberás usar un Font de ancho fijo. ( Times New, Consolas, etc )

Ejemplo: PADR( "Price", 15, "." ) + ":"


NOTA:

Trata de hacer tu pregunta en un nuevo Post para que no se confundan o pierdan las respuestas...
It won't work fine if you use proportional font.