新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Delphi設(shè)置系統(tǒng)默認(rèn)打印機(jī)
獲取默認(rèn)打印機(jī)名:
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到南部網(wǎng)站設(shè)計(jì)與南部網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類(lèi)型包括:做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請(qǐng)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋南部地區(qū)。
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;
更改默認(rèn)打印機(jī):需要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函數(shù) 在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;//這個(gè)函數(shù)也可以更改打印機(jī),效果沒(méi)有上面的好
當(dāng)前文章:Delphi設(shè)置系統(tǒng)默認(rèn)打印機(jī)
文章分享:http://www.ef60e0e.cn/article/pijsjj.html