This grabs the selected printer in a ComboBox and makes it the default printer.Use this on form create (or whatever)... ComboBox1.Items := Printer.Printers; {populates ComboBox} ComboBox1.ItemIndex := Printer.PrinterIndex; {sets display to current printer}then, assuming you have a Button5...procedure TForm1.Button5Click(Sender: TObject); var Device: array[0..255] of Char; Driver: array[0..255] of char; Port: array[0..255] of char; s : array[0..255] of Char; hDeviceMode: THandle; begin Printer.PrinterIndex := ComboBox1.ItemIndex; Printer.GetPrinter (Device, Driver, Port, hDeviceMode); StrCopy (s, Device); StrCat (s, ','); StrCat (s, Driver); StrCat (s, ','); StrCat (s, Port); WriteProfileString ('windows', 'device', s); StrCopy (s, 'windows'); SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s)); end;
uses Printers;procedure TForm1.Button1Click(Sender: TObject); begin showmessage(inttostr( GetDeviceCaps(Printer.Handle, LOGPIXELSX) )); end;返回打印机每英寸相素值-------------------------------------------------------------------------------- function GetPageWidth: Integer; begin Result := Screen.PixelsPerInch*GetDeviceCaps(Printer.Handle, PHYSICALWIDTH) div GetPixelsPerInchX end; function GetPageHeight: Integer; begin Result := Screen.PixelsPerInch*GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT) div GetPixelsPerInchY end; function GetPixelsPerInchX: Integer; begin Result := GetDeviceCaps(Printer.Handle, LOGPIXELSX) end; function GetPixelsPerInchY: Integer; begin Result := GetDeviceCaps(Printer.Handle, LOGPIXELSY) end;
printer.Use this on form create (or whatever)... ComboBox1.Items := Printer.Printers; {populates ComboBox}
ComboBox1.ItemIndex := Printer.PrinterIndex; {sets display to current
printer}then, assuming you have a Button5...procedure TForm1.Button5Click(Sender: TObject);
var
Device: array[0..255] of Char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
s : array[0..255] of Char;
hDeviceMode: THandle;
begin
Printer.PrinterIndex := ComboBox1.ItemIndex;
Printer.GetPrinter (Device, Driver, Port, hDeviceMode);
StrCopy (s, Device);
StrCat (s, ',');
StrCat (s, Driver);
StrCat (s, ',');
StrCat (s, Port);
WriteProfileString ('windows', 'device', s);
StrCopy (s, 'windows');
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));
end;
begin
showmessage(inttostr( GetDeviceCaps(Printer.Handle, LOGPIXELSX) ));
end;返回打印机每英寸相素值--------------------------------------------------------------------------------
function GetPageWidth: Integer; begin Result := Screen.PixelsPerInch*GetDeviceCaps(Printer.Handle, PHYSICALWIDTH) div GetPixelsPerInchX end; function GetPageHeight: Integer; begin Result := Screen.PixelsPerInch*GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT) div GetPixelsPerInchY end; function GetPixelsPerInchX: Integer; begin Result := GetDeviceCaps(Printer.Handle, LOGPIXELSX) end; function GetPixelsPerInchY: Integer; begin Result := GetDeviceCaps(Printer.Handle, LOGPIXELSY) end;