高手救我:如何设置打印机纸张大小及打印方向?

mjer_pan 2003-11-13 08:55:54
我在BCB的QuickRep中设置报表的纸张大小为自定义(297*210),即横向打印A4纸张。,可是安装到其它计算机上打印时,却还是按照A4纵向打印,变成每张报表打印前都要点击打印预览中的打印设置进行手动设置,设置为横向。
而且只支持LQ1600/1800/1900K……
请问这个问题要如何解决?
...全文
1089 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
3xcom 2004-03-25
  • 打赏
  • 举报
回复
收藏啊。
lss983 2004-03-25
  • 打赏
  • 举报
回复
up
zzhong2 2003-11-16
  • 打赏
  • 举报
回复
//下面是设置:

Printer()->Orientation = poPortrait;//纵向打印
Printer()->Orientation = poLandscape;//横向打印

DEVMODE *devmode;// DEVMODE结构指针
THandle devicehandle;//Printer句柄
if(ComboBox1->Items->Count<=0)
Abort();
devmode=NULL;
Printer()->GetPrinter(szDeviceName,szDriverName,szPortName,devicehandle);
if (devicehandle==0)
{
Printer()->PrinterIndex=Printer()->PrinterIndex;
Printer()->GetPrinter(szDeviceName,szDriverName,szPortName,devicehandle);
}
if(devicehandle!=0)
devmode=(DEVMODE *)GlobalLock((void *)devicehandle);
else
{
MessageBox(Handle,"打印机无法设置.","警告",MB_OK|MB_ICONWARNING);
return;
}

if(MaskEdit7->Text.ToDouble()<10||MaskEdit7->Text.ToDouble()>400)
{
MessageBox(Handle,"缩放比必须在10%~400%之间.","警告",MB_OK|MB_ICONWARNING);
return;
}
//为了使Printer的某些参数(TextHeight)在BeginDoc前后一至
Printer()->Orientation=Printer()->Orientation;

if(ComboBox1->Items->Strings[ComboBox1->ItemIndex]!="Custom")
{
devmode->dmFields=devmode->dmFields|DM_PAPERSIZE;
devmode->dmPaperSize=
ComboBox1->Items->Values[ComboBox1->Items->Names[ComboBox1->ItemIndex]].ToInt();
}
else
{
devmode->dmFields=devmode->dmFields|DM_PAPERSIZE;
devmode->dmPaperSize=0;
devmode->dmFields=devmode->dmFields|DM_PAPERWIDTH;
devmode->dmPaperWidth =MaskEdit5->Text.ToDouble()*10;
devmode->dmFields=devmode->dmFields|DM_PAPERLENGTH;
devmode->dmPaperLength =MaskEdit6->Text.ToDouble()*10;
}

devmode->dmFields=devmode->dmFields|DM_DEFAULTSOURCE;
devmode->dmDefaultSource=
ComboBox2->Items->Values[ComboBox2->Items->Names[ComboBox2->ItemIndex]].ToInt();
zzhong2 2003-11-16
  • 打赏
  • 举报
回复
其中PrinterComboBox装的是当前可用的打印机,用下面语句赋值。
PrinterComboBox->Items = Printer()->Printers;
ComboBox1装的是当前选中的打印机支持的纸型,以及纸型尺寸等信息
iNumOfPapers存的是纸型数量
pszPaperNames存的是纸型的名称
pwPaperTypes存的是纸型的类型号
PaperSize存的是纸型的大小尺寸
用下面程序从ComboBox1中取出纸型大小尺寸
MaskEdit5->Text=AnsiString((double)((POINT *)ComboBox1->Items->Objects[ComboBox1-

>ItemIndex])->x/10);
MaskEdit6->Text=AnsiString((double)((POINT *)ComboBox1->Items->Objects[ComboBox1-

>ItemIndex])->y/10);

ComboBox2存的是当前打印机的进纸盒信息,也就是纸张来源信息
要在头文件中定义下面的
private: // User declarations
// Device Name
char szDeviceName[MAX_PATH],//[CCHDEVICENAME],
// Driver Name
szDriverName[MAX_PATH],
// Port Name
szPortName[MAX_PATH];
//其中MAX_PATH在windef.h中有定义:
#define MAX_PATH 260
zzhong2 2003-11-16
  • 打赏
  • 举报
回复
void __fastcall TzzhPageSetupForm::PrinterComboBoxChange(TObject *Sender)
{
POINT *PaperSize;
int iLoop;
char *pszName;
char szTemp[MAX_PATH];
char *pszPos;
int iLength;
int iNumOfPapers;
WORD *pwPaperTypes;
char *pszPaperNames;
int iNumOfBins;
WORD *pwBinTypes;
char *pszBinNames;

ComboBox1->Items->Clear();
ComboBox2->Items->Clear();

// szDeviceName, szDriverName and szPortName as declared
// as private variables in the Form's class
//(in the Form's headerfile)
THandle hPrnDevMode; // Handle to the memory area
// containing the DEVMODE structure

// Get Printer Info (this way we avoid having to remove any
// eventual "On LPT1:" strings (which can be translated on
// other systems)

// Update selected printer (from selection in ComboBox)
Printer()->PrinterIndex = PrinterComboBox->ItemIndex;
// Printer()->PrinterIndex = -1;

// Get Name
Printer()->GetPrinter(szDeviceName, szDriverName,
szPortName, hPrnDevMode);
// Check if either the port name or driver name is empty
if (!strlen(szPortName) || !strlen(szDriverName))
{
// --- szPortName or szDriverName was empty, fill them ---
GetProfileString("Devices", szDeviceName, "",
szTemp, MAX_PATH);
// Find the index of the next comma
pszPos = StrPos(szTemp, ",");
if (pszPos)
{
iLength = strlen(szTemp)-strlen(pszPos);
// Get the driver name
strncpy(szDriverName, szTemp, iLength);
szDriverName[iLength] = '\0'; // Terminate string
// Get the port name
strcpy(szPortName, ++pszPos);
} // ! if
} // ! if

// Notice: In the project header file I've created a const
// names CCHPAPERNAME with the value 64. This should have
// been done by Microsoft, but they didn't do it, so we have
// to do it ourselves ;)

// Note: szDeviceName, szDriverName and szPortName are
// delcared as private variables Form's class
//(in the Form's headerfile) and are already filled with
// the information we need.

// Get the number of papers
// int iNumOfPapers;
iNumOfPapers = DeviceCapabilitiesA(szDeviceName,
szPortName,
DC_PAPERS,
NULL,
NULL);

if(iNumOfPapers<=0)
Abort();
// Allocate memory to contain the list of paper type-numbers
pwPaperTypes = new WORD[iNumOfPapers];
// Get the list of types
DeviceCapabilitiesA(szDeviceName,
szPortName,
DC_PAPERS,
(LPTSTR)pwPaperTypes,
NULL); //DC_PAPERS

// Allocate memory to contain the list of papersize
PaperSize = new POINT[iNumOfPapers];
// Get the list of types
DeviceCapabilitiesA(szDeviceName,
szPortName,
DC_PAPERSIZE,
(LPTSTR)PaperSize,
NULL);

// Allocate memory to contain all paper names
pszPaperNames = new char[iNumOfPapers*64];

// Get list of paper names
DeviceCapabilitiesA(szDeviceName,
szPortName,
DC_PAPERNAMES,
pszPaperNames,
NULL);


// Fill the ListBox with the information
for (iLoop=0; iLoop < iNumOfPapers; iLoop++)
{
pszName = &pszPaperNames[iLoop*64];
ComboBox1->Items->AddObject(AnsiString(pszName)+
"="+IntToStr(pwPaperTypes[iLoop]),(TObject *)&PaperSize[iLoop]);
}

if(ComboBox1->Items->Count>0)
{
ComboBox1->Items->Add("Custom");
ComboBox1->ItemIndex=ComboBox1->Items->IndexOfName("A4");
if(ComboBox1->ItemIndex<0)
ComboBox1->ItemIndex=0;
ComboBox1->OnChange(PrinterComboBox);
}

// Notice: In the project header file I've created a const
// names CCHBINNAME with the value 24. This should have been
// done by Microsoft, but they didn't do it, so we have to
// do it ourselves ;)

// Note: szDeviceName, szDriverName and szPortName are
// delcared as private variables Form's class (in the Form's
// headerfile) and are already filled with the information
// we need.

// Get the number of bins
iNumOfBins = DeviceCapabilitiesA(szDeviceName,
szPortName,
DC_BINS,
NULL,
NULL);

// Allocate memory to contain the list of bin type-numbers
pwBinTypes = new WORD[iNumOfBins];
// Get the list of types
DeviceCapabilitiesA(szDeviceName,
szPortName,
DC_BINS,
(LPTSTR)pwBinTypes,
NULL);

// Allocate memory to contain all bin names
pszBinNames = new char[iNumOfBins*24];

// Get list of paper names
DeviceCapabilitiesA(szDeviceName,
szPortName,
DC_BINNAMES,
pszBinNames,
NULL);


// Fill the ListBox with the information
// char *pszName;
for (iLoop=0; iLoop < iNumOfBins; iLoop++)
{
pszName = &pszBinNames[iLoop*24];
ComboBox2->Items->Add(AnsiString(pszName)
+"="+IntToStr(pwBinTypes[iLoop]));
}

if(ComboBox2->Items->Count>0)
{
ComboBox2->ItemIndex=ComboBox2->Items->IndexOfName("自动选择");
if(ComboBox2->ItemIndex<0)
ComboBox2->ItemIndex=0;
}


delete [] pwPaperTypes;
// delete []PaperSize;
delete []pszPaperNames;
delete []pwBinTypes;
delete []pszBinNames;
}

mjer_pan 2003-11-16
  • 打赏
  • 举报
回复
那这么说,还得对用户的计算机进行打印机设置了?
这样不是很麻烦?
CCLIS 2003-11-16
  • 打赏
  • 举报
回复
在WINDOWS的设置里设置打印机,将它的纸型设成你所需要的即可,程序里对打印机进行修改,一般不会影响到系统,退出程序再进入后,会自动取系统的值。

13,874

社区成员

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

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