www.pudn.com > 2006021801.zip > frmFileMapping.frm


VERSION 5.00 
Begin VB.Form FileMapping  
   BorderStyle     =   1  'Fixed Single 
   Caption         =   "Form1" 
   ClientHeight    =   6525 
   ClientLeft      =   45 
   ClientTop       =   330 
   ClientWidth     =   7815 
   LinkTopic       =   "Form1" 
   MaxButton       =   0   'False 
   MinButton       =   0   'False 
   ScaleHeight     =   6525 
   ScaleWidth      =   7815 
   StartUpPosition =   3  '窗口缺省 
   Begin VB.TextBox Text2  
      Height          =   4215 
      Left            =   480 
      MultiLine       =   -1  'True 
      ScrollBars      =   2  'Vertical 
      TabIndex        =   4 
      Text            =   "frmFileMapping.frx":0000 
      Top             =   1080 
      Width           =   6855 
   End 
   Begin VB.CommandButton Command1  
      Caption         =   "写入" 
      Default         =   -1  'True 
      Height          =   375 
      Left            =   3240 
      TabIndex        =   1 
      Top             =   6000 
      Width           =   975 
   End 
   Begin VB.Timer Timer1  
      Enabled         =   0   'False 
      Interval        =   100 
      Left            =   7200 
      Top             =   120 
   End 
   Begin VB.TextBox Text1  
      Height          =   495 
      Left            =   480 
      TabIndex        =   0 
      Text            =   "开始吧!" 
      Top             =   5400 
      Width           =   6975 
   End 
   Begin VB.Label Label2  
      Alignment       =   2  'Center 
      Caption         =   "用时钟控制和共享内存映射来异步通讯" 
      BeginProperty Font  
         Name            =   "宋体" 
         Size            =   14.25 
         Charset         =   134 
         Weight          =   400 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FF0000& 
      Height          =   375 
      Left            =   240 
      TabIndex        =   3 
      Top             =   120 
      Width           =   7215 
   End 
   Begin VB.Label Label1  
      Caption         =   "要观察本程序的效果,请再起动本程序的一个实例" 
      Height          =   375 
      Left            =   1440 
      TabIndex        =   2 
      Top             =   600 
      Width           =   4215 
   End 
End 
Attribute VB_Name = "FileMapping" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
'用时钟控制和共享内存映射来异步通讯 
'目的是共享内存一经修改就更新目标文本框 
Option Explicit 
Public ss As New CSharedString 
Private strInstance As String                '进程随机号 
 
Private Sub Command1_Click() 
    Dim strTmp As String 
    If ss <> "" Then 
        strTmp = ss 
        ss = strTmp & vbCrLf & strInstance & Text1 
    End If 
'    ss = ss & strInstance & Text1 
    Timer1.Enabled = True 
    Text1 = "" 
End Sub 
 
Private Sub Form_Activate() 
    Command1.SetFocus 
    Call Command1_Click 
End Sub 
 
Private Sub Form_Load() 
    ss.Create "AdamBear2002" 
    Randomize (Time) 
    strInstance = "进程" & Str(Int(Rnd() * 100)) & "说道:" 
    If ss = "" Then 
        ss = "对话开始" 
    End If 
End Sub 
 
Private Sub Text1_Change() 
    ' 
End Sub 
 
Private Sub Text1_GotFocus() 
    Timer1.Enabled = False 
End Sub 
 
Private Sub Text1_LostFocus() 
    Timer1.Enabled = True 
End Sub 
 
Private Sub Timer1_Timer() 
    Text2.Text = ss 
End Sub