dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 8, 1997

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Activating a Previous Instance of an Application

To prevent users from launching multiple instances of your application, check the PrevInstance property of VB's App object; if the property is True, the program is already running. To activate the previous instance, call Windows' FindWindow, ShowWindow, and SetFocus APIs:

 
Global Const SW_RESTORE=9
Declare Function FindWindow Lib "User" _ 
        (ByVal lpClassName As Any, ByVal _
        lbWindowName As Any) As Integer
Declare Function ShowWindow Lib "User" _ 
        (ByVal hWnd As Integer, ByVal _
        nCmdShow As Integer) As Integer
Declare Function SetFocusAPI Lib _
        "User" Alias "SetFocus" (ByVal _
        hWnd As Integer) As Integer

Sub Main ()

        Dim hWnd As Integer
        Dim iResult As Integer

        ' App object's Title property may be 
        ' set at runtime, as illustrated 
        ' here, or at compile time in VB's 
        ' Make .EXE' dialog.
        App.Title = "Test Application"

        If App.PrevInstance Then

                ' ThunderForm is the class name 
                ' for VB forms (Thunder was the 
                ' original code name for Visual 
                ' Basic within 'Microsoft)

                ' Find the existing instance
                hWnd = FindWindow("Thunder_
                        Form", App.Title)

                ' FindWindow function returns a 
                ' non-zero value if it finds a 
                matching window 
                If hWnd <> 0 Then
                        ' Restore window if minimized
                        iResult = ShowWindow(hWnd,
                                SW_RESTORE)
' Set focus to the specified window
                        iResult = SetFocusAPI(hWnd)
                        ' Close this instance
                        End
                End If
        End If

        ' If no previous instance, show
        ' main form and proceed normally.
        frmMain.Show

End Sub



Senthil Shanmugham
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date