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