|
-
Oct 13th, 2001, 02:49 AM
#1
Thread Starter
Fanatic Member
How to setfocus on existing window
Hi,
I have an application runnig. i want only one instance of it on my system. So i check for the previous instance and then if exist i get the handle and then set that window as fore ground window .. But it is not working fine.. Can any body help me out..
i am sending the code..
Sub Main()
Dim handle As Long
Dim lng As Long
Dim SaveTitle As String
If (App.PrevInstance) Then
SaveTitle = App.Title
handle = FindWindow(0&, "My Application")
If handle = 0 Then
handle = FindWindow(0&, SaveTitle)
End If
lng = BringWindowToTop(handle)
lng = SetForegroundWindow(handle)
If lng = 0 Then
MsgBox "Previous instance not found ", vbInformation
End If
'Kill the Duplicate Instance of the Application in any case.
End
End If
frmMyapplication.Show
End Sub
Reply ASAP
Pradeep
-
Oct 13th, 2001, 04:04 AM
#2
Conquistador
1) Put all code inside [vbcode] [/vbcode] tags
2) Do you not have a form?
??
-
Oct 13th, 2001, 04:36 AM
#3
Thread Starter
Fanatic Member
its not workin
Its not working...
if you see the code i have sent you would find
BringWindowToTop(handle) which i have already used.. Bur i dont know why its not working....
pradeep
-
Oct 13th, 2001, 05:10 AM
#4
PowerPoster
-
Oct 13th, 2001, 11:24 AM
#5
Change your FindWindow line to match the following. Adding the classname will help narrow your search
Code:
'Use This line when you are running a compiled EXE
strClass = ThunderRT6Form
'Use this line if you are running within the IDE
strClass = ThunderForm
handle = FindWindow(strClass, "My Application")
-
Oct 14th, 2001, 01:48 AM
#6
Thread Starter
Fanatic Member
Thanks beachbum
beachbum
The link which you have mentioned is exactly what i wanted..
Thank you
Pradeep
-
Oct 14th, 2001, 02:31 AM
#7
Conquistador
Originally posted by Megatron
Change your FindWindow line to match the following. Adding the classname will help narrow your search
Code:
'Use This line when you are running a compiled EXE
strClass = ThunderRT6Form
'Use this line if you are running within the IDE
strClass = ThunderForm
handle = FindWindow(strClass, "My Application")
Is he even using a form?
-
Oct 14th, 2001, 02:51 AM
#8
Thread Starter
Fanatic Member
THANK YOU ALL
Thank you guys,
Every thing is workin fine... Thank you da_silvy... your code also works fine..
Thank you
Pradeep
-
Oct 14th, 2001, 05:03 AM
#9
Conquistador
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
|