Form 의 Print 메소드가 Bitmap 을 Printer 에 출력하네요.
ListBox 도 Canvas->Bitmap 으로 접근이 가능할텐데...
아니면 Bitmap 에 Canvas 를 그대로 뿌려주던지 해서 적용하면 될 듯 하네요.
VCL 코드는 델파이라 일단 밑에 그냥 적어볼께요. 한번 보세요.
procedure TCustomForm.Print;
var
FormImage: TBitmap;
Info: PBitmapInfo;
InfoSize: DWORD;
Image: Pointer;
ImageSize: DWORD;
Bits: HBITMAP;
DIBWidth, DIBHeight: Longint;
PrintWidth, PrintHeight: Longint;
begin
Printer.BeginDoc;
try
FormImage := GetFormImage;
Canvas.Lock;
try
{ Paint bitmap to the printer }
with Printer, Canvas do
begin
Bits := FormImage.Handle;
GetDIBSizes(Bits, InfoSize, ImageSize);
Info := AllocMem(InfoSize);
try
Image := AllocMem(ImageSize);
try
GetDIB(Bits, 0, Info^, Image^);
with Info^.bmiHeader do
begin
DIBWidth := biWidth;
DIBHeight := biHeight;
end;
case PrintScale of
poProportional:
begin
PrintWidth := MulDiv(DIBWidth, GetDeviceCaps(Handle,
LOGPIXELSX), PixelsPerInch);
PrintHeight := MulDiv(DIBHeight, GetDeviceCaps(Handle,
LOGPIXELSY), PixelsPerInch);
end;
poPrintToFit:
begin
PrintWidth := MulDiv(DIBWidth, PageHeight, DIBHeight);
if PrintWidth < PageWidth then
PrintHeight := PageHeight
else
begin
PrintWidth := PageWidth;
PrintHeight := MulDiv(DIBHeight, PageWidth, DIBWidth);
end;
end;
else
PrintWidth := DIBWidth;
PrintHeight := DIBHeight;
end;
StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0, 0,
DIBWidth, DIBHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Image, ImageSize);
end;
finally
FreeMem(Info, InfoSize);
end;
end;
finally
Canvas.Unlock;
FormImage.Free;
end;
finally
Printer.EndDoc;
end;
end;
김택중 님이 쓰신 글 :
: 장우혁 님이 쓰신 글 :
: : : 이렇게만 하니까 내용이 출력되질 않고 가만히 있네요;;
: :
: : => 실제로 코드가 출력되지 않고 가만히 있으라는 코드 같습니다.
: :
: : if(PrintDialog1->Execute())
: : {
: : 이안에실제로어떤것을출력할지코드를작성해야함();
: : // 그런데 소스보면 브레이스안에 아무것도 없네요.
: : }
: :
: : 이런 식으로 작성하셔야 할 듯 한데요.
: : 제가 C++이 아니고 C인데다가 주로 콘솔쪽으로 개발하다보니 이런 쪽은 잼병인데요.
: :
: :
여기 를 참조해보시겠습니까?
: :
: : 대충 살펴보니 레퍼런스의 BeginDoc() 과 EndDoc() 사이의 부분을 살펴보셔야 할 듯 합니다.
:
: 답변 감사해요^^*
:
: 그런데요 링크 들어가봤더니 잘 들어가지지가 않아요...ㅡ.ㅜ;
:
: 혹시 ListBox가 아니더라도 프린트 하는 예제를 한번 보고 싶습니다.
:
: 혹시 예제 있으신 분 있으신지요?