怎样做打印时的“页面设置”功能???

gjgj3368 2003-06-28 05:09:21
比如说我做了一个报表,在打印之前有页面设置的要求,我应该怎么完成这个功能??谢谢!
...全文
374 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
watercelery 2003-07-22
  • 打赏
  • 举报
回复
靠,我试过用TPrinterSetupDialog,好象打印的时候,根本不起作用。
solares1 2003-07-20
  • 打赏
  • 举报
回复
gz
ljb198102 2003-07-06
  • 打赏
  • 举报
回复
拖一个空间即可
ybluo 2003-07-04
  • 打赏
  • 举报
回复
用TPrinterSetupDialog进行打印设置
gary_jojo 2003-07-04
  • 打赏
  • 举报
回复
mark
albeta 2003-07-03
  • 打赏
  • 举报
回复
是不是说用PrintDialog?
Yesing 2003-06-28
  • 打赏
  • 举报
回复
这么复杂?好像不是C++ BUilder的做法?
tccsdn 2003-06-28
  • 打赏
  • 举报
回复
显示打印对话框
UINT APIENTRY PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam);

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

void __fastcall TForm1::PrintDialogButtonClick(TObject *Sender)
{
PRINTDLG pd;
ZeroMemory(&pd, sizeof(PRINTDLG));

// initialize PRINTDLG
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = Handle;
pd.nCopies = 1;
pd.nFromPage = 0xFFFF;
pd.nToPage = 0xFFFF;
pd.nMinPage = 1;
pd.nMaxPage = 0xFFFF;
pd.Flags = PD_ENABLEPRINTHOOK;
pd.lpfnPrintHook = PrintHookProc;

if (PrintDlg(&pd))
{
// do some printing...

if (pd.hDevMode) GlobalFree(pd.hDevMode);
if (pd.hDevNames) GlobalFree(pd.hDevNames);
}
}
//---------------------------------------------------------------------------

UINT APIENTRY PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam)
{
if (uiMsg == WM_INITDIALOG)
{
// manipulate some controls in the hook procedure
// for example, disable the "Properties" button
HWND HPropButton = GetDlgItem(hdlg, psh2);
EnableWindow(HPropButton, false);
}
return 0L;
}

改变纸张大小:
//---------------------------------------------------------------------------
void __fastcall TForm1::PrintButtonClick(TObject *Sender)
{
// get the default printer name, driver, and port
char *def_string = "no printer";
char buffer[MAX_PATH];
GetProfileString("windows", "device", def_string,
buffer, MAX_PATH);

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

// parse the buffer to extract individual properties
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);

// open the printer
HANDLE HPrinter;
if (OpenPrinter(Device.c_str(), &HPrinter, NULL))
{
// call DocumentProerties() with a zero fMode parameter
// to get the number of bytes required
long int num_bytes;
num_bytes = DocumentProperties(NULL, HPrinter, Device.c_str(),
NULL, NULL, 0);

// allocate the memory
unsigned char *buffer = new unsigned char[num_bytes];

// call DocumentProperties() again, this time to get the
// device mode information
DocumentProperties(NULL, HPrinter, Device.c_str(),
(PDEVMODE)buffer, NULL, DM_OUT_BUFFER);

PDEVMODE pdm = (PDEVMODE)buffer;

// modify the appropriate fields
pdm->dmPaperSize = DMPAPER_10X14; // for example

// tell Windows which fields we changed
pdm->dmFields = pdm->dmFields | DM_PAPERSIZE;

// call DocumentProperties() yet again, this time to get
// the final DEVMODE to pass into the CreateDC() function
DocumentProperties(NULL, HPrinter, Device.c_str(),
pdm, pdm, DM_OUT_BUFFER | DM_IN_BUFFER);

// create a printer device context
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;

// start printing
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);
// print some text
::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);
}
}


yydy 2003-06-28
  • 打赏
  • 举报
回复
不会,关注

13,874

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧