function IsDefaultPrinterSetup: boolean;
var
FDevice: PChar;
FDriver: PChar;
FPort: PChar;
FHandle: THandle;
CurrentPrinterName: string;
begin
GetMem(FDevice,255);
GetMem(FDriver,255);
GetMem(FPort,255);
try
try
Printer.GetPrinter(FDevice, FDriver, FPort, FHandle);
CurrentPrinterName := FDevice;
if CurrentPrinterName <> '' then
begin
result := True;
end
else
begin
result := False; // 기본프린터 없음
end;
except
on Exception do
begin
result := False;
end;
end;
finally
if FDevice <> nil then
FreeMem(FDevice, 255);
if FDriver <> nil then
FreeMem(FDriver, 255);
if FPort <> nil then
FreeMem(FPort, 255);
end;
end;
// .dpr 소스 예시
begin
Application.Initialize;
if IsDefaultPrinterSetup then
begin
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run;
end
else
begin
ShowMessage('기본 프린터가 설정되어있지 않습니다. 프로그램을 종료합니다.');
end;
end.
//참고로 프린터의 상태를 알아보시려면 GetPrinter라는 API를 사용하시면 됩니다..
PRINTER_INFO_2 구조체로 Status 멤버가 반환되는데 다음과 같은 정보를 얻을 수
있습니다.
기본프린터가 설정되어 있지 않은 경우 메시지를 출력하고 종료하는 루틴입니다..
function IsDefaultPrinterSetup: boolean;
var
FDevice: PChar;
FDriver: PChar;
FPort: PChar;
FHandle: THandle;
CurrentPrinterName: string;
begin
GetMem(FDevice,255);
GetMem(FDriver,255);
GetMem(FPort,255);
try
try
Printer.GetPrinter(FDevice, FDriver, FPort, FHandle);
CurrentPrinterName := FDevice;
if CurrentPrinterName <> '' then
begin
result := True;
end
else
begin
result := False; // 기본프린터 없음
end;
except
on Exception do
begin
result := False;
end;
end;
finally
if FDevice <> nil then
FreeMem(FDevice, 255);
if FDriver <> nil then
FreeMem(FDriver, 255);
if FPort <> nil then
FreeMem(FPort, 255);
end;
end;
// .dpr 소스 예시
begin
Application.Initialize;
if IsDefaultPrinterSetup then
begin
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run;
end
else
begin
ShowMessage('기본 프린터가 설정되어있지 않습니다. 프로그램을 종료합니다.');
end;
end.
//참고로 프린터의 상태를 알아보시려면 GetPrinter라는 API를 사용하시면 됩니다..
PRINTER_INFO_2 구조체로 Status 멤버가 반환되는데 다음과 같은 정보를 얻을 수
있습니다.
PRINTER_STATUS_BUSY
PRINTER_STATUS_DOOR_OPEN
PRINTER_STATUS_ERROR
PRINTER_STATUS_INITIALIZING
PRINTER_STATUS_IO_ACTIVE
PRINTER_STATUS_MANUAL_FEED
PRINTER_STATUS_NO_TONER
PRINTER_STATUS_NOT_AVAILABLE
PRINTER_STATUS_OFFLINE
PRINTER_STATUS_OUT_OF_MEMORY
PRINTER_STATUS_OUTPUT_BIN_FULL
PRINTER_STATUS_PAGE_PUNT
PRINTER_STATUS_PAPER_JAM
PRINTER_STATUS_PAPER_OUT
PRINTER_STATUS_PAPER_PROBLEM
PRINTER_STATUS_PAUSED
PRINTER_STATUS_PENDING_DELETION
PRINTER_STATUS_PRINTING
PRINTER_STATUS_PROCESSING
PRINTER_STATUS_TONER_LOW
PRINTER_STATUS_UNAVAILABLE
PRINTER_STATUS_USER_INTERVENTION
PRINTER_STATUS_WAITING
PRINTER_STATUS_WARMING_UP
그럼~ 즐거운 프로그래밍 하세요~