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 / articles / vbbultn / source / coop1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-04-06  |  6.0 KB  |  194 lines

  1. VERSION 2.00
  2. Begin Form Coop1 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Coop1"
  6.    ClientHeight    =   1785
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1485
  9.    ClientWidth     =   4845
  10.    Height          =   2190
  11.    Left            =   1035
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   1785
  14.    ScaleWidth      =   4845
  15.    Top             =   1140
  16.    Width           =   4965
  17.    Begin CommandButton ExitBut 
  18.       Caption         =   "Exit"
  19.       Height          =   465
  20.       Left            =   3180
  21.       TabIndex        =   6
  22.       Top             =   1200
  23.       Width           =   1605
  24.    End
  25.    Begin TextBox TotalText 
  26.       Height          =   315
  27.       Left            =   870
  28.       MaxLength       =   12
  29.       TabIndex        =   5
  30.       Text            =   "144.64"
  31.       Top             =   1290
  32.       Width           =   1245
  33.    End
  34.    Begin TextBox AmountText 
  35.       Height          =   315
  36.       Left            =   870
  37.       MaxLength       =   12
  38.       TabIndex        =   4
  39.       Text            =   "$5"
  40.       Top             =   900
  41.       Width           =   1245
  42.    End
  43.    Begin TextBox CountText 
  44.       Height          =   315
  45.       Left            =   870
  46.       MaxLength       =   4
  47.       TabIndex        =   3
  48.       Text            =   "129"
  49.       Top             =   510
  50.       Width           =   1245
  51.    End
  52.    Begin TextBox CompanyText 
  53.       Height          =   315
  54.       Left            =   870
  55.       MaxLength       =   24
  56.       TabIndex        =   2
  57.       Text            =   "Desaware SpyWorks-VB"
  58.       Top             =   120
  59.       Width           =   2265
  60.    End
  61.    Begin CommandButton SendMessBut 
  62.       Caption         =   "Send Message"
  63.       Height          =   465
  64.       Left            =   3180
  65.       TabIndex        =   1
  66.       Top             =   660
  67.       Width           =   1605
  68.    End
  69.    Begin CommandButton LaunchBut 
  70.       Caption         =   "Launch New App"
  71.       Height          =   465
  72.       Left            =   3180
  73.       TabIndex        =   0
  74.       Top             =   120
  75.       Width           =   1605
  76.    End
  77.    Begin ccCallback Callback1 
  78.       IntVersion      =   5
  79.       Left            =   2550
  80.       Top             =   1140
  81.       Type            =   6  'EnumWindows
  82.    End
  83.    Begin Label Label1 
  84.       Alignment       =   1  'Right Justify
  85.       BackColor       =   &H00C0C0C0&
  86.       Caption         =   "Single"
  87.       Height          =   255
  88.       Index           =   3
  89.       Left            =   120
  90.       TabIndex        =   10
  91.       Top             =   1320
  92.       Width           =   705
  93.    End
  94.    Begin Label Label1 
  95.       Alignment       =   1  'Right Justify
  96.       BackColor       =   &H00C0C0C0&
  97.       Caption         =   "Currency"
  98.       Height          =   255
  99.       Index           =   2
  100.       Left            =   60
  101.       TabIndex        =   9
  102.       Top             =   930
  103.       Width           =   765
  104.    End
  105.    Begin Label Label1 
  106.       Alignment       =   1  'Right Justify
  107.       BackColor       =   &H00C0C0C0&
  108.       Caption         =   "Integer"
  109.       Height          =   255
  110.       Index           =   1
  111.       Left            =   120
  112.       TabIndex        =   8
  113.       Top             =   540
  114.       Width           =   705
  115.    End
  116.    Begin Label Label1 
  117.       Alignment       =   1  'Right Justify
  118.       BackColor       =   &H00C0C0C0&
  119.       Caption         =   "String"
  120.       Height          =   255
  121.       Index           =   0
  122.       Left            =   150
  123.       TabIndex        =   7
  124.       Top             =   150
  125.       Width           =   675
  126.    End
  127. Option Explicit
  128. Dim NewShellApp As Integer
  129. Dim OtherAppMainWindowHwnd As Integer
  130. Dim PrivateCoopMessage As Integer
  131. Sub Callback1_EnumWindows (hWnd As Integer, lpData As Long, retval As Integer)
  132. Dim thismod As Integer, res As Integer
  133. Dim classname As String
  134.     ' Check if this window belongs to the new instance we launched
  135.     thismod = GetWindowWord(hWnd, GWW_HINSTANCE)
  136.     ' The default return value is already TRUE to continue enumeration
  137.     If thismod <> NewShellApp Then Exit Sub
  138.     classname = String$(32, 0)
  139.     res = GetClassName(hWnd, classname, Len(classname) + 1)
  140.     classname = Left$(classname, InStr(1, classname, Chr$(0)) - 1)
  141.     If classname = THUNDERRTMAIN Then Exit Sub
  142.     ' Stop the enumeration once we find the window
  143.     retval = 0
  144.     OtherAppMainWindowHwnd = hWnd
  145. End Sub
  146. Sub ExitBut_Click ()
  147.     Unload Me
  148. End Sub
  149. Sub Form_Load ()
  150.     PrivateCoopMessage = RegisterWindowMessage(COOP_MESSAGE)
  151. End Sub
  152. Sub LaunchBut_Click ()
  153. Dim res As Integer
  154.     NewShellApp = Shell(App.Path & "\COOP2.EXE", 1)
  155.     ' If Shell was successful then
  156.     If NewShellApp Then
  157.         ' Get the top level window handle of the newly launched application
  158.         res = EnumWindows(Callback1.ProcAddress, 0)
  159.     End If
  160. End Sub
  161. Sub SendMessBut_Click ()
  162. Dim cs As CoopStructure
  163. Dim lp As Long, lres As Long
  164.     If PrivateCoopMessage Then
  165.         ' Note that the Max length of CompanyText is
  166.         ' set to the size of the CompanyName element.
  167.         ' The other Text controls also have limited Max
  168.         ' length to prevent overflow.
  169.         cs.CompanyName = CompanyText.Text
  170.         ' Prevent invalid data type
  171.         On Error GoTo InvalidCount
  172.         cs.Count = CInt(CountText.Text)
  173.         On Error GoTo InvalidAmount
  174.         cs.Amount = CCur(AmountText.Text)
  175.         On Error GoTo InvalidTotal
  176.         cs.Total = CSng(TotalText.Text)
  177.         ' Turn off error checking
  178.         On Error GoTo 0
  179.         ' Get address of the structure and send it to the other application.
  180.         lp = dwGetAddressForObject(cs)
  181.         lres = SendMessageBynum(OtherAppMainWindowHwnd, PrivateCoopMessage, 0, lp)
  182.     End If
  183.     Exit Sub
  184. InvalidCount:
  185.     cs.Count = 0
  186.     Resume Next
  187. InvalidAmount:
  188.     cs.Amount = 0
  189.     Resume Next
  190. InvalidTotal:
  191.     cs.Total = 0
  192.     Resume Next
  193. End Sub
  194.