Print Windows Form

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
bpd2000
Posts: 1013
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 163 times
Been thanked: 70 times

Re: Print Windows Form

Post by bpd2000 » Sat Oct 15, 2016 10:06 am

Thank you Esgici for your modification
BPD
Convert Dream into Reality through HMG

User avatar
mol
Posts: 2985
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 160 times
Been thanked: 85 times
Contact:

Post by mol » Thu Mar 30, 2017 12:48 pm

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: 5210
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 155 times
Been thanked: 144 times
Contact:

Post by Rathinagiri » Thu Mar 30, 2017 1:44 pm

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: 2985
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 160 times
Been thanked: 85 times
Contact:

Post by mol » Thu Mar 30, 2017 3:05 pm

thank you very much!

User avatar
mol
Posts: 2985
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 160 times
Been thanked: 85 times
Contact:

Post by mol » Thu Mar 30, 2017 6:39 pm

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: 2985
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 160 times
Been thanked: 85 times
Contact:

Post by mol » Thu Dec 14, 2017 9:39 am

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: 2985
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 160 times
Been thanked: 85 times
Contact:

Post by mol » Thu Dec 14, 2017 12:22 pm

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: 116
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain
Has thanked: 29 times
Been thanked: 21 times

Post by BeGeS » Thu Jan 11, 2018 9:39 pm

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: 927
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 13 times
Been thanked: 36 times
Contact:

Post by andyglezl » 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...
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
mol
Posts: 2985
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 160 times
Been thanked: 85 times
Contact:

Post by mol » Fri Jan 12, 2018 6:30 am

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