|
Активация ранее запущенной этой же программы |
|
|
Скопируйте код на форму. Скомпилируйте exe-файл. Запустите exe-программу, минимизируйте, снова запустите exe-программу. Смотрите, что получиться... Private Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As
Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd
As Long) As Long
Private Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long)
As Long
Const GW_HWNDPREV = 3
Private Sub ShowPrevInstance()
Dim OldTitle As String
Dim ll_WindowHandle As Long
'saving the current title in OldTitle variable
'and changing the application title
OldTitle = App.Title
App.Title = "abcba - This App Will Be Closed"
'finding the previous instance. if you are using VB 5.0,
'change "ThunderRT6Main" to "ThunderRT5Main"
ll_WindowHandle = FindWindow("ThunderRT6Main", OldTitle)
'if there is no old instances of your application - exit.
If ll_WindowHandle = 0 Then Exit Sub
'Find the window we need to restore
ll_WindowHandle = GetWindow(ll_WindowHandle, GW_HWNDPREV)
'Now restore it
Call OpenIcon(ll_WindowHandle)
'And Bring it to the foreground
Call SetForegroundWindow(ll_WindowHandle)
End
End Sub
Private Sub Form_Load()
If App.PrevInstance Then ShowPrevInstance
End Sub
|
|
|
|
|
|
|