与EM_FORMATRANGE使用有关的问题 |
尚未結案
|
fangwy
中階會員 ![]() ![]() ![]() 發表:99 回覆:139 積分:62 註冊:2003-09-10 發送簡訊給我 |
我采取以下方式控制RichEdit打印(代码是引用本站一个大大的回贴),问题是:这段代码只能打印一页,不知如何控制打印多页.
我的思路是知道上一页打印的结束位置,重设fmtRange.chrg.cpMin NewPage一页再接着打印.但如何能知道上一页打印到那里了?
说明一下,我试过其他方法打印:RichEdit的print好象无法控制左右上下边距,而且好象遇到表格会出错(不确定是不是表格造成的错误);QRRechText,可能版本的原因,无法打印图片,一些格式如上/下标也无法打印.
var
printarea: Trect;
x, y: Integer;
richedit_outputarea: TRect;
printresX, printresY: Integer;
fmtRange: TFormatRange;
prtRange: TEXTRANGE;
begin
Printer.beginDoc;
try
with Printer.Canvas do begin
printresX := GetDeviceCaps(handle, LOGPIXELSX);
printresY := GetDeviceCaps(handle, LOGPIXELSY);
{ Font.Name := 'Arial';
Font.Size := 14;
Font.Style := [fsBold];}
printarea :=
Rect(printresX, // 1 inch left margin
printresY * 3 div 2, // 1.5 inch top margin
Printer.PageWidth - printresX, // 1 inch right margin
Printer.PageHeight - printresY * 3 div 2 // 1.5 inch bottom margin
);
x := printarea.left;
y := printarea.top;
{ TextOut( x, y, 'A TRichEdit print example' );
y := y TextHeight('Ag');
Moveto( x, y );
Pen.Width := printresY div 72; // 1 point
Pen.Style := psSolid;
Pen.Color := clBlack;
LineTo( printarea.Right, y );
Inc( y, printresY * 5 div 72 );} // Define a rectangle for the rich edit text. The height is set to the
// maximum. But we need to convert from device units to twips,
// 1 twip = 1/1440 inch or 1/20 point.
richedit_outputarea :=
Rect((printarea.left 2) * 1440 div printresX,
y * 1440 div printresY,
(printarea.right - 4) * 1440 div printresX,
(printarea.bottom) * 1440 div printresY); // Tell rich edit to format its text to the printer. First set
// up data record for message:
fmtRange.hDC := Handle; // printer canvas handle
fmtRange.hdcTarget := Handle; // ditto
fmtRange.rc := richedit_outputarea;
fmtRange.rcPage :=
Rect(0, 0,
Printer.PageWidth * 1440 div printresX,
Printer.PageHeight * 1440 div printresY); // the following lines select the text to print, in this case
// the complete content of the rich edit control.
reText.Perform(EM_EXGETSEL, 0, Longint(@fmtRange.chrg));
if fmtRange.chrg.cpMax = 0 then
begin
fmtRange.chrg.cpMin := 0; //reText.SelStart;
fmtRange.chrg.cpMax := reText.GetTextLen - 1;
end; // first measure the text, to find out how high the format rectangle
// will be. The call sets fmtrange.rc.bottom to the actual height
// required, if all characters in the selected range will fit into
// a smaller rectangle,
reText.Perform(EM_FORMATRANGE, 0, Longint(@fmtRange)); // Draw a rectangle around the format rectangle
{ Pen.Width := printresY div 144; // 0.5 points
Brush.Style := bsClear;
Rectangle( printarea.Left, y - 2, printarea.right,
fmtrange.rc.bottom * printresY div 1440 2 );} // Now render the text
reText.Perform(EM_FORMATRANGE, 1, Longint(@fmtRange));
// and print it
reText.Perform(EM_DISPLAYBAND, 0, Longint(@fmtRange.rc));
y := fmtrange.rc.bottom * printresY div 1440 printresY * 5 div 72; // Free cached information
reText.Perform(EM_FORMATRANGE, 0, 0);
// TextOut( x, y, 'End of example.' ); //reText.Perform( EM_GETTEXTRANGE, 0, Longint( @prtRange));
end;
finally
Printer.EndDoc;
end;
end;
|
fangwy
中階會員 ![]() ![]() ![]() 發表:99 回覆:139 積分:62 註冊:2003-09-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |