给你一个例子: 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 { Copy the printer names to the combobox and set the combobox to show the currently selected default printer } cbPrinters.Items.Assign(Printer.Printers); cbPrinters.Text := Printer.Printers[Printer.PrinterIndex]; // Update the label to reflect the default printer 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 // Set the new printer based on the ComboBox's selected printer PrinterIndex := cbPrinters.ItemIndex; // Store the printer name into a temporary string TempStr1 := Printers[PrinterIndex]; // Delete the unnecessary portion of the printer name System.Delete(TempStr1, Pos(' on ', TempStr1), Length(TempStr1)); // Create a TIniFile class IniFile := TIniFile.Create('WIN.INI'); try // Retrieve the device name of the selected printer TempStr2 := IniFile.ReadString('Devices', TempStr1, ''); // Change the default printer to that chosen by the user IniFile.WriteString('windows', 'device', TempStr1 + ',' + TempStr2); // Tell all windows that the default printer changed. StrCopy(S, 'windows'); SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@S)); finally IniFile.Free; end; end; // Update the label to reflect the new printer selection lblPrinter.Caption := Printer.Printers[Printer.PrinterIndex]; end;end.
窗体上有个TComBox,命名为cb1,为当前的所以打印机列表。 窗体名为Form1procedure TForm1.FormCreate(Sender: TObject); begin cb1.items.assign(printer.printers); end;procedure TForm1.Button1Click(Sender: TObject); var LPrinter:string; PrinIniFile:Tinifile; LStr:string; begin LStr:=printer.Printers[cb1.itemindex]; delete(Lstr,pos(' on ',Lstr),Length(LStr)); PrinIniFile:=TIniFile.Create('WIN.ini'); try LPrinter:=PrinIniFile.ReadString('Devices',LStr,''); PrinIniFile.writestring('windows','device',LStr+','+LPrinter); finally PrinIniFile.free; end; end;
设置默认打印机 uses printers;
procedure SetDefaultPrinter(const printerindex:integer); Var FHandle : THandle; HPrt : THandle; PrtInfo5: PPrinterInfo5; FDevice: array[0..79] of char; FDriver: array[0..79] of char; FPort: array[0..79] of char;
设置打印参数是要修改TDeviceMode结构同yjq说的一样 var ADevice, ADriver, APort:array [0..255] of Char; DeviceHandle:THandle; DevMode:PDeviceMode;//TDeviceMode指针 begin {首先获取TPrinter的DeviceMode结构的句柄} PrinterGetPrinter(ADevice, ADriver, APort, DeviceHandle); {如果句柄是0, 表示打印机没有装载} if DeviceHandle=0 then begin Printer.PrinterIndex := Printer.PrinterIndex; Printer.GetPritner(ADevice, ADriver, APort, DeviceHandle); end; {如果DeviceHandle还是0, 表示有错误发生。否则,就调用} {GlobalLock来获取TDeviceMode结构的指针} if DeviceHandle=0 then Raise Exception.Create('Could Not Initialize TDeviceMode structure') else DevMode:=GlobalLock(DeviceHandle); {下面是设置纸张大小} with DevMode^ do begin dmFields:=dmFields or DM_PAPERSIZE; dmPaperSize:=DMPADER_LETTER;//LETTER,8-1/2 {如果纸张大小由dmPaperWidth和dmPaperLength设置,则dmPaperSize的值可以设为0} //dmFields:=dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH; //dmPaperLength:=somelength; //dmPaperWidth:=somewidth; end; if not DeviceHandle=0 then GlobalUnlock(DeviceHandle);
我的防火墙老是提示 [9:06:43] 61.136.132.166 (61.136.132.182)等试图连接本机的 Http[80] 端口, TCP标志: S 该操作被拒绝。 什么意思
procedure SetPrinter(DeviceMode, DeviceNames: THandle);
var
DevNames: PDevNames;
begin
DevNames := PDevNames(GlobalLock(DeviceNames));
try
with DevNames^ do
Printer.SetPrinter(PChar(DevNames) + wDeviceOffset,
PChar(DevNames) + wDriverOffset,
PChar(DevNames) + wOutputOffset, DeviceMode);
finally
GlobalUnlock(DeviceNames);
GlobalFree(DeviceNames);
end;
end;
如何调试ISAPI
来点明细的解决了,100分都是你的
来点明细的
帮帮忙吧,大侠们
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
{ Copy the printer names to the combobox and set the combobox to
show the currently selected default printer }
cbPrinters.Items.Assign(Printer.Printers);
cbPrinters.Text := Printer.Printers[Printer.PrinterIndex];
// Update the label to reflect the default printer
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
// Set the new printer based on the ComboBox's selected printer
PrinterIndex := cbPrinters.ItemIndex;
// Store the printer name into a temporary string
TempStr1 := Printers[PrinterIndex];
// Delete the unnecessary portion of the printer name
System.Delete(TempStr1, Pos(' on ', TempStr1), Length(TempStr1));
// Create a TIniFile class
IniFile := TIniFile.Create('WIN.INI');
try
// Retrieve the device name of the selected printer
TempStr2 := IniFile.ReadString('Devices', TempStr1, '');
// Change the default printer to that chosen by the user
IniFile.WriteString('windows', 'device', TempStr1 + ',' + TempStr2);
// Tell all windows that the default printer changed.
StrCopy(S, 'windows');
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@S));
finally
IniFile.Free;
end;
end;
// Update the label to reflect the new printer selection
lblPrinter.Caption := Printer.Printers[Printer.PrinterIndex];
end;end.
窗体名为Form1procedure TForm1.FormCreate(Sender: TObject);
begin
cb1.items.assign(printer.printers);
end;procedure TForm1.Button1Click(Sender: TObject);
var LPrinter:string;
PrinIniFile:Tinifile;
LStr:string;
begin
LStr:=printer.Printers[cb1.itemindex];
delete(Lstr,pos(' on ',Lstr),Length(LStr));
PrinIniFile:=TIniFile.Create('WIN.ini');
try
LPrinter:=PrinIniFile.ReadString('Devices',LStr,'');
PrinIniFile.writestring('windows','device',LStr+','+LPrinter);
finally
PrinIniFile.free;
end;
end;
uses printers;
procedure SetDefaultPrinter(const printerindex:integer);
Var
FHandle : THandle;
HPrt : THandle;
PrtInfo5: PPrinterInfo5;
FDevice: array[0..79] of char;
FDriver: array[0..79] of char;
FPort: array[0..79] of char;
begin
{printerindex为选中打印机的索引,如果使用打印机名称,则此句可忽略}
Printer.PrinterIndex := printerindex;
Printer.GetPrinter (FDevice, FDriver, FPort, FHandle);
OpenPrinter(FDevice, HPrt, nil);
if HPrt = 0 then
raise(Exception.Create('不能打开打印机'));
try
PrtInfo5 := GetPrinterInfo5(HPrt);
PrtInfo5.Attributes := PrtInfo5.Attributes +
PRINTER_ATTRIBUTE_DEFAULT;
SetPrinter(HPrt,5,PrtInfo5,PRINTER_CONTROL_SET_STATUS);
FreeMem(PrtInfo5);
finally
ClosePrinter(HPrt);
end;
end;
设置打印参数是要修改TDeviceMode结构同yjq说的一样
var
ADevice, ADriver, APort:array [0..255] of Char;
DeviceHandle:THandle;
DevMode:PDeviceMode;//TDeviceMode指针
begin
{首先获取TPrinter的DeviceMode结构的句柄}
PrinterGetPrinter(ADevice, ADriver, APort, DeviceHandle);
{如果句柄是0, 表示打印机没有装载}
if DeviceHandle=0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPritner(ADevice, ADriver, APort, DeviceHandle);
end;
{如果DeviceHandle还是0, 表示有错误发生。否则,就调用}
{GlobalLock来获取TDeviceMode结构的指针}
if DeviceHandle=0 then
Raise Exception.Create('Could Not Initialize TDeviceMode structure')
else
DevMode:=GlobalLock(DeviceHandle);
{下面是设置纸张大小}
with DevMode^ do
begin
dmFields:=dmFields or DM_PAPERSIZE;
dmPaperSize:=DMPADER_LETTER;//LETTER,8-1/2
{如果纸张大小由dmPaperWidth和dmPaperLength设置,则dmPaperSize的值可以设为0}
//dmFields:=dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH;
//dmPaperLength:=somelength;
//dmPaperWidth:=somewidth;
end;
if not DeviceHandle=0 then
GlobalUnlock(DeviceHandle);
[9:06:43] 61.136.132.166 (61.136.132.182)等试图连接本机的 Http[80] 端口,
TCP标志: S
该操作被拒绝。
什么意思
[9:06:43] 61.136.132.166 (61.136.132.182)等试图连接本机的 Http[80] 端口,
TCP标志: S
该操作被拒绝。
什么意思
有可能是病毒在攻击,就象泥姆达,自己打包发送,攻击的就是80端口