home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap17 / addin4.frm < prev    next >
Text File  |  1995-10-09  |  3KB  |  115 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. End
  32. Attribute VB_Name = "Form1"
  33. Attribute VB_Creatable = False
  34. Attribute VB_Exposed = False
  35. Option Explicit
  36. 'Public thisInstance As VBIDE.Application
  37. ' Declarations for the API functions used to manipulate
  38. ' initilization files.
  39.  
  40. Private Declare Function WritePrivateProfileString _
  41.     Lib "Kernel32" Alias "WritePrivateProfileStringA" _
  42.     (ByVal AppName$, ByVal KeyName As Any, _
  43.     ByVal KeyDefault As Any, ByVal FileName$) As Long
  44.  
  45. Private Declare Function GetPrivateProfileString Lib _
  46.     "Kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName$, _
  47.     ByVal KeyName$, ByVal KeyDefault$, ByVal ReturnString$, _
  48.     ByVal NumBytes As Long, ByVal FileName$) As Long
  49.  
  50. ' This method adds a profile string to the VB.INI file. The
  51. ' instance of VB that is started will see it.
  52. Private Sub Command1_Click()
  53.     Dim prof As String
  54.     
  55.     prof = String$(255, Chr$(0))
  56.  
  57.     ' If profile string is not present, return "NotFound" as the
  58.     ' result.
  59.     GetPrivateProfileString "Add-Ins32", "AddIn4.Connector", _
  60.         "NotFound", prof, Len(prof) + 1, "VB.INI"
  61.  
  62.     ' get rid of trailing blanks.
  63.     prof = Left(prof, InStr(prof, Chr(0)) - 1)
  64.  
  65.     If prof = "NotFound" Then
  66.         WritePrivateProfileString "Add-Ins32", _
  67.             "AddIn4.Connector", "0", "VB.INI"
  68.     End If
  69.  
  70.     ' Change the directory in the next line to reflect the
  71.     ' the directory in which Visual Basic is installed, if the shell
  72.     ' fails
  73.     Shell "vb32.exe", vbNormalFocus
  74. End Sub
  75.  
  76. Private Sub Command2_Click()
  77.     Unload Form1
  78. End Sub
  79.  
  80. ' Perform some control initialization.
  81. Private Sub Form_Load()
  82.     With Screen
  83.         Left = (.Width - Width) / 2
  84.         Top = (.Height - Height) / 2
  85.     End With
  86.         
  87.     With Command1
  88.         .Caption = "Start Add-In"
  89.         .Left = 40
  90.         .Top = 15
  91.     End With
  92.     
  93.     With Command2
  94.         .Left = Command1.Left
  95.         .Top = Command1.Top + Command1.Height + 15
  96.         .Caption = "End Add-In"
  97.     End With
  98.     
  99.     With Form1
  100.         .Height = (Command1.Height * 3)
  101.         .Width = Command1.Width
  102.     End With
  103.  
  104. End Sub
  105.  
  106. ' Remove the profile string so that new instances
  107. ' of VB will not look for it.
  108. Private Sub Form_Unload(Cancel As Integer)
  109.     WritePrivateProfileString "Add-Ins32", _
  110.         "AddIn4.Connector", "", "VB.INI"
  111.     End
  112. End Sub
  113.  
  114.  
  115.