NSDPrinterWatch メンバ
プリンタを監視します。
※使用環境、プリンタードライバーの設定によっては監視できない場合もあります。
●コンストラクタ
名前 説明 NSDPrinterWatch NSDPrinterWatchを初期化します。
●プロパティの一覧
名前 説明 PrinterName プリンタ名を返します。 Watch 監視状態を返します。 WatchFlag 監視中の条件を返します。 ChangeNotificationInfo 監視中の通知有無情報を返します。 NotificationRetryStyle 変更通知の取得に成功した場合で、通知情報が受け取れない場合の処理設定を設定します。
●メソッドの一覧
名前 引数 戻り値 説明 Dispose なし なし NSDPrinterWatchクラスのオブジェクトで使用されている全てのリソースを解放します。 PrinterWatch ( String , Printer_Change_Notification_General_Flags , NSD_NotificationStyle ) Boolean型 プリンターを監視します。 PrinterWatchEnd なし Boolean型 プリンターの監視を終了します。 GetPrinterList ( String ) Boolean型 インストールされているプリンタのリストを返します。
●イベントの一覧
名前 引数 戻り値 説明 Event_Change_Notification ( NSDPrinterWatch , Printer_Change_Notification_General_Flags , Integer , Date ) なし 通知用イベント。
●データ用クラスの一覧
名前:NSDPrintJob
内容:印刷ジョブの通知情報用のクラス。
名前 型 説明 Id Int32 ジョブのID。 PrinterName String プリンタの名前。 MachineName String マシンの名前。 PortName String ポートの名前。 UserName String ユーザーの名前。 NotifyUserName String 通知する必要があるユーザーの名前。 DataTypeName String データタイプの名前。 PrintProcessorName String プリントプロセッサの名前。 Parameters String パラメータの名前。 DriverName String ドライバーの名前。 DEVMODEInfo NSDDevmodeInfo DEVMODE情報。 Status Job_Status ステータス。 StatusString String ステータス(文字)。 DocumentName String 印刷ジョブの名前。 Priority Int32 ジョブの優先度。 Position Int32 印刷キュー内のジョブの位置。 Submitted NSDSystemtimeInfo ジョブが送信された時刻。 StartTime Int32 印刷可能な最も早い時間。 UntilTime Int32 印刷可能な、もっとも遅い時間。 LapsedTime Int32 ジョブが印刷を開始してから経過した秒単位の合計時間。 TotalPages Int32 ジョブのページ数。 PagesPrinted Int32 印刷したページ数。 TotalBytes Int32 ジョブのサイズ(バイト単位)。 BytesPrinted Int32 印刷したバイト数。
名前:NSDPrintNotification
内容:プリンター通知情報。
名前 型 説明 Id Int32 ID。 ServerName String サーバーの名前。 PrinterName String プリンタの名前。 ShareName String プリンタの共有名。 PortName String 出力ポートの名前。 DriverName String ドライバの名前。 Comment String プリンタの簡単な説明です。 Location String プリンタの物理的な場所。 DEVMODEInfo NSDDevmodeInfo DEVMODE情報。 Sepfile String セパレータページを作成するために使用されるファイルの名前。 PrintProcessor String プリントプロセッサの名前。 Parameters String パラメータ。 Datatype String 印刷ジョブを記録するために使用するデータ型。 SecurityDescriptor IntPtr セキュリティ記述子。 Attributes Printer_Attribute プリンタの属性。 Priority Int32 印刷ジョブに使用する優先順位。 DefaultPriority Int32 各印刷ジョブに割り当てられるデフォルトの優先順位。 StartTime Int32 印刷可能な最も早い時間。 UntilTime Int32 印刷可能な、もっとも遅い時間。 Status Printer_Status ステータス。 StatusString String ステータス(文字)。 CJobs Int32 印刷ジョブの数。 AveragePpm Int32 プリンタで印刷されている分あたりの平均ページ数。 TotalPages Int32 合計ページ数。 PagesPrinted Int32 印刷したページ数。 TotalBytes Int32 ジョブのサイズ(バイト単位)。 BytesPrinted Int32 印刷したバイト数。
名前:NSDSystemtimeInfo
内容:システム時間情報。
名前 型 説明 Value SYSTEMTIME システム時間情報。
名前:NSDDevmodeInfo
内容:DeviceMode情報。
名前 型 説明 Value DEVMODE DeviceMode情報。
名前:SYSTEMTIME
構文:
Public Structure SYSTEMTIME Dim wYear As Int16 Dim wMonth As Int16 Dim wDayOfWeek As Int16 Dim wDay As Int16 Dim wHour As Int16 Dim wMinute As Int16 Dim wSecond As Int16 Dim wMilliseconds As Int16 End Structure
内容:時間情報。
名前 型 説明 wYear Int16 年。 wMonth Int16 月。 wDayOfWeek Int16 曜日。 wDay Int16 日。 wHour Int16 時。 wMinute Int16 分。 wSecond Int16 秒。 wMilliseconds Int16 ミリ秒。
名前:DEVMODE
構文:
Public Structure DEVMODE Public dmDeviceName As String Public dmSpecVersion As Int16 Public dmDriverVersion As Int16 Public dmSize As Int16 Public dmDriverExtra As Int16 Public dmFields As DM Public dmOrientation As Int16 Public dmPaperSize As Int16 Public dmPaperLength As Int16 Public dmPaperWidth As Int16 Public dmScale As Int16 Public dmCopies As Int16 Public dmDefaultSource As Int16 Public dmPrintQuality As Int16 Public dmColor As Int16 Public dmDuplex As Int16 Public dmYResolution As Int16 Public dmTTOption As Int16 Public dmCollate As Int16 Public dmFormName As String Public dmUnusedPadding As Int16 Public dmBitsPerPel As Int32 Public dmPelsWidth As Int32 Public dmPelsHeight As Int32 Public dmDisplayFlags As Int32 Public dmDisplayFrequency As Int32 End Structure
内容:プリンタやディスプレイデバイスの情報。
名前 型 説明 dmDeviceName String デバイス名。 dmSpecVersion Int16 DEVMODEのバージョン。 dmDriverVersion Int16 プリンタードライバのバージョン。 dmSize Int16 DEVMODEのサイズ。 dmDriverExtra Int16 DEVMODEのプライベート領域サイズ。 dmFields DM フラグ定数。 dmOrientation Int16 印刷方向(縦、横)。 dmPaperSize Int16 用紙サイズ。 dmPaperLength Int16 用紙の長さ。 dmPaperWidth Int16 用紙の幅。 dmScale Int16 ページサイズをx/100の割合でスケーリングする。 dmCopies Int16 印刷部数。 dmDefaultSource Int16 予約(0)。 dmPrintQuality Int16 印刷品質。 dmColor Int16 カラープリンタ又はモノクロ。 dmDuplex Int16 両面。 dmYResolution Int16 0以外は垂直方向の解像度。 dmTTOption Int16 TrueTypeフォントの印刷方法を指定。 dmCollate Int16 丁合い機能を持つプリンタに対して複数部数コピーの際のページの丁合いを行うように要求する。 dmFormName Int16 使用する用紙の形状名。 dmUnusedPadding Int16 予約領域。 dmBitsPerPel Int32 プリンタデバイスでは使用されない。 dmPelsWidth Int32 プリンタデバイスでは使用されない。 dmPelsHeight Int32 プリンタデバイスでは使用されない。 dmDisplayFlags Int32 プリンタデバイスでは使用されない。 dmDisplayFrequency Int32 プリンタデバイスでは使用されない。
名前:NSD_CHANGE_NOTIFICATION_INFO
構文:
Public Structure NSD_CHANGE_NOTIFICATION_INFO Dim Form As Boolean Dim Port As Boolean Dim Job As Boolean Dim Printer As Boolean Dim PrintProcessor As Boolean Dim PrinterDriver As Boolean End Structure
内容:通知有無の情報。
名前 型 説明 Form Boolean 用紙の通知有無。 Port Boolean ポートの通知有無。 Job Boolean ジョブの通知有無。 Printer Boolean プリンタの通知有無。 PrintProcessor Boolean プリントプロセッサの通知有無。 PrinterDriver Boolean プリンタドライバーの通知有無。
●定数の一覧
名前:Printer_Change_Notification_General_Flags (変更通知を受け取る条件) 定数 内容 PRINTER_CHANGE_FORM 用紙への変更があると通知します。 PRINTER_CHANGE_PORT ポートへの変更があると通知します。 PRINTER_CHANGE_JOB ジョブへの変更があると通知します。 PRINTER_CHANGE_PRINTER プリンタへの変更があると通知します。 PRINTER_CHANGE_PRINT_PROCESSOR プリントプロセッサへの変更があると通知します。 PRINTER_CHANGE_PRINTER_DRIVER プリンタドライバへの変更があると通知します。 PRINTER_CHANGE_ALL クライアントは、すべての変更通知に関心があることを示すためにこの値を使用することができます。 PRINTER_CHANGE_ALL_2 PRINTER_CHANGE_ALLと同一。
名前:Printer_Change_Notification_Form_Flags (用紙に関する通知内容) 定数 内容 PRINTER_CHANGE_ADD_FORM サーバーに用紙が追加されました。 PRINTER_CHANGE_SET_FORM サーバ上で用紙が設定されました。 PRINTER_CHANGE_DELETE_FORM サーバーから用紙が削除されました。
名前:Printer_Change_Notification_Port_Flags (ポートに関する通知内容) 定数 内容 PRINTER_CHANGE_ADD_PORT サーバーにポートまたはモニタが追加されました。 PRINTER_CHANGE_CONFIGURE_PORT サーバー上でポートが設定されました。 PRINTER_CHANGE_DELETE_PORT サーバーからポートまたはモニタが削除されました。
名前:Printer_Change_Notification_Job_Flags (印刷ジョブに関する通知内容) 定数 内容 PRINTER_CHANGE_ADD_JOB プリンタに印刷ジョブが送信されました。 PRINTER_CHANGE_SET_JOB ジョブが設定されました。 PRINTER_CHANGE_DELETE_JOB ジョブが削除されました。 PRINTER_CHANGE_WRITE_JOB ジョブデータが書き込まれました。
名前:Printer_Change_Notification_Printer_Flags (プリンターに関する通知内容) 定数 内容 PRINTER_CHANGE_ADD_PRINTER サーバーにプリンタが追加されました。 PRINTER_CHANGE_SET_PRINTER プリンタが設定されました。 PRINTER_CHANGE_DELETE_PRINTER プリンタが削除されました。 PRINTER_CHANGE_FAILED_CONNECTION_PRINTER プリンタへの接続に失敗しました。
名前:Printer_Change_Notification_Processor_Flags (プリントプロセッサに関する通知内容) 定数 内容 PRINTER_CHANGE_ADD_PRINT_PROCESSOR サーバーにプリントプロセッサが追加されました。 PRINTER_CHANGE_DELETE_PRINT_PROCESSOR サーバーからプリントプロセッサが削除されました。
名前:Printer_Change_Notification_Driver_Flags (プリンタードライバーに関する通知内容) 定数 内容 PRINTER_CHANGE_ADD_PRINTER_DRIVER サーバーにプリンタドライバが追加されました。 PRINTER_CHANGE_SET_PRINTER_DRIVER プリンタドライバが設定されました。 PRINTER_CHANGE_DELETE_PRINTER_DRIVER サーバーからプリンタドライバが削除されました。
名前:Printer_Status (プリンターステータス) 定数 内容 PRINTER_STATUS_BUSY プリンタがビジー状態です。 PRINTER_STATUS_DOOR_OPEN プリンタのドアが開いています。 PRINTER_STATUS_ERROR プリンタがエラー状態になります。 PRINTER_STATUS_INITIALIZING プリンタが初期化されています。 PRINTER_STATUS_IO_ACTIVE プリンタがアクティブな入力または出力状態になります。 PRINTER_STATUS_MANUAL_FEED プリンタが手差し状態になっています。 PRINTER_STATUS_NOT_AVAILABLE プリンタは、印刷には使用できません。 PRINTER_STATUS_NO_TONER プリンタは、トナーが不足しています。 PRINTER_STATUS_OFFLINE プリンタがオフラインになっています。 PRINTER_STATUS_OUTPUT_BIN_FULL プリンタの出力ビンがいっぱいです。 PRINTER_STATUS_OUT_OF_MEMORY プリンタは、メモリが不足しています。 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_POWER_SAVE プリンタがパワーセーブモードになっています。 PRINTER_STATUS_PRINTING プリンタは印刷されています。 PRINTER_STATUS_PROCESSING 印刷ジョブをプリンタが処理している。 PRINTER_STATUS_SERVER_OFFLINE プリンタがオフラインになっています。 PRINTER_STATUS_SERVER_UNKNOWN プリンタのステータスは不明です。 PRINTER_STATUS_TONER_LOW プリンタは、トナーが少なくなっています。 PRINTER_STATUS_USER_INTERVENTION プリンタは、ユーザーが何かをする必要がありますエラーがあります。 PRINTER_STATUS_WAITING プリンタは待機しています。 PRINTER_STATUS_WARMING_UP プリンタがウォームアップされています。
名前:Job_Status (印刷ジョブステータス) 定数 内容 JOB_STATUS_BLOCKED_DEVQ プリンタドライバはジョブを印刷することはできません。 JOB_STATUS_COMPLETE ジョブがプリンタに配信されています。 JOB_STATUS_DELETED ジョブが削除されました。 JOB_STATUS_DELETING ジョブが削除されています。 JOB_STATUS_ERROR エラーは、ジョブに関連付けられています。 JOB_STATUS_OFFLINE プリンタがオフラインになっています。 JOB_STATUS_PAPEROUT プリンタが用紙切れです。 JOB_STATUS_PAUSED ジョブが一時停止されます。 JOB_STATUS_PRINTED ジョブが印刷された。 JOB_STATUS_PRINTING ジョブが印刷されています。 JOB_STATUS_RESTART ジョブが再起動されました。 JOB_STATUS_SPOOLING ジョブがスプールされています。 JOB_STATUS_USER_INTERVENTION プリンタは、ユーザーが何かをする必要がありますエラーがあります。
名前:Printer_Attribute (プリンターの属性) 定数 内容 PRINTER_ATTRIBUTE_DEFAULT プリンタがシステムのデフォルトプリンタ。 PRINTER_ATTRIBUTE_DIRECT ジョブは、プリンタに直接送信されます。 PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST スプーリングを完了したすべてのジョブは、スプールを完了していないジョブの前に印刷するようにスケジュールされている。 PRINTER_ATTRIBUTE_ENABLE_BIDI 双方向の通信がプリンタで有効になっている。 PRINTER_ATTRIBUTE_ENABLE_DEVQ このフラグを設定すると、一致しない文書がキューに保持されるようになります。 PRINTER_ATTRIBUTE_FAX プリンタがFAXプリンタです。 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS 印刷された後、ジョブは保持されます.クリアするとジョブが削除されます。 PRINTER_ATTRIBUTE_LOCAL プリンタはローカルプリンタです。 PRINTER_ATTRIBUTE_NETWORK プリンタはネットワークプリンタの接続です。 PRINTER_ATTRIBUTE_PUBLISHED プリンタが公開されているかどうかを示します。 PRINTER_ATTRIBUTE_QUEUED 最後のページのスプール後に印刷を開始します。 PRINTER_ATTRIBUTE_RAW_ONLY RAWデータ型の印刷ジョブがスプールされなければならない。 PRINTER_ATTRIBUTE_SHARED プリンタが共有されています。 PRINTER_ATTRIBUTE_TS プリンタがリダイレクトされ、ターミナルサーバーのプリンタです。 PRINTER_ATTRIBUTE_WORK_OFFLINE プリンタが現在接続されているかどうかを示します。プリンタが現在接続されていない場合、印刷ジョブがスプールを続行します。
名前:NSD_NotificationStyle (通知スタイル) 定数 内容 UNKNOWN 不明。 JOB_NOTIFICATION 印刷ジョブの通知。 PRINTER_NOTIFICATION プリンターの通知。 BOTH 印刷ジョブ、プリンターの通知(両方)。
名前:NSD_NotificationRetryStyle (再通知の取得スタイル) 定数 内容 NO_RETRY 変更通知の取得に成功した場合で、通知情報が受け取れない場合はスキップします。 REFRESH_RETRY 変更通知の取得に成功した場合で、通知情報が受け取れない場合はリフレッシュを行います。
名前:DM (フラグ定数) 定数 内容 DM_ORIENTATION 印刷方向(縦、横)。 DM_PAPERSIZE 用紙サイズ。 DM_PAPERLENGTH 用紙の長さ。 DM_PAPERWIDTH 用紙の幅。 DM_SCALE ページサイズをx/100の割合でスケーリングする。 DM_COPIES 印刷部数。 DM_DEFAULTSOURCE 給紙トレイを示す番号。 DM_PRINTQUALITY 印刷品質。 DM_COLOR カラープリンタ又はモノクロ。 DM_DUPLEX 両面。 DM_YRESOLUTION 0以外は垂直方向の解像度。 DM_TTOPTION TrueTypeフォントの印刷方法を指定。 DM_COLLATE 丁合い機能を持つプリンタに対して複数部数コピーの際のページの丁合いを行うように要求する。 DM_FORMNAME 使用する用紙の形状名。 DM_LOGPIXELS プリンタデバイスでは使用されない。 DM_BITSPERPEL プリンタデバイスでは使用されない。 DM_PELSWIDTH プリンタデバイスでは使用されない。 DM_PELSHEIGHT プリンタデバイスでは使用されない。 DM_DISPLAYFLAGS プリンタデバイスでは使用されない。 DM_DISPLAYFREQUENCY プリンタデバイスでは使用されない。
●NSDPrinterWatchコンストラクタの説明
構文:Public Sub New()
使用法:Dim Cls_PWatch As New NSDPrinterWatch
引数:なし。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub End Class
●NSDPrinterWatchプロパティの説明
名前:PrinterName
構文:Public ReadOnly Property PrinterName() As String
機能:プリンタ名を返します。
引数:なし。
値:String
値の説明:プリンタ名を返します。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 MsgBox("プリンタ名:" & Sender.PrinterName) End If End Sub End Class
名前:Watch
構文:Public ReadOnly Property Watch() As Boolean
機能:監視状態を返します。
引数:なし。
値:Boolean
値の説明:
True :監視中です。
False:監視していません。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) End If End Sub End Class
名前:WatchFlag
構文:Public ReadOnly Property WatchFlag() As Printer_Change_Notification_General_Flags
機能:監視中の条件を返します。
引数:なし。
値:Printer_Change_Notification_General_Flags
値の説明:
監視中の変更通知を受け取る条件を返します。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub Private Sub Button2_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button2.Click If Cls_PWatch.Watch Then ' 監視中。 Dim Str_WatchContents As String = "通知内容" & ControlChars.CrLf With Cls_PWatch If .WatchFlag And NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_FORM Then Str_WatchContents &= ControlChars.CrLf & "用紙が変更されたことを通知する。" End If If .WatchFlag And NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PORT Then Str_WatchContents &= ControlChars.CrLf & "ポートが変更されたことを通知する。" End If If .WatchFlag And NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_JOB Then Str_WatchContents &= ControlChars.CrLf & "印刷ジョブの動作時に通知する。" End If If .WatchFlag And NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PRINTER Then Str_WatchContents &= ControlChars.CrLf & "プリンタが変更されたことを通知する。" End If If .WatchFlag And NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PRINT_PROCESSOR Then Str_WatchContents &= ControlChars.CrLf & "プリントプロセッサが変更されたことを通知する。" End If If .WatchFlag And NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PRINTER_DRIVER Then Str_WatchContents &= ControlChars.CrLf & "プリンタドライバが変更されたことを通知する。" End If End With MsgBox(Str_WatchContents) Else ' 監視していない。 MsgBox("監視していません。") End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) End If End Sub End Class
名前:ChangeNotificationInfo
構文:Public ReadOnly Property ChangeNotificationInfo() As NSD_CHANGE_NOTIFICATION_INFO
機能:監視中の通知有無情報を返します。
引数:なし。
値:NSD_CHANGE_NOTIFICATION_INFO
値の説明:
監視中の通知有無情報を返します。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub Private Sub Button2_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button2.Click If Cls_PWatch.Watch Then ' 監視中。 Dim Str_WatchContents As String = "通知内容" & ControlChars.CrLf With Cls_PWatch.ChangeNotificationInfo If .Form Then Str_WatchContents &= ControlChars.CrLf & "用紙が変更されたことを通知する。" End If If .Port Then Str_WatchContents &= ControlChars.CrLf & "ポートが変更されたことを通知する。" End If If .Job Then Str_WatchContents &= ControlChars.CrLf & "印刷ジョブの動作時に通知する。" End If If .Printer Then Str_WatchContents &= ControlChars.CrLf & "プリンタが変更されたことを通知する。" End If If .PrintProcessor Then Str_WatchContents &= ControlChars.CrLf & "プリントプロセッサが変更されたことを通知する。" End If If .PrinterDriver Then Str_WatchContents &= ControlChars.CrLf & "プリンタドライバが変更されたことを通知する。" End If End With MsgBox(Str_WatchContents) Else ' 監視していない。 MsgBox("監視していません。") End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) End If End Sub End Class
名前:NotificationRetryStyle
構文:Public Property NotificationRetryStyle() As NSD_NotificationRetryStyle
機能:変更通知の取得に成功した場合で、通知情報が受け取れない場合の処理設定を設定します。
引数:なし。
値の説明:
変更通知の取得に成功した場合で、通知情報が受け取れない場合の処理。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH Cls_PWatch.NotificationRetryStyle = NSDPrinterWatch.NSD_NotificationRetryStyle.REFRESH_RETRY ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) End If End Sub End Class
●NSDPrinterWatchメソッドの説明
名前:Dispose
構文:Public Overridable Sub Dispose()
機能:NSDPrinterWatchクラスのオブジェクトで使用されている全てのリソースを解放します。
※終了時に必ず呼び出します。
引数:なし。
戻り値:なし。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub End Class
名前:PrinterWatch
構文:Public Function PrinterWatch( PrinterName , WatchFlag , NotificationStyle ) As Boolean
機能:プリンターを監視します。
引数:
名前 型 引数渡しの方法 説明 PrinterName String 値渡し(ByVal) プリンタ名を渡します。
※プリンタ名はGetPrinterListで渡されたプリンタ名を渡します。WatchFlag Printer_Change_Notification_General_Flags 値渡し(ByVal) 変更通知を受け取る条件を渡します。 NotificationStyle NSD_NotificationStyle 値渡し(ByVal) 通知スタイルを渡します。 戻り値:Boolean
戻り値の説明:
True:成功 False:失敗
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) End If End Sub End Class
名前:PrinterWatchEnd
構文:Public Function PrinterWatchEnd() As Boolean
機能:プリンターの監視を終了します。
引数:なし。
戻り値:Boolean
戻り値の説明:
True:成功 False:失敗
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) End If End Sub End Class
名前:GetEventsContens
構文:Public Function GetEventsContens( GeneralFlag , NotificationFlags , Contens() ) As Boolean
機能:イベントの内容を取得します。
引数:
名前 型 引数渡しの方法 説明 GeneralFlag Printer_Change_Notification_General_Flags 値渡し(ByVal) 変更通知を受け取る条件を渡します。 NotificationFlags Integer 値渡し(ByVal) GeneralFlagの条件に対するフラグを渡します。
GeneralFlagの値 参照するフラグ PRINTER_CHANGE_FORM Printer_Change_Notification_Form_Flags PRINTER_CHANGE_PORT Printer_Change_Notification_Port_Flags PRINTER_CHANGE_JOB Printer_Change_Notification_Job_Flags PRINTER_CHANGE_PRINTER Printer_Change_Notification_Printer_Flags PRINTER_CHANGE_PRINT_PROCESSOR Printer_Change_Notification_Processor_Flags PRINTER_CHANGE_PRINTER_DRIVER Printer_Change_Notification_Driver_Flags Contens() String 参照渡し(ByRef) 内容を返します。 戻り値:Boolean
戻り値の説明:
True:成功 False:失敗
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) End If End Sub End Class
名前:GetPrinterList
構文:Public Function GetPrinterList( PrinterList() ) As Boolean
機能:インストールされているプリンタのリストを返します。
引数:
名前 型 引数渡しの方法 説明 PrinterList() String 参照渡し(ByRef) プリンタ名のリストを返します。 戻り値:Boolean
戻り値の説明:
True:成功 False:失敗
使用例:
Public Class Form1 Dim StrCls_PrinterName() As String = Nothing ' プリンタの一覧。 Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Using Cls_Pw As New NSDPrinterWatch Cls_Pw.GetPrinterList(StrCls_PrinterName) End Using End Sub End Class
●NSDPrinterWatchイベントの説明
名前:Event_Change_Notification
構文:Public Event Event_Change_Notification( Sender , GeneralFlag , NotificationFlags , NotifyInfo , Time )
機能:通知用イベント。
引数:
名前 型 引数渡しの方法 説明 Sender NSDPrinterWatch 値渡し(ByVal) 呼び出し側のNSDPrinterWatchを渡します。 GeneralFlag Printer_Change_Notification_General_Flags 値渡し(ByVal) 変更通知を受け取る条件を渡します。 ※複数の場合もありますので、ビットフラグで判定します。
エラー発生の場合は-1。NotificationFlags Integer 値渡し(ByVal) GeneralFlagの条件に対するフラグを渡します。
GeneralFlagの値 参照するフラグ PRINTER_CHANGE_FORM Printer_Change_Notification_Form_Flags PRINTER_CHANGE_PORT Printer_Change_Notification_Port_Flags PRINTER_CHANGE_JOB Printer_Change_Notification_Job_Flags PRINTER_CHANGE_PRINTER Printer_Change_Notification_Printer_Flags PRINTER_CHANGE_PRINT_PROCESSOR Printer_Change_Notification_Processor_Flags PRINTER_CHANGE_PRINTER_DRIVER Printer_Change_Notification_Driver_Flags NotifyInfo NSDPrinterNotifyInfo 値渡し(ByVal) プリンターの通知情報を渡します。 Time Date 値渡し(ByVal) 呼び出し時間を渡します。 ※GeneralFlagとNotificationFlagsが共に-1の場合は、監視を継続することはできません。
再度監視を行う場合は、監視の終了処理を行ってからPrinterWatchメソッドを使用して監視を行ってください。戻り値:なし。
使用例:
Public Class Form1 Dim Cls_PWatch As NSDPrinterWatch = Nothing Private Sub Form1_FormClosed( sender As Object, _ e As System.Windows.Forms.FormClosedEventArgs _ ) Handles Me.FormClosed Cls_PWatch.Dispose() Cls_PWatch = Nothing End Sub Private Sub Form1_Load( sender As Object, _ e As System.EventArgs _ ) Handles Me.Load Cls_PWatch = New NSDPrinterWatch End Sub Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs _ ) Handles Button1.Click If Cls_PWatch.Watch Then ' 監視中。 ' 監視を解除します。 WatchEnd() Else ' 監視していない。 Dim Int_General_Flags As NSDPrinterWatch.Printer_Change_Notification_General_Flags = _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_ALL Dim Int_NotificationStyle As NSDPrinterWatch.NSD_NotificationStyle = _ NSDPrinterWatch.NSD_NotificationStyle.BOTH ' 監視を行います。 If Cls_PWatch.PrinterWatch("監視するプリンタ名", Int_General_Flags, Int_NotificationStyle) Then ' 通知用イベントをセットします。 AddHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification Else MsgBox("監視が正常に行えていません。") End If End If End Sub ' 監視を解除します。 Private Sub WatchEnd() Cls_PWatch.PrinterWatchEnd() ' 通知用イベントを解除します。 RemoveHandler Cls_PWatch.Event_Change_Notification, AddressOf Change_Notification End Sub Sub Change_Notification( ByVal Sender As NSDPrinterWatch, _ ByVal IntVal_General_Flag As NSDPrinterWatch.Printer_Change_Notification_General_Flags, _ ByVal IntVal_NotificationFlags As Integer, _ ByVal ClsNotifyInfo As NSDPrinterWatch.NSDPrinterNotifyInfo, _ ByVal Time As Date ) If IntVal_General_Flag = -1 AndAlso _ IntVal_NotificationFlags = -1 Then MsgBox("変更通知が受け取れないエラーが発生しました。") ' 監視中なので、監視を解除します。 WatchEnd() Else ' 内容を取得します。 Dim Str_Contents() As String = Nothing Sender.GetEventsContens(IntVal_General_Flag, IntVal_NotificationFlags, Str_Contents) Dim Str_Msg As String = Nothing For Int_Loop As Integer = 0 To Str_Contents.Length - 1 Str_Msg = Str_Msg & Str_Contents(Int_Loop) & ControlChars.CrLf Next MsgBox(Str_Msg) Dim Str_DebugMsg As String = Nothing If (IntVal_General_Flag And _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_FORM) Then ’フォーム(用紙)の変更通知。 If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Form_Flags.PRINTER_CHANGE_ADD_FORM) Then Str_DebugMsg &= "サーバーに用紙が追加されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Form_Flags.PRINTER_CHANGE_SET_FORM) Then Str_DebugMsg &= "サーバ上で用紙が設定されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Form_Flags.PRINTER_CHANGE_DELETE_FORM) Then Str_DebugMsg &= "サーバーから用紙が削除されました。" & ControlChars.CrLf End If End If If (IntVal_General_Flag And _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PORT) Then ' ポートの変更通知。 If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Port_Flags.PRINTER_CHANGE_ADD_PORT) Then Str_DebugMsg &= "サーバーにポートまたはモニタが追加されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Port_Flags.PRINTER_CHANGE_CONFIGURE_PORT) Then Str_DebugMsg &= "サーバー上でポートが設定されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Port_Flags.PRINTER_CHANGE_DELETE_PORT) Then Str_DebugMsg &= "サーバーからポートまたはモニタが削除されました。" & ControlChars.CrLf End If End If If (IntVal_General_Flag And _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_JOB) Then ' ジョブに対する変更通知条件。 If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Job_Flags.PRINTER_CHANGE_ADD_JOB) Then Str_DebugMsg &= "プリンタに印刷ジョブが送信されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Job_Flags.PRINTER_CHANGE_SET_JOB) Then Str_DebugMsg &= "ジョブが設定されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Job_Flags.PRINTER_CHANGE_DELETE_JOB) Then Str_DebugMsg &= "ジョブが削除されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Job_Flags.PRINTER_CHANGE_WRITE_JOB) Then Str_DebugMsg &= "ジョブデータが書き込まれました。" & ControlChars.CrLf End If End If If (IntVal_General_Flag And _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PRINTER) Then ' プリンターの変更通知。 If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Printer_Flags.PRINTER_CHANGE_ADD_PRINTER) Then Str_DebugMsg &= "サーバーにプリンタが追加されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Printer_Flags.PRINTER_CHANGE_SET_PRINTER) Then Str_DebugMsg &= "プリンタが設定されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Printer_Flags.PRINTER_CHANGE_DELETE_PRINTER) Then Str_DebugMsg &= "プリンタが削除されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Printer_Flags.PRINTER_CHANGE_FAILED_CONNECTION_PRINTER) Then Str_DebugMsg &= "プリンタへの接続に失敗しました。" & ControlChars.CrLf End If End If If (IntVal_General_Flag And _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PRINT_PROCESSOR) Then ' プリントプロセッサの変更通知。 If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Processor_Flags.PRINTER_CHANGE_ADD_PRINT_PROCESSOR) Then Str_DebugMsg &= "サーバーにプリントプロセッサが追加されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Processor_Flags.PRINTER_CHANGE_DELETE_PRINT_PROCESSOR) Then Str_DebugMsg &= "サーバーからプリントプロセッサが削除されました。" & ControlChars.CrLf End If End If If (IntVal_General_Flag And _ NSDPrinterWatch.Printer_Change_Notification_General_Flags.PRINTER_CHANGE_PRINT_PROCESSOR) Then ' プリンタードライバーの変更通知。 If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Driver_Flags.PRINTER_CHANGE_ADD_PRINTER_DRIVER) Then Str_DebugMsg &= "サーバーにプリンタドライバが追加されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Driver_Flags.PRINTER_CHANGE_SET_PRINTER_DRIVER) Then Str_DebugMsg &= "プリンタドライバが設定されました。" & ControlChars.CrLf End If If (IntVal_NotificationFlags And _ NSDPrinterWatch.Printer_Change_Notification_Driver_Flags.PRINTER_CHANGE_DELETE_PRINTER_DRIVER) Then Str_DebugMsg &= "サーバーからプリンタドライバが削除されました。" & ControlChars.CrLf End If End If If Not ClsNotifyInfo.JobInfoCollection Is Nothing Then ' 印刷ジョブの通知情報が存在します。 Dim Int_JobInfoCount As Integer = 1 For Each OneJob As NSDPrinterWatch.NSDPrintJob In ClsNotifyInfo.JobInfoCollection ' 一つの印刷ジョブ情報。 Dim Str_JobMsg As String = Nothing Dim Str_JobInfoCount As String = "(" & Int_JobInfoCount.ToString & ")" Str_JobMsg = "印刷ジョブの名前" & Str_JobInfoCount & ":" & OneJob.DocumentName & ControlChars.CrLf Str_JobMsg &= "マシンの名前" & Str_JobInfoCount & ":" & OneJob.MachineName & ControlChars.CrLf Str_JobMsg &= "ユーザーの名前" & Str_JobInfoCount & ":" & OneJob.UserName & ControlChars.CrLf Str_DebugMsg &= Str_JobMsg Int_JobInfoCount += 1 Next End If If Not ClsNotifyInfo.PrintInfoCollection Is Nothing Then ' プリンタ通知情報が存在します。 Dim Int_PrintNotifyInfoCount As Integer = 1 For Each OnePrintNotify As NSDPrinterWatch.NSDPrintNotification In ClsNotifyInfo.PrintInfoCollection Dim Str_PrintNotifyMsg As String = Nothing Dim Str_PrintNotifyInfoCount As String = "(" & Int_PrintNotifyInfoCount.ToString & ")" Str_PrintNotifyMsg = "サーバーの名前" & Str_PrintNotifyInfoCount & ":" & OnePrintNotify.ServerName & ControlChars.CrLf Str_PrintNotifyMsg &= "プリンタの名前" & Str_PrintNotifyInfoCount & ":" & OnePrintNotify.PrinterName & ControlChars.CrLf Str_PrintNotifyMsg &= "出力ポートの名前" & Str_PrintNotifyInfoCount & ":" & OnePrintNotify.PortName & ControlChars.CrLf Str_DebugMsg &= Str_PrintNotifyMsg Int_PrintNotifyInfoCount += 1 Next End If Debug.WriteLine(Str_DebugMsg) End If End Sub End Class
Copyright (C) 2012 Nihon System Developer Corp. All Rights Reserved.