home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch12 / singlapp / singlapp.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  1.4 KB  |  43 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2130
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4620
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   2130
  10.    ScaleWidth      =   4620
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.Label Label1 
  13.       Caption         =   "Only one instance of this program can run."
  14.       Height          =   735
  15.       Left            =   360
  16.       TabIndex        =   0
  17.       Top             =   720
  18.       Width           =   3615
  19.    End
  20. Attribute VB_Name = "Form1"
  21. Attribute VB_GlobalNameSpace = False
  22. Attribute VB_Creatable = False
  23. Attribute VB_PredeclaredId = True
  24. Attribute VB_Exposed = False
  25. Option Explicit
  26. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  27.     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  28. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
  29.     ByVal nCmdShow As Long) As Long
  30. Const SW_SHOWNORMAL = 1
  31. Private Sub Form_Load()
  32.     Dim retValue As Long
  33.     Dim otherWnd As Long
  34.     Dim oldCaption As String
  35.     If App.PrevInstance Then
  36.         MsgBox "Cannot start more than one copy."
  37.         Unload Me
  38.         
  39.         otherWnd = FindWindow(0&, oldCaption)
  40.         retValue = ShowWindow(App.hInstance, SW_SHOWNORMAL)
  41.     End If
  42. End Sub
  43.