home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / msmqocm.cab / disdraw.frm < prev    next >
Text File  |  1997-10-06  |  12KB  |  398 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5820
  5.    ClientLeft      =   3345
  6.    ClientTop       =   2295
  7.    ClientWidth     =   6330
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   5820
  10.    ScaleWidth      =   6330
  11.    Begin VB.Frame Frame1 
  12.       Caption         =   "Sent Messages"
  13.       Height          =   975
  14.       Left            =   3120
  15.       TabIndex        =   6
  16.       Top             =   4680
  17.       Width           =   2535
  18.       Begin VB.OptionButton Option1 
  19.          Caption         =   "&Express"
  20.          Height          =   252
  21.          Index           =   0
  22.          Left            =   240
  23.          TabIndex        =   4
  24.          Top             =   240
  25.          Value           =   -1  'True
  26.          Width           =   2052
  27.       End
  28.       Begin VB.OptionButton Option1 
  29.          Caption         =   "&Recoverable"
  30.          Height          =   252
  31.          Index           =   1
  32.          Left            =   240
  33.          TabIndex        =   5
  34.          Top             =   600
  35.          Width           =   2052
  36.       End
  37.    End
  38.    Begin VB.PictureBox Picture1 
  39.       Height          =   3855
  40.       Left            =   240
  41.       MousePointer    =   1  'Arrow
  42.       ScaleHeight     =   253
  43.       ScaleMode       =   3  'Pixel
  44.       ScaleWidth      =   389
  45.       TabIndex        =   3
  46.       Top             =   120
  47.       Width           =   5895
  48.    End
  49.    Begin VB.CommandButton Attach 
  50.       Caption         =   "&Attach"
  51.       Default         =   -1  'True
  52.       BeginProperty Font 
  53.          Name            =   "MS Sans Serif"
  54.          Size            =   8.25
  55.          Charset         =   0
  56.          Weight          =   700
  57.          Underline       =   0   'False
  58.          Italic          =   0   'False
  59.          Strikethrough   =   0   'False
  60.       EndProperty
  61.       Height          =   375
  62.       Left            =   4800
  63.       TabIndex        =   2
  64.       Top             =   4200
  65.       Width           =   1335
  66.    End
  67.    Begin VB.TextBox FriendName 
  68.       Height          =   285
  69.       Left            =   1440
  70.       TabIndex        =   1
  71.       Top             =   4200
  72.       Width           =   2055
  73.    End
  74.    Begin VB.Label Label1 
  75.       Caption         =   "Remote &Friend:"
  76.       Height          =   255
  77.       Left            =   240
  78.       TabIndex        =   0
  79.       Top             =   4200
  80.       Width           =   1215
  81.    End
  82. End
  83. Attribute VB_Name = "Form1"
  84. Attribute VB_GlobalNameSpace = False
  85. Attribute VB_Creatable = False
  86. Attribute VB_PredeclaredId = True
  87. Attribute VB_Exposed = False
  88. ' ------------------------------------------------------------------------
  89. '               Copyright (C) 1995 Microsoft Corporation
  90. '
  91. ' You have a royalty-free right to use, modify, reproduce and distribute
  92. ' the Sample Application Files (and/or any modified version) in any way
  93. ' you find useful, provided that you agree that Microsoft has no warranty,
  94. ' obligations or liability for any Sample Application Files.
  95. ' ------------------------------------------------------------------------
  96. '
  97. ' Type Guid
  98. '
  99. Const guidDraw = "{151ceac0-acb5-11cf-8b51-0020af929546}"
  100. Option Explicit
  101. Const MaxNumLen = 7
  102. Private Type Line
  103.     X1 As Long
  104.     Y1 As Long
  105.     X2 As Long
  106.     Y2 As Long
  107. End Type
  108.  
  109. Dim lLastX As Long
  110. Dim lLastY As Long
  111. Dim Lines() As Line
  112. Dim cLines As Integer
  113. Dim lArraySize As Integer
  114. Dim strScreenText As String
  115. Dim fWasText As Integer
  116. Dim strLogin As String
  117. Dim q As MSMQQueue
  118. Attribute q.VB_VarHelpID = -1
  119. Dim WithEvents qevent As MSMQEvent
  120. Attribute qevent.VB_VarHelpID = -1
  121. Dim qFriend As MSMQQueue
  122. Dim msgOut As MSMQMessage
  123.  
  124. '
  125. 'Locate a remote queue
  126. '
  127. Private Sub Attach_Click()
  128.     Dim queryFriend As New MSMQQuery
  129.     Dim qinfoFriend As MSMQQueueInfo
  130.     Dim qinfos As MSMQQueueInfos
  131.     FriendName = UCase(FriendName)
  132.     Set qinfos = queryFriend.LookupQueue( _
  133.         Label:=(FriendName), _
  134.         ServiceTypeGuid:=guidDraw)
  135.     qinfos.Reset
  136.     Set qinfoFriend = qinfos.Next
  137.     If qinfoFriend Is Nothing Then                   'And locate it
  138.         MsgBox "No Such friend, Sorry..."   'No queue defined
  139.     Else
  140.         If Not qFriend Is Nothing Then
  141.           If qFriend.IsOpen Then qFriend.Close
  142.         End If
  143.  
  144.         Set qFriend = qinfoFriend.Open(MQ_SEND_ACCESS, 0)
  145.         Caption = strLogin + " - Connected to " + FriendName
  146.         Attach.Enabled = False
  147.     End If
  148. End Sub
  149.  
  150. '
  151. ' Application Initialization
  152. '
  153. Private Sub Form_Load()
  154.     Dim strDefaultQueueName As String
  155.     Dim lTempPointer As Long
  156.     Dim query As New MSMQQuery
  157.     Dim qinfo As MSMQQueueInfo
  158.     Dim qinfos As MSMQQueueInfos
  159.     Dim strComputerName As String
  160.     
  161.     Set msgOut = New MSMQMessage
  162.     strDefaultQueueName = Environ("USERNAME")
  163.     strLogin = InputBox("Your Name Please", "Login", strDefaultQueueName)
  164.     If strLogin = "" Then End
  165.     strLogin = UCase(strLogin)
  166.     Caption = strLogin
  167.     Set qinfos = query.LookupQueue( _
  168.         Label:=strLogin, _
  169.         ServiceTypeGuid:=guidDraw)
  170.     qinfos.Reset             'And locate this queue
  171.     Set qinfo = qinfos.Next
  172.     If qinfo Is Nothing Then
  173.         Set qinfo = New MSMQQueueInfo
  174.         strComputerName = "."
  175.         qinfo.PathName = strComputerName + "\" + strLogin
  176.         qinfo.Label = strLogin
  177.         qinfo.ServiceTypeGuid = guidDraw
  178.         qinfo.Create                 'If there is no such create one.
  179.     End If
  180.     On Error GoTo retry_on_error
  181.         lTempPointer = Screen.MousePointer
  182.         Screen.MousePointer = 11 'ccArrowHourglass
  183.         Set q = qinfo.Open(MQ_RECEIVE_ACCESS, 0)
  184.         On Error GoTo 0
  185.         Screen.MousePointer = lTempPointer
  186.         GoTo all_ok
  187. retry_on_error:
  188.     '
  189.     'We may still not see the queue until the next replication
  190.     ' In this case, we get MQ_ERROR_QUEUE_NOT_FOUND and retry.
  191.     '
  192.     If Err.Number = MQ_ERROR_QUEUE_NOT_FOUND Then
  193.         Err.Clear
  194.         DoEvents
  195.         Resume
  196.     Else
  197.         MsgBox Err.Description, , "Error in Open"
  198.         End
  199.     End If
  200.     
  201. all_ok:
  202.     'All messages will be received asynchronously
  203.     ' So need an event handler
  204.     Set qevent = New MSMQEvent
  205.     q.EnableNotification qevent
  206. End Sub
  207. '
  208. 'Gets points and returns a line
  209. '
  210. Private Function PointsToLine(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Line
  211.     Dim lineNew As Line
  212.     lineNew.X1 = X1
  213.     lineNew.Y1 = Y1
  214.     lineNew.X2 = X2
  215.     lineNew.Y2 = Y2
  216.     PointsToLine = lineNew
  217. End Function
  218. '
  219. 'Draw a line in the picture control
  220. '
  221. Private Sub DrawLine(lineDraw As Line)
  222.     Picture1.Line (lineDraw.X1, lineDraw.Y1)-(lineDraw.X2, lineDraw.Y2)
  223.     fWasText = False
  224. End Sub
  225. '
  226. 'Display a line
  227. '
  228. Private Sub AddLine(lineNew As Line)
  229.     DrawLine lineNew
  230.     cLines = cLines + 1
  231.     If (cLines > lArraySize) Then
  232.         lArraySize = cLines * 2
  233.         ReDim Preserve Lines(lArraySize)
  234.     End If
  235.     Lines(cLines - 1) = lineNew
  236. End Sub
  237. '
  238. 'Clear the display
  239. '
  240. Private Sub ClearDraw()
  241.     cLines = 0
  242.     strScreenText = ""
  243.     Picture1.Refresh
  244. End Sub
  245. '
  246. 'Decode a string into a line
  247. '
  248. Private Function LineToString(lineIn As Line) As String
  249.     Dim strFormat As String
  250.     strFormat = String(MaxNumLen, "0")
  251.     LineToString = Format$(lineIn.X1, strFormat) + Format$(lineIn.Y1, strFormat) + Format$(lineIn.X2, strFormat) + Format$(lineIn.Y2, strFormat)
  252. End Function
  253. '
  254. 'Encode a line into a string
  255. '
  256. Private Function StringToLine(strIn As String) As Line
  257.     Dim lineOut As Line
  258.     lineOut.X1 = Val(Mid$(strIn, 1, MaxNumLen))
  259.     lineOut.Y1 = Val(Mid$(strIn, MaxNumLen + 1, MaxNumLen))
  260.     lineOut.X2 = Val(Mid$(strIn, MaxNumLen * 2 + 1, MaxNumLen))
  261.     lineOut.Y2 = Val(Mid$(strIn, MaxNumLen * 3 + 1, MaxNumLen))
  262.     StringToLine = lineOut
  263. End Function
  264.  
  265. Private Sub Form_Unload(Cancel As Integer)
  266.     If Not q Is Nothing Then
  267.         q.Close
  268.     End If
  269.     If Not qFriend Is Nothing Then qFriend.Close
  270.     
  271. End Sub
  272.  
  273.  
  274.  
  275. Private Sub FriendName_Change()
  276.         Attach.Enabled = True
  277. End Sub
  278.  
  279.  
  280. '
  281. 'Message Receive event
  282. '
  283. Private Sub qevent_Arrived(ByVal q As Object, ByVal lCursor As Long)
  284.     Dim msgIn As MSMQMessage
  285.     Dim lineNew As Line
  286.     Dim strTextIn As String
  287.     
  288.     On Error GoTo ErrorHandler
  289.     Set msgIn = q.Receive(ReceiveTimeout:=100)
  290.     If Not msgIn Is Nothing Then
  291.         strTextIn = msgIn.Body          'Read the body of the message
  292.         If Len(strTextIn) = 1 Then         'If 1 byte long
  293.             TypeChar strTextIn             'it is a character - so display it
  294.         Else
  295.             lineNew = StringToLine(msgIn.Body)   'Otherwise it is a line
  296.             AddLine lineNew                         'so draw it
  297.         End If
  298.     End If
  299. ErrorHandler:
  300.     ' reenable event firing
  301.     q.EnableNotification qevent
  302. End Sub
  303.  
  304.  
  305.  
  306.  
  307. Private Sub qevent_ArrivedError(ByVal pdispQueue As Object, ByVal lErrorCode As Long, ByVal lCursor As Long)
  308.     MsgBox Hex$(lErrorCode), , "Receive Error!"
  309.     q.EnableNotification qevent
  310. End Sub
  311.  
  312. Private Sub Option1_Click(Index As Integer)
  313.     msgOut.Delivery = Index
  314. End Sub
  315.  
  316.  
  317. '
  318. 'Key press event
  319. '
  320. Private Sub Picture1_KeyPress(KeyAscii As Integer)
  321.     TypeChar (Chr(KeyAscii))                'Display the character
  322.     If Not qFriend Is Nothing Then
  323.         If qFriend.IsOpen Then
  324.             msgOut.Priority = 4                 'Set the priority to 4 (high)
  325.             msgOut.Body = Chr(KeyAscii)         'Fill the body with the character
  326.             msgOut.Label = "Key: " + msgOut.Body
  327.             msgOut.Send qFriend                 'And send the message
  328.         End If
  329.     End If
  330. End Sub
  331. '
  332. 'Display a character
  333. '(Handles backspace)
  334. '
  335. Private Sub TypeChar(Key As String)
  336.     If Asc(Key) = 8 Then 'BackSpace
  337.         If strScreenText <> "" Then
  338.             strScreenText = Left$(strScreenText, Len(strScreenText) - 1)
  339.             Picture1.Refresh
  340.         End If
  341.     Else
  342.         strScreenText = strScreenText + Key
  343.         If fWasText Then
  344.             Picture1.Print Key;
  345.         Else
  346.             Picture1.Refresh
  347.         End If
  348.     End If
  349. End Sub
  350. '
  351. 'Mouse Down Event
  352. '
  353. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  354.     If Button = 1 Then      'Remember the
  355.         lLastX = X           'Mouse location
  356.         lLastY = Y
  357.     End If
  358. End Sub
  359. '
  360. 'Mouse Move Event
  361. '
  362. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  363.     If Button = 1 And X > 0 And Y > 0 Then          'Something to draw?
  364.         Dim lineNew As Line
  365.         lineNew = PointsToLine(lLastX, lLastY, X, Y)  'Get a new line
  366.         AddLine lineNew                             'And display it
  367.         If Not qFriend Is Nothing Then
  368.             If qFriend.IsOpen Then
  369.                 msgOut.Priority = 3                     'Set the priority to 3 (low)
  370.                 msgOut.Body = LineToString(lineNew)     'Fill the body with the line
  371.                 msgOut.Label = Str(lLastX) + "," + Str(lLastY) + " To " + Str(X) + "," + Str(Y)
  372.                 msgOut.Send qFriend                     'And send the message
  373.             End If
  374.         End If
  375.         lLastX = X
  376.         lLastY = Y
  377.     End If
  378. End Sub
  379. '
  380. '2nd button click == Clear the display
  381. '
  382. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  383.     If Button = 2 Then ClearDraw
  384. End Sub
  385. '
  386. 'Repaint the display event
  387. '
  388. Private Sub Picture1_Paint()
  389.     Dim I As Integer
  390.     For I = 0 To cLines - 1
  391.         DrawLine Lines(I)
  392.     Next
  393.     Picture1.CurrentX = 0
  394.     Picture1.CurrentY = 0
  395.     Picture1.Print strScreenText;
  396.     fWasText = True
  397. End Sub
  398.