|
-
Feb 17th, 2006, 03:39 PM
#1
Thread Starter
Member
[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:
Public Class Form1
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim name As String = "IEFrame"
Dim title As String = "Sign In - Microsoft Internet Explorer"
Dim handleofwindow As Long = FindWindow(name, title)
If handleofwindow <> 0 Then
SetWindowText(handleofwindow, "What are you doing?")
End If
End Sub
End Class
-
Feb 17th, 2006, 04:34 PM
#2
-
Feb 17th, 2006, 04:55 PM
#3
Re: Help Change a Title of Another Window
Heres the correct .NET declarations:
VB Code:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Int32
Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" ( _
ByVal hwnd As Int32, _
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.
-
Feb 17th, 2006, 05:31 PM
#4
Lively Member
Re: Help Change a Title of Another Window
it looks like that should work if you declared everything properly like they have mentioned.
-
Feb 17th, 2006, 07:02 PM
#5
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|