如何能程序设置默认打印机的打印纸大小与方向?
解决方案 »
- 请问如何把这样的时间格式转换一下
- 上海delphi程序员,工资标准多少啊
- ★上星了,第2颗太难挣了,就算了吧,转j2ee了,
- 如何判断当前用户用的是什么操作系统??
- delphi中读取access时间字段的问题,急!!!
- 为什么select * from hxyzl where hxyzh='%1%'语句不能把所有以‘1’开头的记录找出来?
- 编译项目时遇到 [Error] File not found: 'OGCONST.R32', 找不到那里有引用这个文件
- 如何能找到执行程序的当前目录
- 谁能告诉我TInterFace的意义?
- 怎样用DELPHI对有密码的ACCESS库(.mdb)解密?
- 关于新闻组软件的编写
- 软件考试天津成绩?
给你一点代码 参考一下
PRINTDLG pd;
pd.lStructSize=(DWORD)sizeof(PRINTDLG);
BOOL bRet=GetPrinterDeviceDefaults(&pd);
POSITION pos = GetFirstDocTemplatePosition( );
while (pos)
{
CSingleDocTemplate *ptemp = (CSingleDocTemplate*)GetNextDocTemplate( pos ) ;
POSITION posDoc = ptemp->GetFirstDocPosition();
while(posDoc){
CSCReportDoc * pDocument = (CSCReportDoc *)ptemp->GetNextDoc(posDoc);
if (pDocument)
{
LPDEVMODE pDevMode=(LPDEVMODE )::GlobalLock(m_hDevMode);
pDevMode->dmOrientation= pDocument->GetPrintOrient();
pDevMode->dmPaperSize =pDocument->GetPrintSize();
::GlobalUnlock(m_hDevMode); CWinApp::OnFilePrintSetup(); pDevMode=(LPDEVMODE )::GlobalLock(m_hDevMode);
pDocument->SetPrintOrient(pDevMode->dmOrientation);
pDocument->SetPrintSize(pDevMode->dmPaperSize);
::GlobalUnlock(m_hDevMode);
}
}
}
在打印前调用以下函数procedure SetPaperSize(X, Y: Integer);
// 这段代码绝对可用。单位是0.1mm
// A4时 Printer.Pagewidth:=1440; A5时 Printer.Pagewidth:=1049;
// B5时 Printer.Pagewidth:=1290; 16K时 Printer.Pagewidth:=1035;
// lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
PDMode: PDEVMODE;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
if (x = 0) or (y = 0) then
begin
{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
{pDMode^.dmPaperSize := DMPAPER_LEGAL; changed by wulianmin}
pDMode^.dmPaperSize := DMPAPER_FANFOLD_US;
end
else
begin
{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := x {SomeValueInTenthsOfAMillimeter};
pDMode^.dmPaperLength := y {SomeValueInTenthsOfAMillimeter};
end;
{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL; GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
//以下开始打印
end;