hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article386.htm

Không rõ

Tránh nạp chương trình nhiều lần (VB)

Option Explicit

Private Sub Form_Load()

If App.PrevInstance Then

ActivatePrevInstance

End If

End Sub

' Thêm một module

' Paste đoạn code vào

Option Explicit

Public Const GW_HWNDPREV = 3

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

Sub ActivatePrevInstance()

Dim OldTitle As String

Dim PrevHndl As Long

Dim result As Long

OldTitle = App.Title

App.Title = unwanted instance

PrevHndl = FindWindow(ThunderRTMain, OldTitle)

If PrevHndl = 0 Then

PrevHndl = FindWindow(ThunderRT5Main, OldTitle)

End If

If PrevHndl = 0 Then

PrevHndl = FindWindow(ThunderRT6Main, OldTitle)

End If

If PrevHndl = 0 Then

Exit Sub

End If

PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)

result = OpenIcon(PrevHndl)

result = SetForegroundWindow(PrevHndl)

End

End Sub


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com