小弟 正做一个传真服务器 上的小模块
对邮件里发过来的 附件里的可打印文档 做为传真 发出去...
我现在是这样做的...
1: 分解邮件,然后把附件里的所有附件 一个个 放到一个指定的目录下, 如果是.tif /.tiff 文件 就直接发出去.如果是 .txt/htm/.doc 等..可打印的文档, 我就把它们
shellexcute(0,'print','..\beyond.txt',nil,nil,nil) 打印一下
然后再把打印出来的 .tif文件发出去...
现在问题是:
这个函数只能调用默认的打印机来打印.
而我想要的是,要调用我想要的打印机来打印,不能调用打印机配置窗口来选择想要的打印机,因为传真服务器是无人职守的. 我用 printer.printerindex 那个来设置..没有用.. 谁能告诉我...
如何 在程序中调用一个打印机来打印,而不管默认的打印机是哪个.
或者: 如何在程序中把一个打印机设为默认打印机,急啊//
大哥门江湖救急忙啊....
对邮件里发过来的 附件里的可打印文档 做为传真 发出去...
我现在是这样做的...
1: 分解邮件,然后把附件里的所有附件 一个个 放到一个指定的目录下, 如果是.tif /.tiff 文件 就直接发出去.如果是 .txt/htm/.doc 等..可打印的文档, 我就把它们
shellexcute(0,'print','..\beyond.txt',nil,nil,nil) 打印一下
然后再把打印出来的 .tif文件发出去...
现在问题是:
这个函数只能调用默认的打印机来打印.
而我想要的是,要调用我想要的打印机来打印,不能调用打印机配置窗口来选择想要的打印机,因为传真服务器是无人职守的. 我用 printer.printerindex 那个来设置..没有用.. 谁能告诉我...
如何 在程序中调用一个打印机来打印,而不管默认的打印机是哪个.
或者: 如何在程序中把一个打印机设为默认打印机,急啊//
大哥门江湖救急忙啊....
解决方案 »
- delphi 用comobj 读取excel表格中的数据 并且用dbgrid显示的问题
- 怎么检测到电脑正在播放音乐,只要能检测到就可以了!
- delphi群号3562775,希望大家都能学到东西
- select语句怎么样取得两个字段的和?
- COM+的问题,非高勿入
- 分享:Delphi导入EXCEL数据表的交互技术(全用代码实现)
- 求一个支持正/反 零宽断言 的DELPHI 版本 正则库
- 我建立的图标的资源文件,怎样在程序中加入和使用?
- 如何用delphi将gif文件设为墙纸(pc上)?
- 〓〓〓〓 如何在rxlib的richedit中插入图片 〓〓〓〓
- 是不是我的delphi有问题
- 获奖了,获奖了,兄弟们去领啊!我先放分200!
这是一个设置默认打印机的程序
unit MainFrm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TMainForm = class(TForm)
cbPrinters: TComboBox;
lblPrinter: TLabel;
procedure FormCreate(Sender: TObject);
procedure cbPrintersChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation
uses IniFiles, Printers;{$R *.DFM}procedure TMainForm.FormCreate(Sender: TObject);
begin
cbPrinters.Items.Assign(Printer.Printers);
cbPrinters.Text := Printer.Printers[Printer.PrinterIndex];
lblPrinter.Caption := Printer.Printers[Printer.PrinterIndex];
end;procedure TMainForm.cbPrintersChange(Sender: TObject);
var
IniFile: TIniFile;
TempStr1, TempStr2: String;
S: array[0..64] of char;
begin
with Printer do
begin
PrinterIndex := cbPrinters.ItemIndex;
TempStr1 := Printers[PrinterIndex];
System.Delete(TempStr1, Pos(' on ', TempStr1), Length(TempStr1));
IniFile := TIniFile.Create('WIN.INI');
try
TempStr2 := IniFile.ReadString('Devices', TempStr1, '');
IniFile.WriteString('windows', 'device', TempStr1 + ',' + TempStr2);
StrCopy(S, 'windows');
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@S));
finally
IniFile.Free;
end;
end;
lblPrinter.Caption := Printer.Printers[Printer.PrinterIndex];
end;end.
{
char Buffer[256], tmpBuf[256];
long iDefaultIsThere = -1;
long iColPos;
size_t iBufLen; GetProfileString("windows", "device", ",,,", Buffer, sizeof(Buffer));
iBufLen = strlen(Buffer); if (iBufLen > 0) {
iDefaultIsThere = 0; // there is a default printer // make sure that temp buffer is clean
memset (tmpBuf, 0, sizeof(tmpBuf)); // get comma position
for (iColPos = 0; Buffer[iColPos] != ','; iColPos++)
; // do nothing // copy iColPos + 1 bytes
strncpy(tmpBuf, Buffer, iColPos);
strcat (tmpBuf, "\0"); // terminate string strcpy(szDefaultPrinterName, tmpBuf); } return iDefaultIsThere;
}
long SWGetDefaultPrinterDriver(LPSTR szDriver)
{
char Buffer[256], tmpBuf[256];
long iDefaultIsThere = -1;
long iColPos, iFirstColPos = 0;
size_t iBufLen; GetProfileString("windows", "device", ",,,", Buffer, sizeof(Buffer));
iBufLen = strlen(Buffer); if (iBufLen > 0) {
iDefaultIsThere = 0; // there is a default driver memset(szDriver, 0, sizeof(szDriver));
memset(tmpBuf, 0, sizeof(tmpBuf)); // find first column
for (iColPos = 0; Buffer[iColPos] != ','; iColPos++)
iFirstColPos = iColPos; // save column position ++iFirstColPos;
++iFirstColPos; // find second column
for (iColPos = iFirstColPos; Buffer[iColPos] != ','; iColPos++)
; // do nothing strncpy(tmpBuf, Buffer + iFirstColPos, (iColPos -iFirstColPos));
strcat (tmpBuf, "\0"); strcpy(szDriver, tmpBuf);
} return iDefaultIsThere;
}long SWGetDefaultPrinterPort(LPSTR szPort)
{
char Buffer[256], tmpBuf[256];
long iDefaultIsThere = -1;
long iColPos, iSecondColPos = 0;
size_t iBufLen; GetProfileString("windows", "device", ",,,", Buffer, sizeof(Buffer));
iBufLen = strlen(Buffer); if (iBufLen > 0) { iDefaultIsThere = 0; // there is a default driver memset(tmpBuf, 0, sizeof(tmpBuf));
// find first column
for (iColPos = 0; Buffer[iColPos] != ','; iColPos++)
iSecondColPos = iColPos; // save column position ++iSecondColPos;
++iSecondColPos; // find second column
for (iColPos = iSecondColPos; Buffer[iColPos] != ','; iColPos++)
iSecondColPos = iColPos; // save column position ++iSecondColPos;
++iSecondColPos; strncpy(tmpBuf, Buffer + iSecondColPos, (iBufLen -iSecondColPos));
strcat (tmpBuf, "\0"); strcpy(szPort, tmpBuf);
}
return iDefaultIsThere;
}char szMsg[512] = "";
#define cnstDefaultPrinter "Synway Fax Printer"
long SWSetDefaultPrinter()
{
char szDefaultPrinterName[256] = ""; SWGetDefaultPrinterName(szDefaultPrinterName); sprintf(szMsg, "SWSetDefaultPrinter SWGetDefaultPrinterName is [%s]", szDefaultPrinterName); if (stricmp(szDefaultPrinterName, cnstDefaultPrinter) == 0)
{
return 0;
} // brute test
if (SWCheckPrinterName(cnstDefaultPrinter) == FALSE)
return -1; // To set the default printer for Windows NT use:
/* Note printer driver is usually WINSPOOL under Windows NT */
char Driver[256], PrinterDriverPort[1000]; memset(Driver, 0, sizeof(Driver));
//memset(Port, 0, sizeof(Port));
memset(PrinterDriverPort, 0, sizeof(PrinterDriverPort)); // get other info
//SWGetDefaultPrinterPort(Port);
SWGetDefaultPrinterDriver(Driver);
// put them all together
strcpy(PrinterDriverPort, cnstDefaultPrinter);//printer driver
strcat(PrinterDriverPort, ",");
strcat(PrinterDriverPort, Driver); //printer name
strcat(PrinterDriverPort, ",");
strcat(PrinterDriverPort, "fax"); //port
strcat(PrinterDriverPort, "\0"); //eg "My Printer,WINSPOOL,lpt1:"
WriteProfileString("windows", "device", PrinterDriverPort);
PostMessage(HWND_BROADCAST, WM_WININICHANGE, 0L, 0L); return 0;
}