home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap17 / addin4.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-10-09  |  3.2 KB  |  98 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5205
  5.    ClientLeft      =   3735
  6.    ClientTop       =   5790
  7.    ClientWidth     =   6690
  8.    Height          =   5640
  9.    Left            =   3675
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5205
  12.    ScaleWidth      =   6690
  13.    Top             =   5415
  14.    Width           =   6810
  15.    Begin VB.CommandButton Command2 
  16.       Caption         =   "Command2"
  17.       Height          =   495
  18.       Left            =   2760
  19.       TabIndex        =   1
  20.       Top             =   1800
  21.       Width           =   1215
  22.    End
  23.    Begin VB.CommandButton Command1 
  24.       Caption         =   "Command1"
  25.       Height          =   495
  26.       Left            =   2760
  27.       TabIndex        =   0
  28.       Top             =   2400
  29.       Width           =   1215
  30.    End
  31. Attribute VB_Name = "Form1"
  32. Attribute VB_Creatable = False
  33. Attribute VB_Exposed = False
  34. Option Explicit
  35. 'Public thisInstance As VBIDE.Application
  36. ' Declarations for the API functions used to manipulate
  37. ' initilization files.
  38. Private Declare Function WritePrivateProfileString _
  39.     Lib "Kernel32" Alias "WritePrivateProfileStringA" _
  40.     (ByVal AppName$, ByVal KeyName As Any, _
  41.     ByVal KeyDefault As Any, ByVal FileName$) As Long
  42. Private Declare Function GetPrivateProfileString Lib _
  43.     "Kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName$, _
  44.     ByVal KeyName$, ByVal KeyDefault$, ByVal ReturnString$, _
  45.     ByVal NumBytes As Long, ByVal FileName$) As Long
  46. ' This method adds a profile string to the VB.INI file. The
  47. ' instance of VB that is started will see it.
  48. Private Sub Command1_Click()
  49.     Dim prof As String
  50.     prof = String$(255, Chr$(0))
  51.     ' If profile string is not present, return "NotFound" as the
  52.     ' result.
  53.     GetPrivateProfileString "Add-Ins32", "AddIn4.Connector", _
  54.         "NotFound", prof, Len(prof) + 1, "VB.INI"
  55.     ' get rid of trailing blanks.
  56.     prof = Left(prof, InStr(prof, Chr(0)) - 1)
  57.     If prof = "NotFound" Then
  58.         WritePrivateProfileString "Add-Ins32", _
  59.             "AddIn4.Connector", "0", "VB.INI"
  60.     End If
  61.     ' Change the directory in the next line to reflect the
  62.     ' the directory in which Visual Basic is installed, if the shell
  63.     ' fails
  64.     Shell "vb32.exe", vbNormalFocus
  65. End Sub
  66. Private Sub Command2_Click()
  67.     Unload Form1
  68. End Sub
  69. ' Perform some control initialization.
  70. Private Sub Form_Load()
  71.     With Screen
  72.         Left = (.Width - Width) / 2
  73.         Top = (.Height - Height) / 2
  74.     End With
  75.         
  76.     With Command1
  77.         .Caption = "Start Add-In"
  78.         .Left = 40
  79.         .Top = 15
  80.     End With
  81.     With Command2
  82.         .Left = Command1.Left
  83.         .Top = Command1.Top + Command1.Height + 15
  84.         .Caption = "End Add-In"
  85.     End With
  86.     With Form1
  87.         .Height = (Command1.Height * 3)
  88.         .Width = Command1.Width
  89.     End With
  90. End Sub
  91. ' Remove the profile string so that new instances
  92. ' of VB will not look for it.
  93. Private Sub Form_Unload(Cancel As Integer)
  94.     WritePrivateProfileString "Add-Ins32", _
  95.         "AddIn4.Connector", "", "VB.INI"
  96.     End
  97. End Sub
  98.