Re: Print Windows Form
Posted: Sat Oct 15, 2016 10:06 am
Thank you Esgici for your modification
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://www.hmgforum.com/
Rathinagiri wrote: ↑Sat Oct 15, 2016 3:42 amThese are the new functions we have: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.
And you can use the following BosTaurus function to draw a bitmap in memory to the PageDC as above.Code: Select all
New Functions: OpenPrinterGetDC() --> hDC of the current Open Printer OpenPrinterGetPageDC() --> hDC of the current Page being printed
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.
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
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
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
It won't work fine if you use proportional font.