Title: Simple and direct way without TPrinter class: How to get the default printer name?
Question: Some times and for some reasons, you want to get the default printer name (local or network printers). How to do that?
Answer:
In reference to my previous article "Jobs information (an easy way)?".
http://www.delphi3000.com/articles/article_1699.asp
I decided to add another function, which can be used separately or with GetSpoolerJobs in my pervious article. The new function is GetDefaultPrinterName.
Function 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;
Example of use:
............................
var
sPrinterName : String;
//JOB_INFO_1_ARRAY is declared in my previous article.
aJobs : JOB_INFO_1_ARRAY;
begin
//Get the default printer name.
sPrinterName := GetDefaultPrinterName;
//Now get all jobs from the spooler using my previous article.
aJobs := GetSpoolerJobs(sPrinterName);
............................
As usual, any comments are welcome.
Abdulaziz Jasser