|
-
January 28th, 2000, 12:59 AM
#1
~Focus~
From my program, how would I make another program the active window, such as Microsoft paint or notepad?
-
January 28th, 2000, 04:37 AM
#2
Re: ~Focus~
It depends on which version of Windows you are running. If you are running Windows95, or NT4 then you can use this code :
option Explicit
'
public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(byval hWnd1 as Long, byval hWnd2 as Long, byval lpsz1 as string, _
byval lpsz2 as string) as Long
public Declare Function SetForegroundWindow Lib "user32" _
(byval hwnd as Long) as Long
'
public Sub FindNotepad()
Dim lHwnd as Long
'
lHwnd = FindWindowEx(0, 0, "Notepad", vbNullString)
If lHwnd > 0 then
SetForegroundWindow lHwnd
End If
End Sub
- in a module.
If you use Win98 or Win2K, Microsoft have 'changed the rules' so that an application can't just jump to the front when it feels like it - although Karl Peterson has some excellent code to get around this problem at :
http://www.mvps.org/vb/index2.html?samples.htm - look for the ForceFore.zip sample - be warned though, it's quite heavy going if you don't know anything about the API.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
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
|