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