BCB6如何设置默认打印机
本帖最后由 xjhwc 于 2013-05-27 10:34:39 编辑 XP系统有2个打印机,1:HP print,是默认打印机。2:epson print。如何用代码把默认打印机从HP print改成epson print。以下代码是可以,但SendMessage会对后面的程序造成其他影响,所以在不用SendMessage的情况下,如何设置默认打印机?
//设置默认打印机
char ADevice[300];
char ADriver[300];
char APort[300];
char s[300];
unsigned int hDeviceMode;
TPrinter* APrinter=Printer();
int nIndex=APrinter->Printers->IndexOf("epson print");
APrinter->PrinterIndex=nIndex;
APrinter->GetPrinterA(ADevice,ADriver,APort,hDeviceMode);
StrCopy(s,ADevice);
StrCat(s,",");
StrCat(s,ADriver);
StrCat(s,",");
StrCat(s,APort);
WriteProfileString("windows","device",s);
StrCopy(s,"windows");
SendMessage(HWND_BROADCAST,WM_WININICHANGE,0,(long)&s);
谢谢大家!
[解决办法]
有这两句就行了
int nIndex = APrinter->Printers->IndexOf("Challsoft PDF Printer");
APrinter->PrinterIndex = nIndex;