leontager Posted August 5, 2003 Posted August 5, 2003 how do I set the focus on a window from .net Private Sub Button1_Click(ByVal sender As System. _ Object, ByVal e As System.EventArgs) Handles Button1.Click Dim wWindow As Long wWindow = FindWindow(vbNullString, "Untitled - Notepad") SetFocus(wWindow) End Sub shoudn't this work? Quote
*Experts* Volte Posted August 5, 2003 *Experts* Posted August 5, 2003 Did you check to make sure it actually found that Window? Before you SetFocus(), look at the value of wWindow. Remember, if you're searching on window caption, the text has to be exactly the same. I would recommend that you leave the second parameter (the window caption) as Nothing and specify the first parameter (the window class) as Notepad, since that is the Notepad window's class. Quote
leontager Posted August 5, 2003 Author Posted August 5, 2003 well actually I was just testing the code. What class would I use for internet explorer? also, I did check the value of wWindow and I got some long number. I think it started with a 4. Quote
*Experts* Volte Posted August 5, 2003 *Experts* Posted August 5, 2003 You might try using the [api]SetForegroundWindow[/api] API instead, or maybe the [api]SetActiveWindow[/api] API to focus it, instead of the SetFocus API.. Use "IEFrame" for Internet Explorer's class. Quote
leontager Posted August 5, 2003 Author Posted August 5, 2003 thank you. SetForegroundWindow works fine:D Quote
Leaders dynamic_sysop Posted August 6, 2003 Leaders Posted August 6, 2003 you could always do it without FindWindow , like this... Private Declare Function BringWindowToTop Lib "user32.dll" (ByVal hwnd As IntPtr) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim proc() As Process = Process.GetProcessesByName("Notepad") Dim x As Integer For x = LBound(proc) To UBound(proc) If proc(x).MainWindowTitle = "Untitled - Notepad" Then BringWindowToTop(proc(x).MainWindowHandle) End If Next End Sub Quote
Recommended Posts