网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Delphi设置系统默认打印机

获取默认打印机名:

站在用户的角度思考问题,与客户深入沟通,找到南部网站设计与南部网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:做网站、网站制作、企业官网、英文网站、手机端网站、网站推广、域名申请雅安服务器托管、企业邮箱。业务覆盖南部地区。

function TForm1.GetDefaultPrinterName: string;
var
  iSize: Integer;
  sIniFile, sSection, sKeyName: PChar;
begin
  iSize := 256;
  sIniFile := 'win.ini';
  sSection := 'windows';
  sKeyName := 'device';
  SetLength(Result, iSize);
  GetPrivateProfileString(sSection, sKeyName, nil, PChar(Result), iSize, sIniFile);
  Result := Copy(Result, 0, Pos(',', Result) - 1);
end;

更改默认打印机:需要Uses WinSpool

procedure ChangeDefaultPrinter(const Name: string);
var
  W2KSDP: function(pszPrinter: PChar): Boolean; stdcall;
  H: THandle;
  Size, Dummy: Cardinal;
  PI: PPrinterInfo2;
begin
  if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion >= 5) then
  begin
    @W2KSDP := GetProcAddress(GetModuleHandle(winspl), 'SetDefaultPrinterA');
    if @W2KSDP = nil then RaiseLastOSError;
    if not W2KSDP(PChar(Name)) then RaiseLastOSError;
  end
  else
  begin
    if not OpenPrinter(PChar(Name), H, nil) then RaiseLastOSError;
    try
      GetPrinter(H, 2, nil, 0, @Size);
      if GetLastError <> ERROR_INSUFFICIENT_BUFFER then RaiseLastOSError;
      GetMem(PI, Size);
      try
        if not GetPrinter(H, 2, PI, Size, @Dummy) then RaiseLastOSError;
        PI^.Attributes := PI^.Attributes or PRINTER_ATTRIBUTE_DEFAULT;
        if not SetPrinter(H, 2, PI, PRINTER_CONTROL_SET_STATUS) then RaiseLastOSError;
      finally
        FreeMem(PI);
      end;
    finally
      ClosePrinter(H);
    end;
  end;
end; //ChangeDefaultPrinter
ChangeDefaultPrinter函数 在D7下使用SetDefaultPrinterA,在Delphi2010以上版本使用SetDefaultPrinterW
procedure TDM.ChangeDefaultPrinter(const Name: string);
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;
  I: Integer;
begin
  for I := 0 to Printer.Printers.Count - 1 do
    if Printer.Printers.Strings[I] = name then
    begin
      Printer.PrinterIndex := I;
      Break;
    end;
  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;//这个函数也可以更改打印机,效果没有上面的好

当前名称:Delphi设置系统默认打印机
文章出自:http://bjjierui.cn/article/pijsjj.html

其他资讯