Results 1 to 5 of 5

Thread: [RESOLVED] Help Change a Title of Another Window

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    palo alto california
    Posts
    45

    Resolved [RESOLVED] Help Change a Title of Another Window

    Hi,

    I am trying to learn how to manipulate other opened windows from a VB.NET program. In this case I want to change the title of a particular IE window when/if it opens. That is a hotmail sign in account.
    The code works fine up to finding the correct window and I see it remove the title "Sign In - Microsoft Internet Explorer" but it just leaves it blank?

    Am I declaring something wrong . I mean HELP!!!


    VB Code:
    1. Public Class Form1
    2.  
    3.      Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    4.       Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    5.    
    6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.         Timer1.Interval = 1000
    8.         Timer1.Start()
    9.     End Sub
    10.  
    11.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    12.  
    13.         Dim name As String = "IEFrame"
    14.         Dim title As String = "Sign In - Microsoft Internet Explorer"
    15.         Dim handleofwindow As Long = FindWindow(name, title)
    16.         If handleofwindow <> 0 Then
    17.          
    18.             SetWindowText(handleofwindow, "What are you doing?")
    19.  
    20.         End If
    21.        
    22.  
    23.     End Sub
    24.  
    25.  
    26.  
    27. End Class

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Help Change a Title of Another Window

    In VB.Net Long variables from VB6 translate to Integer variables. Other than that I can't help


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Help Change a Title of Another Window

    Heres the correct .NET declarations:
    VB Code:
    1. Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    2.      ByVal lpClassName As String, _
    3.      ByVal lpWindowName As String) As Int32
    4. Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" ( _
    5.      ByVal hwnd As Int32, _
    6.      ByVal lpString As String) As Int32
    If you still can't seem to get SetWIndowText to work, you can also use SendMessage with the "WM_SETTEXT" constant in order to set the text to what you want. The "APIViewer 2004" link in my sig has a .NET mode with all the correct .NET declarations of the API functions (as well as types and constants). Remember to set it to .NET mode in the options, as it starts in VB6 mode.

  4. #4

    Re: Help Change a Title of Another Window

    it looks like that should work if you declared everything properly like they have mentioned.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    palo alto california
    Posts
    45

    Resolved Re: Help Change a Title of Another Window

    Thanks,

    That was the solution. I must remember VB.NET uses INTeger (int32) instead of Long.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width