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 / samples5 / ch14 / pipedest.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  2.1 KB  |  73 lines

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