Cegah Aplikasi Visual Basic Bisa Dijalankan Dua Kali

0 comments
Option Explicit

Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Public Const GW_HWNDPREV = 3

Sub ActivatePrevInstance()

    Dim AppTitle As String
    Dim PrevHndl As Long
    Dim result As Long

    AppTitle = App.Title
    App.Title = "unwanted instance"
    
    If PrevHndl = 0 Then
        PrevHndl = FindWindow("ThunderRT6Main", AppTitle)
        If PrevHndl <> 0 Then
                PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)
                result = OpenIcon(PrevHndl)
                result = SetForegroundWindow(PrevHndl)
                End
        End If
    End If
    
End Sub
Procedure dijalankan pada event Form_Load()
If App.PrevInstance Then ActivatePrevInstance



Related Post :



0 comments:

Post a Comment

 
VB Source Code | © 2011 Design by DheTemplate.com and Theme 2 Blog

Find more free Blogger templates at DheTemplate.com - Daily Updates Free Blogger Templates