VB中使用DDE实现两个应用程序之间的通讯

工程:Main
加载一个pictureBox,命名为picDDE
加载一个commandButton,命名为cmdSendMessage

Option Explicit

Private Sub LinkAndSendMessage(ByVal Msg As String)
    Dim t As Long
   
    picDDE.LinkMode = 0
    picDDE.LinkTopic = "Child|frmChild"
    picDDE.LinkMode = 2
    picDDE.LinkExecute Msg
   
    t = picDDE.LinkTimeout
    picDDE.LinkTimeout = 1
    picDDE.LinkMode = 0
    picDDE.LinkTimeout = t
End Sub

Private Sub cmdSendMessage_Click()
    LinkAndSendMessage "测试通讯!!"
End Sub

Private Sub Form_Load()
    Shell App.Path & "/Child.exe"
End Sub


工程:Child
设置其LineMode = 1-Source
设置其LineTopic = frmChild
Option Explicit

Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
    MsgBox CmdStr
    Cancel = 0
End Sub

展开阅读全文

没有更多推荐了,返回首页