PDA

View Full Version : کنترل پرینتر



مجتبی جوادی
دوشنبه 05 مرداد 1388, 18:39 عصر
دوستان سلام
چگونه می توان وضعیت پرینتر را (در حال چاپ است یا نه ) کنترل نمود ؟
با تشکر

p_ooya
دوشنبه 05 مرداد 1388, 23:18 عصر
چند تا API داره ویندوز که برای کار با پرینتره. شاید بدردتون بخوره :

BOOL GetPrinter(

HANDLE hPrinter, // handle to printer of interest
DWORD Level, // version of printer info data structure
LPBYTE pPrinter, // pointer to array of bytes that receives printer info. structure
DWORD cbBuf, // size, in bytes, of array of bytes
LPDWORD pcbNeeded // pointer to variable with count of bytes retrieved (or required)
);


BOOL GetJob(

HANDLE hPrinter, // handle of printer
DWORD JobId, // job identifier value
DWORD Level, // data-structure level
LPBYTE pJob, // address of data-structure array
DWORD cbBuf, // count of bytes in array
LPDWORD pcbNeeded // address of value that contains count of bytes retrieved (or required)
);


BOOL ReadPrinter(

HANDLE hPrinter, // handle of printer object
LPVOID pBuf, // address of array of bytes that receives data
DWORD cbBuf, // size, in bytes, of array
LPDWORD pNoBytesRead // address of variable with number of bytes retrieved
);


DWORD GetPrinterData(

HANDLE hPrinter, // handle of printer object
LPTSTR pValueName, // address of data type
LPDWORD pType, // reserved
LPBYTE pData, // address of array of bytes that receives data
DWORD nSize, // size, in bytes, of array
LPDWORD pcbNeeded // address of variable with number of bytes retrieved (or required)
);

Saeed_m_Farid
سه شنبه 06 مرداد 1388, 09:23 صبح
دوستان سلام
چگونه می توان وضعیت پرینتر را (در حال چاپ است یا نه ) کنترل نمود ؟
با تشکر
سلام
میتونید از تابع زیر هم استفاده کنید، با فرض اینکه LPTPort شماره پورت پرینتری هست که می خواهید چک کنید و نتیجه هم یکی از حالتهای زیر هست :

1. 01h - Timeout
2. 08h - I/O Error
3. 10h - Printer selected
4. 20h - Out of paper
5. 40h - Printer acknowledgement
6. 80h - Printer not busy (0 if busy)

تابع آزمایش وضعیت پرینتر :

function TestPrinterStatus(LPTPort: Word): Byte;
var
Status: byte;
CheckLPT: word;
begin
Status := 0;
if (LPTPort >= 1) and (LPTPort <= 3) then
begin
CheckLPT := LPTPort - 1;
asm
mov dx, CheckLPT;
mov al, 0;
mov ah, 2;
int 17h;
mov &Status, ah;
end;
end;
Result := Status;
end;
البته با ویندوز NT جواب نمیده و access violation می گیرید :چشمک: ...

مجتبی جوادی
سه شنبه 06 مرداد 1388, 13:14 عصر
آقا سعید ممنون
پورت من usb است میشه یک مثال از نحوه استفاده از این کد بزنید . مثلا با فشرن یک کلید در یک تکس باکس جمله (پرینتر فعال و یا غیر فعال است ) را بنویسد.
با تشکر