|
-
Nov 8th, 2006, 08:13 PM
#1
Thread Starter
Lively Member
[RESOLVED] set focus
i have a program and when i click a button in the program i want ti to set focus on another process i have runing. the other process is running in windowed mode how can i do this?
-
Nov 8th, 2006, 08:17 PM
#2
Re: set focus
The easy way is to use the AppActivate function. The alternative is to use a Process object to get the handle to the other app's main window, then call the SetForegroundWindow API function. Some consider it poor form to use Runtime functions like AppActivate, and I'm one of them, but I'd consider that preferable to resorting to API calls. The difference is that AppActivate will not restore the application window if it's minimised, whereas you can test for that and restore it using API functions, although it requires more than just SetForegroundWindow.
-
Nov 8th, 2006, 08:22 PM
#3
Re: set focus
You can test for the app being minimized by using the IsIconic API.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 8th, 2006, 08:29 PM
#4
Thread Starter
Lively Member
Re: set focus
Ok i used AppActivate and it works just fine for what i need. I dont need to restore the process if it has been minimized. Here is the code i used incase anyone else is wondering how to do it this way.
VB Code:
Dim proc As Process
Dim h As Integer
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
proc = Process.GetProcessesByName("myprocess")(0)' the process to set focus too must be started before this code is run
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
AppActivate(proc.Id)'sets focus to the process
End Sub
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
|