• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 38 رای - 2.71 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: تعداد صفحات پرینت شده از طرف هر کلاینت
حالت خطی
#7
(06-22-2012، 04:44 PM)Amin_Mansouri نوشته: درود
با سورس زیر میتونی تعداد صفحات پرنت شده رو بدست بیاری
چو شبکه داخل هستد یه برنامه تحت سرور بنویس با یه کلاینت کلی سورس مثل چت هست که میتوند ازشون کمک بگیرید نوشتنش ک اری نداره
واسه تعداد صفحات پرینت شده و وضعیت پرینت من 2 تا سورس بهت میدم.
سورس 1:
کد:
Get the number of print jobs in a print queue

The following routine can be used to return the number of print jobs waiting in a queue (for both local and network printers).

Option Explicit

'Constants Definition
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8

'Types Definition
Private Type DEVMODE
    dmDeviceName As String * CCHDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCHFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Long
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
End Type

Private Type PRINTER_DEFAULTS
    pDatatype As String
    pDevMode As DEVMODE
    DesiredAccess As Long
End Type

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Type JOB_INFO_1_API
    JobId As Long
    pPrinterName As Long
    pMachineName As Long
    pUserName As Long
    pDocument As Long
    pDatatype As Long
    pStatus As Long
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type

Private Type JOB_INFO_1
    JobId As Long
    pPrinterName As String
    pMachineName As String
    pUserName As String
    pDocument As String
    pDatatype As String
    pStatus As String
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type

'API Declarations
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal HPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, ByVal pJob As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long

Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long

Private Declare Function HeapAlloc Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GetProcessHeap Lib "kernel32.dll" () As Long
Private Declare Function HeapFree Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long


'Private structure filled by PrinterQueueItems with all the documents data in the selected printer queue
Private JobsDesc(0 To 127) As JOB_INFO_1


'Purpose     :  Returns the number of atJobs in the specified Printer Queue
'Inputs      :  sPrinterName            The name of the printer,
'                                       can be a network path eg. "\\MYSERVER\MYPRINTER"
'Outputs     :  Returns the number of printer atJobs in queue


Function PrinterQueueItems(sPrinterName As String) As Long
    Dim tPrinterStruct As PRINTER_DEFAULTS
    Dim lhwndPrinter As Long
    Dim bRet As Boolean
    Dim atJobs(0 To 127) As JOB_INFO_1_API
    Dim lpcbNeeded As Long
    Dim lpcReturned As Long
    Dim lThisJob As Integer
    Dim lTempBuff As Long

    'Initialize the Printer structure
    tPrinterStruct.pDatatype = vbNullString
    tPrinterStruct.pDevMode.dmSize = Len(tPrinterStruct.pDevMode)
    tPrinterStruct.DesiredAccess = PRINTER_ACCESS_USE
    'Get the printer Handle
    bRet = OpenPrinter(sPrinterName, lhwndPrinter, tPrinterStruct)
    'Get the Printer active atJobs
    bRet = EnumJobs(lhwndPrinter, 0, 127, 1, lTempBuff, 0, lpcbNeeded, lpcReturned)
    If lpcbNeeded = 0 Then
        PrinterQueueItems = 0
    Else
        'Allocate the Buffer
        lTempBuff = HeapAlloc(GetProcessHeap(), 0, lpcbNeeded)
        bRet = EnumJobs(lhwndPrinter, 0, 127, 1, lTempBuff, lpcbNeeded, lpcbNeeded, lpcReturned)
        CopyMem atJobs(0), ByVal lTempBuff, lpcbNeeded
        For lThisJob = 0 To lpcReturned - 1
            JobsDesc(lThisJob).pPrinterName = LPSTRtoSTRING(atJobs(lThisJob).pPrinterName)
            JobsDesc(lThisJob).pMachineName = LPSTRtoSTRING(atJobs(lThisJob).pMachineName)
            JobsDesc(lThisJob).pUserName = LPSTRtoSTRING(atJobs(lThisJob).pUserName)
            JobsDesc(lThisJob).pDocument = LPSTRtoSTRING(atJobs(lThisJob).pDocument)
            JobsDesc(lThisJob).pDatatype = LPSTRtoSTRING(atJobs(lThisJob).pDatatype)
            JobsDesc(lThisJob).pStatus = LPSTRtoSTRING(atJobs(lThisJob).pStatus)
            JobsDesc(lThisJob).JobId = atJobs(lThisJob).JobId
            JobsDesc(lThisJob).Status = atJobs(lThisJob).Status
            JobsDesc(lThisJob).Priority = atJobs(lThisJob).Priority
            JobsDesc(lThisJob).Position = atJobs(lThisJob).Position
            JobsDesc(lThisJob).TotalPages = atJobs(lThisJob).TotalPages
            JobsDesc(lThisJob).PagesPrinted = atJobs(lThisJob).PagesPrinted
            JobsDesc(lThisJob).Submitted = atJobs(lThisJob).Submitted
        Next
        If lTempBuff Then HeapFree GetProcessHeap(), 0, lTempBuff
        PrinterQueueItems = lpcReturned
    End If
    'Close printer
    bRet = ClosePrinter(lhwndPrinter)
End Function

'Removes Null Characters
Private Function TrimStr(strName As String) As String
    'Finds a null then trims the string
    Dim x As Integer

    x = InStr(strName, vbNullChar)
    If x > 0 Then
        TrimStr = Left(strName, x - 1)
    Else
        TrimStr = strName
    End If
End Function


'Returns a string from a pointer
Private Function LPSTRtoSTRING(ByVal lngPointer As Long) As String
    Dim lngLength As Long

    'Get number of characters in string
    lngLength = lstrlenW(lngPointer) * 2
    'Initialize string so we have something to copy the string into
    LPSTRtoSTRING = String(lngLength, 0)
    'Copy the string
    CopyMem ByVal StrPtr(LPSTRtoSTRING), ByVal lngPointer, lngLength
    'Convert to Unicode
    LPSTRtoSTRING = TrimStr(StrConv(LPSTRtoSTRING, vbUnicode))
End Function


'Demonstration routine
Sub Test()
    'Get the Default Printer's Queue
    Debug.Print "Number of Documents in Queue: " & PrinterQueueItems(Printer.DeviceName)
End Sub

سورس 2 که بصورت اموزشی هم هست خیلی کمکت میکنه دوست عزیز
http://support.microsoft.com/kb/202480
بدرود
درودی دیگر دوست من
غرض از مزاحمت اینکه کدی که شما دادید برا VB هستش اگه لطف کنید برا C# هم بذارید ممنون میشم.
ضمن اینکه اگه درد سر نیست براتون در مورد قسمت های مختلف سورسی که میذارید توضیحاتی بدید تا روشن بشم. آخه تازه کارم من استاد.
باسپاس rose
 
پاسخ
  


پیام‌های این موضوع
RE: تعداد صفحات پرینت شده از طرف هر کلاینت - توسط atpf - 06-22-2012، 07:58 PM

موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  سورس کد بدست اوردن تعداد کلمات یک رشته ( سی شارپ) Amin_Mansouri 4 13,346 12-17-2013، 11:46 AM
آخرین ارسال: sal
Question پرینت سریع analyze 1 3,861 02-26-2013، 10:49 AM
آخرین ارسال: Amin_Mansouri
Photo دیدن صفحه نمایش طرف کلاینت از طرف سرور atpf 4 8,896 06-24-2012، 07:04 AM
آخرین ارسال: Amin_Mansouri
  بدست اوردن حجم فایل و تعداد فایل های پاک شده سطل زباله سیستم عامل (سی شارپ) Amin_Mansouri 0 5,451 12-30-2011، 03:59 PM
آخرین ارسال: Amin_Mansouri
  پرینت فایل های متنی Ghoghnus 0 3,311 10-31-2011، 02:57 PM
آخرین ارسال: Ghoghnus
  شمارش تعداد تکرار یک کلمه در رشته Ghoghnus 0 5,852 10-31-2011، 02:32 PM
آخرین ارسال: Ghoghnus

پرش به انجمن:


Browsing: 1 مهمان