.


:




:

































 

 

 

 


Quick Report




: C++ Builder

VCL Synchronize().

:

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

#include <vcl.h>

#pragma hdrstop

 

#include "Unit1.h"

#include "Unit2.h"

#pragma package(smart_init)

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

// Synchronize :

//

// Synchronize(UpdateCaption);

//

// UpdateCaption :

//

// void __fastcall PrintQReport::UpdateCaption()

// {

// Form1->Caption = "Updated in a thread";

// }

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

__fastcall PrintQReport::PrintQReport(bool CreateSuspended)

: TThread(CreateSuspended)

{

}

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

void __fastcall PrintQReport::Execute()

{

//---- ----

Synchronize(Print);

}

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

void __fastcall PrintQReport::Print()

{

Form1->QuickRep1->Print();

}

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

 

 

, API DocumentProperties(). , ( ), OpenPrinter(). DocumentProerties() fMode, , DEVMODE. , DocumentProperties(), , . . DocumentProperties(), DEVMODE CreateDC().

 

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

void __fastcall TForm1::PrintButtonClick(TObject *Sender)
{
// ,
char *def_string = "no printer";
char buffer[MAX_PATH];
GetProfileString("windows", "device", def_string,
buffer, MAX_PATH);

AnsiString Abuffer(buffer);
AnsiString Device, Driver, Port;

//
int first_comma = Abuffer.Pos(",");
Device = Abuffer.SubString(1, first_comma - 1);
Abuffer = Abuffer.SubString(first_comma + 1,
Abuffer.Length() - first_comma);
int second_comma = Abuffer.Pos(",");
Driver = Abuffer.SubString(1, second_comma - 1);
Port = Abuffer.SubString(second_comma + 1,
Abuffer.Length() - second_comma);

//
HANDLE HPrinter;
if (OpenPrinter(Device.c_str(), &HPrinter, NULL))
{
// DocumentProerties() fMode
//
long int num_bytes;
num_bytes = DocumentProperties(NULL, HPrinter, Device.c_str(),
NULL, NULL, 0);

//
unsigned char *buffer = new unsigned char[num_bytes];

// DocumentProperties(), ,
//
DocumentProperties(NULL, HPrinter, Device.c_str(),
(PDEVMODE)buffer, NULL, DM_OUT_BUFFER);

PDEVMODE pdm = (PDEVMODE)buffer;

//
pdm->dmPaperSize = DMPAPER_10X14; //

// Windows,
pdm->dmFields = pdm->dmFields | DM_PAPERSIZE;

// DocumentProperties(),
// DEVMODE CreateDC()
DocumentProperties(NULL, HPrinter, Device.c_str(),
pdm, pdm, DM_OUT_BUFFER | DM_IN_BUFFER);

//
HDC HPrinterDC = CreateDC(Driver.c_str(), Device.c_str(),
NULL, pdm);
if (HPrinterDC)
{
DOCINFO di;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Test Print";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;

//
if (StartDoc(HPrinterDC, &di))
{
if (StartPage(HPrinterDC))
{
float fLogPelsX1, fLogPelsY1;

fLogPelsX1 =
(float)GetDeviceCaps(HPrinterDC, LOGPIXELSX);
fLogPelsY1 =
(float)GetDeviceCaps(HPrinterDC, LOGPIXELSY);

RECT R = Rect(0, 0, fLogPelsX1 * 8.5, fLogPelsY1 * 11);
//
::DrawText(HPrinterDC, Memo1->Text.c_str(),
Memo1->Text.Length(), &R,
DT_LEFT | DT_EDITCONTROL | DT_WORDBREAK);

EndPage(HPrinterDC);
}
EndDoc(HPrinterDC);
}
DeleteDC(HPrinterDC);
}
delete [] buffer;
ClosePrinter(HPrinter);
}
}

 





:


: 2015-10-01; !; : 387 |


:

:

,
==> ...

1861 - | 1635 -


© 2015-2024 lektsii.org - -

: 0.01 .