Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • *Experts*
Posted
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.
Posted
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.
  • *Experts*
Posted

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.

  • Leaders
Posted

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...