Skip to content

Commit

Permalink
Automatic printer switching when changing the printer list and defaul…
Browse files Browse the repository at this point in the history
…t printer
  • Loading branch information
namiltd committed Nov 16, 2023
1 parent be0bd02 commit a820f24
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
Binary file modified WinPrint.RES
Binary file not shown.
4 changes: 2 additions & 2 deletions WinPrint.bdsproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">5</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">59</VersionInfo>
<VersionInfo Name="Build">60</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">True</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
Expand All @@ -162,7 +162,7 @@
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName">GNU GPL Software</VersionInfoKeys>
<VersionInfoKeys Name="FileDescription">WinPrint</VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.5.0.59</VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.5.0.60</VersionInfoKeys>
<VersionInfoKeys Name="InternalName">WinPrint</VersionInfoKeys>
<VersionInfoKeys Name="LegalCopyright">Przemysław Czerkas &amp; Mieczysław Nalewaj</VersionInfoKeys>
<VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys>
Expand Down
4 changes: 2 additions & 2 deletions WinPrint.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
-K$00400000
-E"executable"
-N0"units"
-LE"C:\Documents and Settings\XPMUser\Moje dokumenty\Borland Studio Projects\Bpl"
-LN"C:\Documents and Settings\XPMUser\Moje dokumenty\Borland Studio Projects\Bpl"
-LE"C:\Documents and Settings\User\Moje dokumenty\Borland Studio Projects\Bpl"
-LN"C:\Documents and Settings\User\Moje dokumenty\Borland Studio Projects\Bpl"
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog of WinPrint
=====================

WinPrint 1.5.0.60
-----------------
- [NEW] Automatic printer switching when changing the printer list and default printer

WinPrint 1.5.0.59
-----------------
- [ADD] Added code pages CP-668, CP-774 and CP-851 to supported ones
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COPYRIGHT
---------

Copyright (C) 2004-2008 Przemyslaw Czerkas <[email protected]>
2008-2022 Mieczyslaw Nalewaj <[email protected]>
2008-2023 Mieczyslaw Nalewaj <[email protected]>

See GPL.TXT for copyright and license details.

Expand Down
12 changes: 6 additions & 6 deletions source/ConfigFormUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TConfigData = record
LogoTop: double;
Logo1PageOnly: boolean;
IgnoreEmptyFiles: boolean;
PrinterId: integer;
PrinterName: string;
PortCapturing: integer;
KeepInputFiles: boolean;
SpecialSettings: integer;
Expand Down Expand Up @@ -627,14 +627,14 @@ procedure TConfigForm.ReadConfig;
KeepInputFiles:=ReadBool(section,'KeepInputFiles',DEFAULT_KEEP_INPUT_FILES);
SpecialSettings:=ReadInteger(section,'SpecialSettings',DEFAULT_SPECIAL_SETTINGS);

i := ComboBox2.Items.IndexOf(ReadString(section,'Printer',DEFAULT_PRINTER));
PrinterName:=ReadString(section,'Printer',DEFAULT_PRINTER);
i := ComboBox2.Items.IndexOf(PrinterName);
if i>=0 then begin
ComboBox2.ItemIndex:= i;
PrinterId:= i-1;
end
else begin
ComboBox2.ItemIndex:= 0;
PrinterId:=-1;
PrinterName:='';
end;

finally
Expand Down Expand Up @@ -837,7 +837,7 @@ procedure TConfigForm.ReadConfig;
except
KeepInputFiles:=DEFAULT_KEEP_INPUT_FILES;
end;
PrinterId:=-1;
PrinterName:='';
end
else
begin
Expand Down Expand Up @@ -873,7 +873,7 @@ procedure TConfigForm.ReadConfig;
IgnoreEmptyFiles:=DEFAULT_IGNORE_EMPTY_FILES;
KeepInputFiles:=DEFAULT_KEEP_INPUT_FILES;
SpecialSettings:=DEFAULT_SPECIAL_SETTINGS;
PrinterId:=-1;
PrinterName:='';
end;
finally
CloseKey;
Expand Down
28 changes: 23 additions & 5 deletions source/MainFormUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ function TMainForm.ProcessFile;
SrcCodePage : TCodePage;
OwnNLSCodePage :TCodePage;
fattr : Integer;
PrinterId : Integer;
Device, Driver, Port: array[0..255] of Char;
DevMode: THandle;
CurrentPrinterName: string;

Header : Record
FileHeader : tBitmapFileHeader;
Expand All @@ -426,13 +430,13 @@ function TMainForm.ProcessFile;
result:=true;
try
InputFileName:=ConfigForm.ConfigData.InputFilesDir+SearchRec.Name;

if ConfigForm.ConfigData.KeepInputFiles then
begin
GetSystemTime(NowSystemTime);
TmpFileName:=ChangeFileExt(InputFileName,'.tmp~'+IntToStr(SystemTimeToInt64(NowSystemTime) div 1000000)); //w setkach milisekund
end
else begin
else begin
TmpFileName:=ChangeFileExt(InputFileName,'.tmp~');
end;
if FileExists(TmpFileName) then DeleteFile(TmpFileName);
Expand All @@ -455,13 +459,13 @@ function TMainForm.ProcessFile;
begin
//krytyczny blad podczas tworzenia pliku spoolera - zakoncz aplikacje
MustExit:=true;
raise EInOutError.Create(RString(506));
raise EInOutError.Create(RString(506));
end
else CloseHandle(HandleToFile);
end;
InputFileName := TmpFileName;
end;

TempConfigData:=ConfigForm.ConfigData;

if TempConfigData.EnableFormatting then
Expand Down Expand Up @@ -573,13 +577,27 @@ function TMainForm.ProcessFile;
kopii := TempConfigData.NumberOfCopies;
if kopii<1 then kopii:=1
else if kopii>99 then kopii:=99;

Printer.Refresh; //odswiez zainstalowane drukarki
if Printer.Printers.Count=0 then kopii:=0 //brak drukarek
else if TempConfigData.PrinterName = '' then begin //domyslna
Printer.PrinterIndex:= -1; //ustaw drukarke domyslna
Printer.GetPrinter(Device, Driver, Port, DevMode); //pobierz ustawienia by sprawdzic czy istnieje domyslna
CurrentPrinterName := Device; //konwersja typow
if CurrentPrinterName='' then kopii:=0; //nie ma ustawionej drukarki domyslnej wiec nic nie drukuj
end else begin //nie domyslna wiec szuka id
for PrinterId:=0 to Printer.Printers.Count - 1 do
if CompareText(printer.Printers.Strings[PrinterId], TempConfigData.PrinterName)=0 then break; //znalazlo drukarke
if PrinterId>=Printer.Printers.Count then kopii:=0 //nie znalazlo wiec nic nie drukuj
else Printer.PrinterIndex:= PrinterId; //ustaw drukarke
end;

while (kopii>0) do begin
try
//procedure drukujaca StringList
PrintStrings('Dokument programu '+PROGRAMNAME+' - '+SearchRec.Name,
StringList,
CodePageInfo[SrcCodePage].CpNr,
TempConfigData.PrinterId,
cMILTOINCH*TempConfigData.MarginLeft,
cMILTOINCH*TempConfigData.MarginRight,
cMILTOINCH*TempConfigData.MarginTop,
Expand Down
5 changes: 0 additions & 5 deletions source/PrintStringsUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ interface
function PrintStrings(Title: string;
srclines: TStrings;
const CpNr: integer;
const PrinterId: integer;
const leftmargin,rightmargin,topmargin,bottommargin: single;
const orientation: TPrinterOrientation;
const linesPerInch: single;
Expand All @@ -138,7 +137,6 @@ implementation
function PrintStrings(Title: string;
srclines: TStrings;
const CpNr: integer;
const PrinterId: integer;
const leftmargin,rightmargin,topmargin,bottommargin: single;
const orientation: TPrinterOrientation;
const linesPerInch: single;
Expand Down Expand Up @@ -761,9 +759,6 @@ function PrintStrings(Title: string;
pagecount := 0;
textstart := 0;

// Printer.Refresh; //odswiez zainstalowane drukarki
// Printer.PrinterIndex:=-1; //wybierz domyslna drukarke
Printer.PrinterIndex:= PrinterId;
Printer.GetPrinter(Device, Driver, Port, DevMode); //przeladuj ustawienia drukarki by poprawnie wczytalo wielkosc strony itp
Printer.SetPrinter(Device, Driver, Port, 0);
Printer.Copies:= 1;
Expand Down

0 comments on commit a820f24

Please sign in to comment.