|
-
Sep 13th, 2000, 05:46 PM
#1
Thread Starter
Lively Member
Hi:
I know that with app.previnstance I can detect if my application it's runnig but how can I maximize the application if it's minimize and running and I try to run again?
Thanks in advance
Regards.
Angel Maldonado López.
VB Programmer
-
Sep 13th, 2000, 06:07 PM
#2
Try this:
Code:
Option Explicit
Public Const GW_HWNDPREV = 3
Declare Function OpenIcon Lib "User32" (ByVal hWnd As Long) As Long
Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal _
nCmdShow 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" Alias "GetWindow" (ByVal hWnd As Long, ByVal _
wCmd As Long) As Long
Declare Function SetForegroundWindow Lib "User32" (ByVal hWnd As Long) As _
Long
Public Const SW_MAXIMIZE = 3
Sub ActivatePrevInstance()
Dim OldTitle As String
Dim PrevHndl As Long
Dim result As Long
Dim maxWin As Long
'Save the title of the application.
OldTitle = App.Title
'Rename the title of this application so FindWindow
'will not find this application instance.
App.Title = "unwanted instance"
'Attempt to get window handle using VB4 class name.
PrevHndl = FindWindow("ThunderRTMain", OldTitle)
'Check for no success.
If PrevHndl = 0 Then
'Attempt to get window handle using VB5 class name.
PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
End If
'Check if found
If PrevHndl = 0 Then
'Attempt to get window handle using VB6 class name
PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
End If
'Check if found
If PrevHndl = 0 Then
'No previous instance found.
Exit Sub
End If
'Get handle to previous window.
PrevHndl = getwindow(PrevHndl, GW_HWNDPREV)
'Restore the program.
result = OpenIcon(PrevHndl)
'Activate the application.
result = SetForegroundWindow(PrevHndl)
'Maximize Window
maxWin = ShowWindow(PrevHndl, SW_MAXIMIZE)
'End the application.
End
End Sub
Private Sub Form_Load()
If App.PrevInstance Then
ActivatePrevInstance
End If
End Sub
-
Sep 13th, 2000, 06:40 PM
#3
Be careful on this one. When testing it in the IDE, the ClassName is ThunderForm.
-
Sep 13th, 2000, 06:56 PM
#4
Thread Starter
Lively Member
Hi Matt:
It works perfectly, thanks a lot
Regards.
Angel Maldonado López.
VB Programmer
-
Sep 13th, 2000, 07:17 PM
#5
AM LOPEZ, curious: what version of VB are you using?
-
Sep 13th, 2000, 08:44 PM
#6
Thread Starter
Lively Member
Angel Maldonado López.
VB Programmer
-
Sep 13th, 2000, 08:51 PM
#7
Oh yeah, I see how it works for all VB versions.
Code:
'Attempt to get window handle using VB4 class name.
PrevHndl = FindWindow("ThunderRTMain", OldTitle)
'Check for no success.
If PrevHndl = 0 Then
'Attempt to get window handle using VB5 class name.
PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
End If
'Check if found
If PrevHndl = 0 Then
'Attempt to get window handle using VB6 class name
PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
End If
Did not see that, I only saw Visual Basic 4.0. Well, as long as it works, than that's good .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|