home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk1 / main.fr_ / main.bin
Text File  |  1993-04-28  |  17KB  |  597 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "DDE Experimenter"
  5.    FontTransparent =   0   'False
  6.    Height          =   5745
  7.    Left            =   930
  8.    LinkMode        =   1  'Source
  9.    LinkTopic       =   "System"
  10.    ScaleHeight     =   5340
  11.    ScaleWidth      =   6210
  12.    Top             =   1125
  13.    Width           =   6330
  14.    Begin Frame Frames 
  15.       Caption         =   "Destination Data"
  16.       Height          =   3015
  17.       Index           =   2
  18.       Left            =   120
  19.       TabIndex        =   21
  20.       Top             =   2280
  21.       Width           =   6015
  22.       Begin TextBox txtData 
  23.          Height          =   2160
  24.          Left            =   120
  25.          MultiLine       =   -1  'True
  26.          ScrollBars      =   3  'Both
  27.          TabIndex        =   22
  28.          Text            =   "Text1"
  29.          Top             =   720
  30.          Width           =   5760
  31.       End
  32.       Begin OptionButton optDataType 
  33.          Caption         =   "Graphics"
  34.          Height          =   255
  35.          Index           =   1
  36.          Left            =   1440
  37.          TabIndex        =   14
  38.          Top             =   360
  39.          Width           =   1815
  40.       End
  41.       Begin OptionButton optDataType 
  42.          Caption         =   "Text"
  43.          Height          =   255
  44.          Index           =   0
  45.          Left            =   120
  46.          TabIndex        =   13
  47.          Top             =   360
  48.          Value           =   -1  'True
  49.          Width           =   1095
  50.       End
  51.       Begin PictureBox picData 
  52.          AutoRedraw      =   -1  'True
  53.          DrawWidth       =   2
  54.          Height          =   2160
  55.          Left            =   120
  56.          ScaleHeight     =   2130
  57.          ScaleWidth      =   5730
  58.          TabIndex        =   23
  59.          Top             =   720
  60.          Visible         =   0   'False
  61.          Width           =   5760
  62.       End
  63.    End
  64.    Begin Frame Frames 
  65.       Caption         =   "Source Properties"
  66.       Height          =   1440
  67.       Index           =   1
  68.       Left            =   4200
  69.       TabIndex        =   20
  70.       Top             =   720
  71.       Width           =   1920
  72.       Begin TextBox txtSourceTopic 
  73.          Height          =   285
  74.          Left            =   120
  75.          TabIndex        =   17
  76.          Text            =   "System"
  77.          Top             =   960
  78.          Width           =   1695
  79.       End
  80.       Begin CheckBox chkSourceMode 
  81.          Caption         =   "&Source Enabled"
  82.          Height          =   240
  83.          Left            =   120
  84.          TabIndex        =   15
  85.          Top             =   360
  86.          Value           =   1  'Checked
  87.          Width           =   1680
  88.       End
  89.       Begin Label Labels 
  90.          Caption         =   "Source &Link Topic"
  91.          Height          =   240
  92.          Index           =   3
  93.          Left            =   120
  94.          TabIndex        =   16
  95.          Top             =   720
  96.          Width           =   1680
  97.       End
  98.    End
  99.    Begin CommandButton cmdExit 
  100.       Caption         =   "E&xit"
  101.       Height          =   480
  102.       Left            =   4200
  103.       TabIndex        =   18
  104.       Top             =   120
  105.       Width           =   1920
  106.    End
  107.    Begin Frame Frames 
  108.       Caption         =   "Destination Properties"
  109.       Height          =   2160
  110.       Index           =   0
  111.       Left            =   120
  112.       TabIndex        =   19
  113.       Top             =   0
  114.       Width           =   3960
  115.       Begin ComboBox cboAppName 
  116.          Height          =   300
  117.          Left            =   1200
  118.          TabIndex        =   1
  119.          Text            =   "ProgMan"
  120.          Top             =   360
  121.          Width           =   1215
  122.       End
  123.       Begin ComboBox cboTopic 
  124.          Height          =   300
  125.          Left            =   720
  126.          TabIndex        =   3
  127.          Text            =   "ProgMan"
  128.          Top             =   720
  129.          Width           =   1695
  130.       End
  131.       Begin ComboBox cboItem 
  132.          Height          =   300
  133.          Left            =   720
  134.          TabIndex        =   5
  135.          Top             =   1080
  136.          Width           =   1695
  137.       End
  138.       Begin OptionButton optLinkMode 
  139.          Caption         =   "&Notify"
  140.          Height          =   240
  141.          Index           =   3
  142.          Left            =   2640
  143.          TabIndex        =   8
  144.          Top             =   1200
  145.          Width           =   960
  146.       End
  147.       Begin CommandButton cmdExecute 
  148.          Caption         =   "&Execute"
  149.          Enabled         =   0   'False
  150.          Height          =   480
  151.          Left            =   2640
  152.          TabIndex        =   12
  153.          Top             =   1560
  154.          Width           =   1080
  155.       End
  156.       Begin CommandButton cmdPoke 
  157.          Caption         =   "&Poke"
  158.          Enabled         =   0   'False
  159.          Height          =   480
  160.          Left            =   1440
  161.          TabIndex        =   11
  162.          Top             =   1560
  163.          Width           =   1080
  164.       End
  165.       Begin CommandButton cmdRequest 
  166.          Caption         =   "&Request"
  167.          Enabled         =   0   'False
  168.          Height          =   480
  169.          Left            =   240
  170.          TabIndex        =   10
  171.          Top             =   1560
  172.          Width           =   1080
  173.       End
  174.       Begin OptionButton optLinkMode 
  175.          Caption         =   "&Manual"
  176.          Height          =   240
  177.          Index           =   2
  178.          Left            =   2640
  179.          TabIndex        =   7
  180.          Top             =   960
  181.          Width           =   960
  182.       End
  183.       Begin OptionButton optLinkMode 
  184.          Caption         =   "A&utomatic"
  185.          Height          =   240
  186.          Index           =   1
  187.          Left            =   2640
  188.          TabIndex        =   6
  189.          Top             =   720
  190.          Width           =   1200
  191.       End
  192.       Begin CommandButton cmdConnect 
  193.          Caption         =   "&Connect"
  194.          Height          =   480
  195.          Left            =   2520
  196.          TabIndex        =   9
  197.          Top             =   240
  198.          Width           =   1320
  199.       End
  200.       Begin Label Labels 
  201.          Caption         =   "Item"
  202.          Height          =   255
  203.          Index           =   2
  204.          Left            =   120
  205.          TabIndex        =   4
  206.          Top             =   1080
  207.          Width           =   615
  208.       End
  209.       Begin Label Labels 
  210.          Caption         =   "&Topic"
  211.          Height          =   255
  212.          Index           =   1
  213.          Left            =   120
  214.          TabIndex        =   2
  215.          Top             =   720
  216.          Width           =   615
  217.       End
  218.       Begin Label Labels 
  219.          Caption         =   "&Application"
  220.          Height          =   255
  221.          Index           =   0
  222.          Left            =   120
  223.          TabIndex        =   0
  224.          Top             =   360
  225.          Width           =   975
  226.       End
  227.    End
  228.    Begin Label lblSysLink 
  229.       Height          =   375
  230.       Left            =   4440
  231.       TabIndex        =   25
  232.       Top             =   5400
  233.       Visible         =   0   'False
  234.       Width           =   1455
  235.    End
  236.    Begin Label Topics 
  237.       Height          =   375
  238.       Left            =   120
  239.       TabIndex        =   24
  240.       Top             =   5400
  241.       Visible         =   0   'False
  242.       Width           =   2175
  243.    End
  244. End
  245. Option Explicit
  246. Option Compare Text     ' Perform case-insensitive string comparisons
  247. Dim TopicChangeFlag As Integer, appChangeFlag As Integer, Connected As Integer
  248. Dim NotifyFlag As Integer
  249. Const DEST_TEXT = 0, DEST_PIC = 1
  250. Const MNU_COPY = 0, MNU_PASTE = 1, MNU_PASTELINK = 2
  251.  
  252. Sub cboAppName_Click ()
  253.     If Connected Then cmdConnect.Value = True
  254.     FillTopicList
  255. End Sub
  256.  
  257. Sub cboAppName_LostFocus ()
  258.     If appChangeFlag Then
  259.     appChangeFlag = False
  260.     If Connected Then cmdConnect.Value = True
  261.     FillTopicList
  262.     End If
  263. End Sub
  264.  
  265. Sub cboItem_Change ()
  266. On Error Resume Next
  267.     picData.LinkItem = cboItem.Text
  268.     txtData.LinkItem = cboItem.Text
  269. End Sub
  270.  
  271. Sub cboItem_Click ()
  272.     picData.LinkItem = cboItem.Text
  273.     txtData.LinkItem = cboItem.Text
  274. End Sub
  275.  
  276. Sub cboTopic_Change ()
  277.     TopicChangeFlag = True
  278.     CheckForSystemTopic
  279. End Sub
  280.  
  281. Sub cboTopic_Click ()
  282.     If Connected Then cmdConnect.Value = True
  283.     CheckForSystemTopic
  284. End Sub
  285.  
  286. Sub cboTopic_LostFocus ()
  287.     If TopicChangeFlag Then
  288.     TopicChangeFlag = False
  289.     If Connected Then cmdConnect.Value = True
  290.     CheckForSystemTopic
  291.     End If
  292. End Sub
  293.  
  294. Sub ChangeLinkTopic ()
  295.  
  296. End Sub
  297.  
  298. Sub CheckForSystemTopic ()
  299. Dim i
  300.     If cboTopic.Text = "SYSTEM" Or cboTopic.Text = "PROGMAN" Then
  301.     FillSysItems
  302.     optLinkMode(1).Enabled = False
  303.     optLinkMode(3).Enabled = False
  304.     optLinkMode(2).Value = True
  305.     Else
  306.     For i = 1 To 3
  307.         optLinkMode(i).Enabled = True
  308.     Next
  309.     cboItem.Clear
  310.     cboItem.Text = ""
  311.     If cboAppName.Text = "WINWORD" Then
  312.         cboItem.AddItem "\Doc"
  313.         cboItem.Text = "\Doc"
  314.         cboItem.Refresh
  315.     End If
  316.     End If
  317. End Sub
  318.  
  319. Sub chkSourceMode_Click ()
  320.     LinkMode = Abs(chkSourceMode.Value)
  321.     txtSourceTopic.Enabled = chkSourceMode.Value
  322. End Sub
  323.  
  324. Sub cmdConnect_Click ()
  325. Dim clientLinkMode As Integer
  326.     If Not Connected Then
  327.     For clientLinkMode = 1 To 3
  328.         If optLinkMode(clientLinkMode).Value Then Exit For
  329.     Next
  330.     picData.Picture = LoadPicture()
  331.     txtData.Text = ""
  332.     Select Case MakeConnection(clientLinkMode)
  333.         Case 0
  334.         ConnectState True
  335.         Case NO_APP_RESPONDED
  336.         If MsgBox("Hey! " & cboAppName.Text & " doesn't seem to be running. Should I start it?", MB_YESNO + MB_ICONQUESTION) = IDYES Then
  337.             If StartApp((cboAppName.Text)) Then
  338.             Select Case MakeConnection(clientLinkMode)
  339.                 Case 0
  340.                 ConnectState True
  341.                 Case NO_APP_RESPONDED
  342.                 MsgBox "Sorry, still can't connect."
  343.             End Select
  344.             End If
  345.         End If
  346.     End Select
  347.     Else
  348.     Disconnect txtData
  349.     Disconnect picData
  350.     ConnectState False
  351.     End If
  352. End Sub
  353.  
  354. Sub CmdExecute_Click ()
  355.     ' Empty combo box on Execute form
  356.     ' (This also implictly loads the form if it was unloaded).
  357.     frmExecute.cboExecuteString.Clear
  358.  
  359.     ' Load sample execute strings appropriate to the source application
  360.     Select Case cboAppName.Text
  361.     Case "ProgMan"
  362.         frmExecute.cboExecuteString.AddItem "[CreateGroup(DDE Group)]"
  363.         frmExecute.cboExecuteString.AddItem "[AddItem(C:\VB\SAMPLES\DDE.EXE, Visual Basic DDE App)]"
  364.         frmExecute.cboExecuteString.AddItem "[ShowGroup(DDE Group, 7)]"
  365.     Case "Excel"
  366.         frmExecute.cboExecuteString.AddItem "[SELECT(" & Chr(34) & "R1:R16384" & Chr(34) & ")]"
  367.         frmExecute.cboExecuteString.AddItem "[NEW(2,2)]"
  368.         frmExecute.cboExecuteString.AddItem "[GALLERY.3D.PIE(4)]"
  369.         frmExecute.cboExecuteString.AddItem "[CLOSE()]"
  370.     Case "WinWord"
  371.         frmExecute.cboExecuteString.AddItem "[StartOfLine][EndOfLine 1]"
  372.         frmExecute.cboExecuteString.AddItem "[InsertBookmark .Name = " & Chr(34) & "DDE1" & Chr(34) & "]"
  373.         frmExecute.cboExecuteString.AddItem "[LineDown 1]"
  374.     End Select
  375.  
  376.     frmExecute.Show MODAL
  377.  
  378. End Sub
  379.  
  380. Sub cmdExit_Click ()
  381.     Unload frmMain
  382.     End
  383. End Sub
  384.  
  385. Sub cmdPoke_Click ()
  386. On Error Resume Next
  387.     txtData.LinkPoke
  388.     If Err Then MsgBox Error
  389. End Sub
  390.  
  391. Sub cmdRequest_Click ()
  392. On Error Resume Next
  393.     txtData.LinkRequest
  394.     picData.LinkRequest
  395.     NotifyFlag = False
  396. End Sub
  397.  
  398. Sub ConnectState (State As Integer)
  399. Dim i As Integer
  400.  
  401.     If State Then
  402.     cmdConnect.Caption = "Disconnect"
  403.     Else
  404.     cmdConnect.Caption = "Connect"
  405.     End If
  406.     
  407.     Connected = State
  408.     cmdRequest.Enabled = State
  409.     cmdPoke.Enabled = (optLinkMode(LINK_MANUAL).Value And State)
  410.     cmdExecute.Enabled = State
  411.  
  412.     'cboAppName.Enabled = Not State
  413.     'cboTopic.Enabled = Not State
  414. End Sub
  415.  
  416. Function CreateLink (Ctl As Control, appname As String, topic As String, item As String, LinkType As Integer) As Integer
  417. On Error Resume Next
  418.     Ctl.LinkMode = NONE
  419.     Ctl.LinkTopic = appname & "|" & topic
  420.     Ctl.LinkItem = item
  421.     Ctl.LinkMode = LinkType
  422.     CreateLink = Err
  423.     If Err = 0 And LinkType <> LINK_AUTOMATIC Then
  424.     Ctl.LinkRequest
  425.     End If
  426. End Function
  427.  
  428. Sub Disconnect (Ctl As Control)
  429. Dim tempTimeOutVal
  430. On Error Resume Next    ' Disconnecting with ProgMan causes timeout error: just eat it and go on.
  431.     tempTimeOutVal = Ctl.LinkTimeout
  432.     Ctl.LinkTimeout = 1
  433.     Ctl.LinkMode = NONE
  434.     Ctl.LinkTimeout = tempTimeOutVal
  435. End Sub
  436.  
  437. Sub FillList (cbo As Control, lbl As Control)
  438. Dim i As Integer, lasti As Integer
  439.     Do
  440.     i = i + 1
  441.     lasti = i
  442.     i = InStr(lasti, lbl.Caption, Chr(9))
  443.     If i = 0 Then
  444.         cbo.AddItem Mid(lbl.Caption, lasti)
  445.         Exit Do
  446.     Else
  447.         cbo.AddItem Mid(lbl.Caption, lasti, i - lasti)
  448.     End If
  449.     Loop
  450. End Sub
  451.  
  452. Sub FillSysItems ()
  453.     cboItem.Clear
  454.     Screen.MousePointer = HOURGLASS
  455.     lblSysLink.LinkMode = NONE
  456.     lblSysLink.LinkTopic = cboAppName.Text & "|" & "System"
  457.     lblSysLink.LinkItem = "SysItems"
  458.     On Error Resume Next
  459.     lblSysLink.LinkMode = LINK_MANUAL
  460.     If Err = 0 Then
  461.     lblSysLink.LinkRequest
  462.     FillList cboItem, lblSysLink
  463.     cboItem.Text = "SysItems"
  464.     End If
  465.     cboItem.Refresh
  466.     Screen.MousePointer = DEFAULT
  467. End Sub
  468.  
  469. Sub FillTopicList ()
  470.     cboTopic.Clear
  471.     cboTopic.Text = ""
  472.     If cboAppName.Text = "ProgMan" Then
  473.     cboTopic.Text = "ProgMan"
  474.     Else
  475.     Screen.MousePointer = HOURGLASS
  476.     lblSysLink.LinkMode = NONE
  477.     lblSysLink.LinkTopic = cboAppName.Text & "|" & "System"
  478.     lblSysLink.LinkItem = "Topics"
  479.     On Error Resume Next
  480.     lblSysLink.LinkMode = LINK_MANUAL
  481.     If Err Then
  482.         cboTopic.AddItem "System"
  483.     Else
  484.         lblSysLink.LinkRequest
  485.         FillList cboTopic, lblSysLink
  486.         cboTopic.Text = "System"
  487.     End If
  488.     Screen.MousePointer = DEFAULT
  489.     End If
  490.     cboTopic.Refresh
  491. End Sub
  492.  
  493. Sub Form_Load ()
  494.     cboAppName.AddItem "ProgMan"
  495.     cboAppName.AddItem "DDE"
  496.     cboAppName.AddItem "Excel"
  497.     cboAppName.AddItem "WinWord"
  498.     cboAppName.AddItem "FoxPro"
  499.     cboAppName.AddItem "Access"
  500.     cboAppName.AddItem "Project"
  501.  
  502.     LinkTopic = txtSourceTopic.Text
  503.     Topics.Caption = "Topics" & Chr(9) & "picData" & Chr(9) & "txtData" & Chr(13) & Chr(10)
  504. End Sub
  505.  
  506. Sub Form_Unload (Cancel As Integer)
  507.     Disconnect txtData
  508.     Disconnect picData
  509. End Sub
  510.  
  511. Function MakeConnection (clientLinkMode As Integer) As Integer
  512. Dim ConnectTxt As Integer, ConnectPic As Integer
  513.     ConnectPic = CreateLink(picData, (cboAppName.Text), (cboTopic.Text), (cboItem.Text), clientLinkMode)
  514.     ConnectTxt = CreateLink(txtData, (cboAppName.Text), (cboTopic.Text), (cboItem.Text), clientLinkMode)
  515.     
  516.     If ConnectPic = NO_APP_RESPONDED And ConnectTxt = NO_APP_RESPONDED Then
  517.     MakeConnection = NO_APP_RESPONDED
  518.     ElseIf ConnectTxt = 0 Then
  519.     MakeConnection = 0
  520.     optDataType(DEST_TEXT).Value = True
  521.     ElseIf ConnectPic = 0 Then
  522.     MakeConnection = 0
  523.     optDataType(DEST_PIC).Value = True
  524.     Else
  525.     MakeConnection = ConnectPic
  526.     End If
  527. End Function
  528.  
  529. Sub optDataType_Click (Index As Integer)
  530.     If Index = DEST_TEXT Then
  531.     txtData.Visible = True
  532.     picData.Visible = False
  533.     ElseIf Index = DEST_PIC Then
  534.     txtData.Visible = False
  535.     picData.Visible = True
  536.     End If
  537. End Sub
  538.  
  539. Sub optLinkMode_Click (Index As Integer)
  540.     If Connected Then
  541.     cmdConnect.Value = True
  542.     cmdConnect.Value = True
  543.     End If
  544. End Sub
  545.  
  546. Sub picData_LinkClose ()
  547.     ConnectState False
  548. End Sub
  549.  
  550. Sub picData_LinkNotify ()
  551.     If Not NotifyFlag Then
  552.     MsgBox "New data is available from the DDE Source.  Choose Request to update."
  553.     NotifyFlag = True
  554.     End If
  555. End Sub
  556.  
  557. Sub picData_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  558.     If Button And 1 Then
  559.     PSet (X, Y)
  560.     Else
  561.     picData.ForeColor = QBColor(Rnd * 16)
  562.     End If
  563. End Sub
  564.  
  565. Sub picData_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  566.     If Button And 1 Then picData.Line -(X, Y)
  567. End Sub
  568.  
  569. Sub picData_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  570.     If Button And 1 Then
  571.     picData.LinkSend
  572.     End If
  573. End Sub
  574.  
  575. Function StartApp (appname As String) As Integer
  576. On Error Resume Next
  577.     StartApp = (Shell(appname) > 31)
  578.     If Err Then MsgBox "Couldn't start " & appname
  579.     StartApp = 0
  580. End Function
  581.  
  582. Sub txtData_LinkClose ()
  583.     ConnectState False
  584. End Sub
  585.  
  586. Sub txtData_LinkNotify ()
  587.     If Not NotifyFlag Then
  588.     MsgBox "New data is available from the DDE Source.  Choose Request to update."
  589.     NotifyFlag = True
  590.     End If
  591. End Sub
  592.  
  593. Sub txtSourceTopic_Change ()
  594.     LinkTopic = txtSourceTopic.Text
  595. End Sub
  596.  
  597.