Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I change the Window Title after starting something with Process.Start?

Dim myProc as Process
myProc = myProc.Start("NotePad.exe")

Unfortunately myProc.MainWindowTitle = "Fancy Notepad" doesn't work as this is read only. So how can it be done?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can't change the window title using Process.MainWindowTitle because the property is readonly.

In order to change the window title you will firstly need to obtain a handle to target window and then instruct the Operating System to change the title of the window associated with that handle using the Win32 API function SetWindowsText like this

<DllImport("user32.dll")> _
Shared Function SetWindowText(ByVal hwnd As IntPtr, ByVal windowName As String) As Boolean
End Function

Once you have defined the function above you can proceed to manipulate the window title using the following code:

Dim process As New Process()
process.StartInfo.FileName = "notepad.exe"
process.Start()

Thread.Sleep(100)
SetWindowText(process.MainWindowHandle, "Fancy Notepad")

You need to wait a short few milliseconds before changing the window title otherwise the window title will not change.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...