주어진 폼을 프린트 하는 기능을 여러 군데서 짜집기를 해서 만들었습니다.
가장큰 차이점은 GetFormImage() 함수를 사용하지 않은 점입니다.
간혹 무한루프를 타서요...
void __fastcall TFormMain::ButtonPrintClick(TObject *Sender)
{
//
TForm * pForm = FormMain; // Set Printing Form
Graphics::TBitmap *mjbmp = new Graphics::TBitmap();
mjbmp->Width = pForm->ClientWidth;
mjbmp->Height = pForm->ClientHeight;
mjbmp->Canvas->CopyRect ( Rect(0, 0,mjbmp->Width, mjbmp->Height),
pForm->Canvas, Rect(0, 0, pForm->ClientWidth, pForm->ClientHeight));
if (!PrintDialog1->Execute()) return;
//Graphics::TBitmap *mjbmp= FormMain->GetFormImage();
TPrinter *prt=Printer();
mjbmp->HandleType=bmDIB; // This is *VERY* important
double h=mjbmp->Height,w=mjbmp->Width,fct,wf;
if (w>h) prt->Orientation=poLandscape;
else prt->Orientation=poPortrait;
prt->Title="SPINDLE TEST PRINT";
wf=(double)prt->PageWidth/w;
fct=(double)prt->PageHeight/h;
if (fct>wf) fct=wf;
prt->BeginDoc();
prt->Canvas->StretchDraw(Rect(0,0,fct*w-1,fct*h-1),mjbmp);
prt->Canvas->TextOut(0,0,"PRINT OK");
prt->EndDoc();
delete mjbmp;
}
|
GetFormImage에 무슨 문제가 있는지 잘 이해가 안되네요
어떤 경우에 무한루프를 타는지요? 아직 저는 격어보지 못해서요..
위 코드이 방식이 GetFormImage와 한가지 다른점이 있는데요
위 방식은 현재 Desktop 화면에서 Form의 Client영역을 캡쳐하는것으로써
만약 Form앞에 TopMost로 다른 window가 떠 있는 경우
그 윈도우까지 캡쳐되죠
하지만 GetFormImage는 그것과 상관없이
화면에 가려 전혀 보이지 않더라도 화면image를 캡쳐할수 있습니다.
GetFormImage보다는 위 방식이 간단하고 , 속도는 좀 빠르겠네요