Print Windows Form

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Print Windows Form

Post by bpd2000 »

Thank you Esgici for your modification
BPD
Convert Dream into Reality through HMG
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Print Windows Form

Post 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?
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Print Windows Form

Post 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   
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Print Windows Form

Post 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.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Print Windows Form

Post 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
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Print Windows Form

Post 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
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: Print Windows Form

Post 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.
I get by with a little help from my friends
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Print Windows Form

Post 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...
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Print Windows Form

Post 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.
Post Reply