Delphi 设置系统默认打印机
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,获取默认打印机名:function TForm1.GetDefaultPrinterName: string;var iSize: Integer; sIniFile, sSection, sKe
千家信息网最后更新 2025年12月03日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;//这个函数也可以更改打印机,效果没有上面的好
打印机
函数
效果
版本
面的
系统
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
繁荣富强服务器合并
试图在数据库安全性方面
服务器网络故障维修
浙江北斗网络时钟服务器云主机
上海企业软件开发价格表
遂宁网络技术发展趋势
灌篮高手没有服务器
网络安全应急处置领导小组
石家庄互联网科技公司
excel服务器如何卸载
广西数据软件开发设施标准
近五年来软件开发的失败案例
数据分析服务器如何使用
冷链节点服务器 usdt
cifi年度网络安全峰会
宝山区智能化软件开发协议
智能技术综合数据库
软件开发的大概步骤
数据库系统的关键技术
湖南gps卫星授时服务器
关于网络安全书签制作教程
京山银行金融网络安全
pyqt 软件开发
方舟怎么叫人去自己的服务器玩
惠普家用服务器
数据库自动备份是自动覆盖吗
英国大学邮箱的收发件服务器
绝地求生今天服务器
数据库连接池怎么压测
介绍几种无线网络技术