home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / boxes / demo2 / frmmain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-04-19  |  4.6 KB  |  131 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Another demo from Steven Gotz"
  5.    ClientHeight    =   480
  6.    ClientLeft      =   2415
  7.    ClientTop       =   2010
  8.    ClientWidth     =   4140
  9.    Height          =   1170
  10.    Icon            =   FRMMAIN.FRX:0000
  11.    Left            =   2355
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   480
  15.    ScaleWidth      =   4140
  16.    Top             =   1380
  17.    Width           =   4260
  18.    Begin CommandButton Command1 
  19.       Caption         =   "Command1"
  20.       Height          =   495
  21.       Index           =   0
  22.       Left            =   0
  23.       TabIndex        =   0
  24.       Top             =   0
  25.       Width           =   1400
  26.    End
  27.    Begin CommandButton Command1 
  28.       Caption         =   "Command1"
  29.       Height          =   495
  30.       Index           =   2
  31.       Left            =   2775
  32.       TabIndex        =   2
  33.       Top             =   0
  34.       Width           =   1400
  35.    End
  36.    Begin CommandButton Command1 
  37.       Caption         =   "Command1"
  38.       Height          =   495
  39.       Index           =   1
  40.       Left            =   1400
  41.       TabIndex        =   1
  42.       Top             =   0
  43.       Width           =   1400
  44.    End
  45.    Begin Menu mnuFile 
  46.       Caption         =   "&File"
  47.       Begin Menu mnuExit 
  48.          Caption         =   "E&xit"
  49.       End
  50.    End
  51.    Begin Menu mnuEdit 
  52.       Caption         =   "&Edit"
  53.       Begin Menu mnuEditIni 
  54.          Caption         =   "E&dit INI File"
  55.       End
  56.    End
  57.    Begin Menu mnuHelp 
  58.       Caption         =   "&Help"
  59.       Begin Menu mnuHelpFile 
  60.          Caption         =   "&Help"
  61.       End
  62.       Begin Menu mnuAbout 
  63.          Caption         =   "&About"
  64.       End
  65.    End
  66. 'See .BAS files
  67. Sub Command1_Click (index As Integer)
  68. Static hWnds() As Integer
  69. x% = index 'it is easier to type x% than index
  70. 'Figure out which line to read - Button1, Button2 etc.
  71. ButtonIndex$ = "Button" & LTrim(Str$(x% + 1))
  72. 'Read the INI file for the Application name (i.e. calc.exe) and Window Title
  73. 'Be careful - I only allowed for one possible window with the same
  74. 'general title - use the wildcard wisely
  75. AppName$ = ReadINIFile("Applications", ButtonIndex$, IniName)
  76. Title$ = ReadINIFile("Title", ButtonIndex$, IniName)
  77.       ' Find window with Window title retrieved from the INI file
  78.        Handle% = FindWindowLike(hWnds(), 0, Title$, "*", Null)
  79.        
  80.     If Handle% = 0 Then             'if App is not running
  81.     x% = Shell(AppName$, 1)     'shell by using Application name
  82.     Else                            'if App is running
  83.     'Get the length of task name identified by hWnds(1)
  84.      Length = GetWindowTextLength(hWnds(1))
  85.      'Get task name of the task in the master list.
  86.      ListItem$ = Space$(Length + 1)   'make room first
  87.      Length = GetWindowText(hWnds(1), ListItem$, Length + 1)
  88.     AppActivate ListItem$        'Activate the App.
  89.     SendKeys "%{ }r", True       'To restore App.
  90.     End If
  91. End Sub
  92. Sub Form_Load ()
  93. 'Declare the name of the INI file for use in all INI functions
  94. 'since it is easier to do it only once
  95. IniName = "progstrt.ini"
  96. 'Put the Help menu item on the right
  97. 'Not recommended by Microsoft but I like it
  98. mnuHelp.Caption = Chr$(8) + mnuHelp.Caption
  99. 'Read the captions for the buttons out of the progstrt.ini file
  100. 'and assign to the caption property  - see INIFILES.BAS
  101. For x% = 0 To 2
  102.     ButtonIndex$ = "Button" & LTrim(Str$(x% + 1))
  103.     command1(x%).Caption = ReadINIFile("Buttons", ButtonIndex$, IniName)
  104. Next x%
  105. End Sub
  106. Sub mnuAbout_Click ()
  107. 'The Icon will be taken from the application.
  108. 'This is really quite easy to use.
  109. 'I use this very program as a starter for almost
  110. 'all of my apps now.  Modify the DisplayAboutBox line
  111. 'and change the MyInfoLabel label caption and
  112. 'the label1 caption and you should be in business.
  113. '                         Application                     ver,   year    company        verbose appname                  date
  114. DisplayAboutBox frmMain, "The Start Other Programs Demo", 1.01, "1995", "Steven Gotz", "Another Demo from Steven Gotz", "Apr 14, 1995", 0, True, 0, &HC0C0C0
  115. End Sub
  116. Sub mnuEditIni_Click ()
  117. IniFileBeginStr$ = GetWindowsDir()
  118. NotepadAndIniFileNameWithPath$ = "Notepad.exe " & IniFileBeginStr$ & IniName
  119. x% = DOShell(NotepadAndIniFileNameWithPath$, 3)
  120. For x% = 0 To 2
  121.     ButtonIndex$ = "Button" & LTrim(Str$(x% + 1))
  122.     command1(x%).Caption = ReadINIFile("Buttons", ButtonIndex$, IniName)
  123. Next x%
  124. End Sub
  125. Sub mnuExit_Click ()
  126. Unload frmMain
  127. End Sub
  128. Sub mnuHelpFile_Click ()
  129. x% = Shell("winhelp.exe demo2.hlp", 3)
  130. End Sub
  131.