1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| function SetDefaultPrinter(const PrinterName: String; SendInfoMsg: boolean): boolean; const MaxBuf=256; cs1='Windows'; cs2='Device'; cs3='Devices'; cs4=#0; var Buf: array [0..MaxBuf] of char; PrinterInfo: string; Res: integer; begin Result:=false; Res:=GetProfileString(cs3,PChar(PrinterName),#0,Buf,MaxBuf); if (Res>0) and (Trim(Buf)<>'') then begin PrinterInfo:=PrinterName+','+Buf; while GetProfileString(cs1,cs2,cs4,Buf,MaxBuf)>0 do WriteProfileString(cs1,cs2,#0); WriteProfileString(cs1,cs2,PChar(PrinterInfo)); if SendInfoMsg then case Win32Platform of VER_PLATFORM_WIN32_NT: SendMessage(HWND_BROADCAST,WM_WININICHANGE,0,LongInt(PChar(cs1))); VER_PLATFORM_WIN32_WINDOWS: SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,LongInt(PChar(cs1))); end; Result:=true; end; end; |