home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch14 / pipedest.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  2.2 KB  |  74 lines

  1. VERSION 4.00
  2. Begin VB.Form frmPipeDest 
  3.    Caption         =   "Pipe Destination"
  4.    ClientHeight    =   2940
  5.    ClientLeft      =   1155
  6.    ClientTop       =   4860
  7.    ClientWidth     =   4725
  8.    Height          =   3345
  9.    Left            =   1095
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2940
  12.    ScaleWidth      =   4725
  13.    Top             =   4515
  14.    Width           =   4845
  15.    Begin VB.Timer Timer1 
  16.       Enabled         =   0   'False
  17.       Interval        =   100
  18.       Left            =   4320
  19.       Top             =   0
  20.    End
  21.    Begin VB.TextBox txtDest 
  22.       Height          =   2295
  23.       Left            =   180
  24.       MultiLine       =   -1  'True
  25.       TabIndex        =   0
  26.       Top             =   480
  27.       Width           =   4335
  28.    End
  29.    Begin VB.Label Label1 
  30.       Caption         =   "Incoming Data:"
  31.       Height          =   255
  32.       Left            =   180
  33.       TabIndex        =   1
  34.       Top             =   120
  35.       Width           =   3375
  36.    End
  37. Attribute VB_Name = "frmPipeDest"
  38. Attribute VB_Creatable = False
  39. Attribute VB_Exposed = False
  40. Option Explicit
  41. ' Copyright 
  42.  1997 by Desaware Inc. All Rights Reserved
  43. Dim PipeHandle As Long
  44. Private Sub Form_Load()
  45.     PipeHandle = GetStdHandle(STD_INPUT_HANDLE)
  46.     ' MsgBox "PipeHandle: " & PipeHandle
  47.     Timer1.Enabled = True
  48. End Sub
  49. Private Sub Form_Unload(Cancel As Integer)
  50.     If PipeHandle <> 0 Then
  51.         Call CloseHandle(PipeHandle)
  52.     End If
  53. End Sub
  54. Private Sub Timer1_Timer()
  55.     Dim res&
  56.     Dim x&
  57.     Dim t$
  58.     Dim lread&, lavail&, lmessage&
  59.     res = PeekNamedPipe(PipeHandle, ByVal 0&, 0, lread, lavail, lmessage)
  60.     ' MsgBox res & lread & lavail & lmessage & " E: " & Hex$(GetLastError)
  61.     If res <> 0 And lavail > 0 Then
  62.         ReDim inbuf(lavail) As Byte
  63.         res = ReadFile(PipeHandle, inbuf(0), lavail, lread, 0)
  64.         ' MsgBox "read: " & lavail, lread
  65.         ' We need to convert into Unicode here.
  66.         t$ = inbuf()
  67.         t$ = StrConv(t$, vbUnicode)
  68.         txtDest = txtDest & t$
  69.     End If
  70. End Sub
  71. Private Sub txtDest_KeyPress(KeyAscii As Integer)
  72.     KeyAscii = 0
  73. End Sub
  74.