http://img.blog.csdn.net/20140401094849531?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbmJ4a2VsZQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
1:想用PB程式讀取檔案名,頁數,時間,請問有什么好的方法。
2:最好是能實作有任務的時候 就能觸發讀取。
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
試試用這個$PBExportHeader$uo_class_printer.sru
$PBExportComments$有關列印機的函式
forward
global type uo_class_printer from nonvisualobject
end type
end forward
type systemtime from structure
uint wyear
uint wmonth
uint wdayofweek
uint wday
uint whour
uint wminute
uint wsecond
uint wmillisecond
end type
type job_info_1 from structure
unsignedlong jobid
unsignedlong pprintername
unsignedlong pmachinename
unsignedlong pusername
unsignedlong pdocument
unsignedlong pdatatype
unsignedlong pstatus
unsignedlong status
unsignedlong priority
unsignedlong position
unsignedlong totalpages
unsignedlong pagesprinted
unsignedlong submitted
end type
type printer_defaults from structure
string pdatatype
unsignedlong pdevmode
unsignedlong desiredaccess
end type
global type uo_class_printer from nonvisualobject
end type
global uo_class_printer uo_class_printer
type prototypes
FUNCTION ulong OpenPrinter(ref string pPrinterName,ref ulong phPrinter,ref PRINTER_DEFAULTS pDefault) LIBRARY "winspool.drv" ALIAS FOR "OpenPrinterA"
Function ulong CopyMemory(ref JOB_INFO_1 destination, REF blob source, ulong length) library "kernel32.dll" Alias for "RtlMoveMemory"
Function ulong CopyMemory(ref SYSTEMTIME destination, REF blob source, ulong length) library "kernel32.dll" Alias for "RtlMoveMemory"
FUNCTION ulong EnumJobs(ulong hPrinter,ulong FirstJob,ulong NoJobs,ulong Level,ref blob Job,ulong cdBuf,ref ulong pcbNeeded,ref ulong pcReturned) LIBRARY "winspool.drv" ALIAS FOR "EnumJobsA"
end prototypes
forward prototypes
public function integer of_get_jobinf (long al_hprinter, ref long asa_jobid[], ref string asa_pprintername[], ref string asa_pmachinename[], ref string asa_pusername[], ref string asa_pdocument[], ref string asa_pdatatype[], ref string asa_pstatus[], ref long ala_status[], ref long ala_priority[], ref long ala_position[], ref long ala_totalpages[], ref long ala_pagesprinted[], ref datetime adta_submitted[])
public function long of_openprinter (ref string as_printername)
end prototypes
public function integer of_get_jobinf (long al_hprinter, ref long asa_jobid[], ref string asa_pprintername[], ref string asa_pmachinename[], ref string asa_pusername[], ref string asa_pdocument[], ref string asa_pdatatype[], ref string asa_pstatus[], ref long ala_status[], ref long ala_priority[], ref long ala_position[], ref long ala_totalpages[], ref long ala_pagesprinted[], ref datetime adta_submitted[]);/*
功能:
取列印任務的狀態值
引數:
al_hprinter: 列印機句柄
job_info_1 的專案: 存盤列印機資訊的結構(輸出)
回傳值:
成功回傳列印任務的數量;錯誤回傳 -1
*/
constant int JOB_STATUS_PAUSED = 1
constant int JOB_STATUS_ERROR = 2
constant int JOB_STATUS_DELETING = 4
constant int JOB_STATUS_SPOOLING = 8
constant int JOB_STATUS_PRINTING = 16
constant int JOB_STATUS_OFFLINE = 32
constant int JOB_STATUS_PAPEROUT = 64
constant int JOB_STATUS_PRINTED = 128
constant ulong SYSTEMTIME_LEN=8*2
// 因為 submitted 也是一個結構,所以是 13-1=12 項
constant ulong JOB_INFO_1_LEN=12*4 + SYSTEMTIME_LEN
ulong ll_Needed,ll_Returned
job_info_1 lstr_inf // 裝載列印任務資訊
systemtime lstr_systime // 裝載系統時間(UTC 格式)
blob lbl_buf,lbl_temp
string ls_docname
long nloop,rtn,ll_size,ll_status,ll_buf
date ld_buf
time lt_buf
string ls_buf
ll_Size = 1
SEG_GETJOB:
lbl_buf = blob(Space(ll_size))
if EnumJobs(al_hprinter, 0, 65535, 1, lbl_buf, ll_size, ll_Needed, ll_Returned) = 0 then
if ll_size < ll_Needed then
ll_size = ll_Needed
goto SEG_GETJOB
else
return -1
end if
end if
for nloop = 1 to long(ll_Returned)
// 取一個任務的狀態
lbl_temp = BlobMid(lbl_buf, (nloop - 1) * JOB_INFO_1_LEN + 1)
if CopyMemory(lstr_inf, lbl_temp, JOB_INFO_1_LEN) = 0 then return -1
// 取這個任務中的時間狀態
lbl_temp = BlobMid(lbl_temp, JOB_INFO_1_LEN - SYSTEMTIME_LEN + 1)
if CopyMemory(lstr_systime, lbl_temp, SYSTEMTIME_LEN) = 0 then return -1
asa_jobid[nloop] = lstr_inf.jobid
asa_pprintername[nloop] = string(lstr_inf.pprintername, "address")
asa_pmachinename[nloop] = string(lstr_inf.pmachinename, "address")
asa_pusername[nloop] = string(lstr_inf.pusername, "address")
asa_pdocument[nloop] = string(lstr_inf.pdocument, "address")
asa_pdatatype[nloop] = string(lstr_inf.pdatatype, "address")
asa_pstatus[nloop] = string(lstr_inf.pstatus, "address")
ala_status[nloop] = lstr_inf.status
if asa_pstatus[nloop] = "" then
// 決議狀態碼的含義
ll_status = lstr_inf.status
do
if ll_status >= JOB_STATUS_PRINTED then
ll_buf = JOB_STATUS_PRINTED
ll_status = ll_status - JOB_STATUS_PRINTED
elseif ll_status >= JOB_STATUS_PAPEROUT then
ll_buf = JOB_STATUS_PAPEROUT
ll_status = ll_status - JOB_STATUS_PAPEROUT
elseif ll_status >= JOB_STATUS_OFFLINE then
ll_buf = JOB_STATUS_OFFLINE
ll_status = ll_status - JOB_STATUS_OFFLINE
elseif ll_status >= JOB_STATUS_PRINTING then
ll_buf = JOB_STATUS_PRINTING
ll_status = ll_status - JOB_STATUS_PRINTING
elseif ll_status >= JOB_STATUS_SPOOLING then
ll_buf = JOB_STATUS_SPOOLING
ll_status = ll_status - JOB_STATUS_SPOOLING
elseif ll_status >= JOB_STATUS_DELETING then
ll_buf = JOB_STATUS_DELETING
ll_status = ll_status - JOB_STATUS_DELETING
elseif ll_status >= JOB_STATUS_ERROR then
ll_buf = JOB_STATUS_ERROR
ll_status = ll_status - JOB_STATUS_ERROR
elseif ll_status >= JOB_STATUS_PAUSED then
ll_buf = JOB_STATUS_PAUSED
ll_status = JOB_STATUS_PAUSED
elseif ll_status = 0 then
ll_buf = 0
else
asa_pstatus[nloop] = "" // 未知的狀態碼,置空
exit
end if
choose case ll_buf
case 0
ls_buf = " "
case JOB_STATUS_PAUSED
ls_buf = "暫停"
case JOB_STATUS_ERROR
ls_buf = "錯誤"
case JOB_STATUS_DELETING
ls_buf = "正在洗掉"
case JOB_STATUS_SPOOLING
ls_buf = "正在脫機列印"
case JOB_STATUS_PRINTING
ls_buf = "正在列印"
case JOB_STATUS_OFFLINE
ls_buf = "掉線"
case JOB_STATUS_PAPEROUT
ls_buf = "缺紙"
case JOB_STATUS_PRINTED
ls_buf = "列印完成"
case else
ls_buf = ""
end choose
if ls_buf <> "" then
if asa_pstatus[nloop] = "" then
asa_pstatus[nloop] = ls_buf
else
asa_pstatus[nloop] = ls_buf + " - " + asa_pstatus[nloop]
end if
end if
loop while ll_status > 0
end if
ala_priority[nloop] = lstr_inf.priority
ala_position[nloop] = lstr_inf.position
ala_totalpages[nloop] = lstr_inf.totalpages
ala_pagesprinted[nloop] = lstr_inf.pagesprinted
// 轉換協同世界時間(UTC);但不知為什么小時數不對,用 API GetTimeFormat() 也不行
ld_buf = date(string(lstr_systime.wyear) + "-" + string(lstr_systime.wmonth) + &
"-" + string(lstr_systime.wday))
lt_buf = time(string(lstr_systime.whour) + ":" + string(lstr_systime.wminute) + &
":" + string(lstr_systime.wsecond) + "." + string(lstr_systime.wmillisecond))
adta_submitted[nloop] = datetime(ld_buf, lt_buf)
//asa_submitted.wdayofweek = lstr_systime.wdayofweek
next
return ll_Returned
end function
public function long of_openprinter (ref string as_printername);/*
功能:
打開指定的列印機
引數:
as_printerName: 列印機名;為空串時獲取當前列印機
回傳值:
成功回傳獲得的列印機句柄;錯誤回傳 -1
*/
string ls_null
printer_defaults pDefault // 載入的列印機資訊
ulong ll_hPrinter
int li_pos,rtn
// 取當前列印機
if as_printerName = "" then
as_printerName = ProfileString("win.ini", "windows", "device", "")
li_Pos = Pos(as_printerName, ",")
if li_Pos <> 0 then
as_printerName = Left(as_printerName, li_Pos - 1)
else
MessageBox(this.ClassName() + " : of_openprinter()", &
"Win.ini 檔案中未指定默認列印機!", StopSign!)
return -1
end if
end if
SetNUll(ls_null)
pDefault.pDatatype = ls_null
pDefault.pDevMode = 0
pDefault.DesiredAccess = 8
rtn = OpenPrinter(as_printerName, ll_hPrinter, pDefault)
if rtn = 0 then
MessageBox(this.ClassName() + " : of_openprinter()", &
"列印機 “" + as_printerName + "” 無法打開!", StopSign!)
return -1
end if
return ll_hPrinter
end function
on uo_class_printer.create
TriggerEvent( this, "constructor" )
end on
on uo_class_printer.destroy
TriggerEvent( this, "destructor" )
end on
uj5u.com熱心網友回復:
主要用到了以下這個API函式EnumJobs
編輯
EnumJobs
VB宣告
Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, pJob As Byte, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
說明
列舉列印佇列中的作業
回傳值
Long,非零表示成功,零表示失敗。會設定GetLastError
引數表
引數 型別及說明
hPrinter Long,一個已打開的列印機物件的句柄(用OpenPrinter獲得)
FirstJob Long,作業串列中要列舉的第一個作業的索引(注意編號從0開始)
NoJobs Long,要列舉的作業數量
Level Long,1或2
pJob Byte,包含 JOB_INFO_1 或 JOB_INFO_2 結構的緩沖區
cbBuf Long,pJob緩沖區中的字符數量
pcbNeeded Long,指向一個Long型變數的指標,該變數用于保存請求的緩沖區長度,或者實際讀入的位元組數量
pcReturned Long,載入緩沖區的結構數量(用于那些能回傳多個結構的函式)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/46542.html
標籤:API 調用
上一篇:pb不能創建ASA資料庫
