Saturday 11 May 2019

SetWindowText.exe sets the titlebar text for a window

This uses the inbuilt compilers in Windows 10 - there are three VB.NET compilers and three C# compilers - just copy each text file into the same folder and double click the batch file to make the program.
Window Manipulation Posts

@Echo Off
Echo Two files follow
Echo SetWindowText.bat
Echo This file compiles SetWindowText.vb to SetWindowText.exe using the system VB.NET compiler.
Echo SetWindowText.exe sets the titlebar text for a window
Echo     SetWindowText.exe "OldWindowTitle" "NewWindowTitle"
Echo EG Open notepad and type in a command prompt
Echo     SetWindowText.exe "Untitled - Notepad" "My Window Title"
Echo ----------------------------------------------------------------------
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\SetWindowText.exe" "%~dp0\SetWindowText.vb" 
pause



Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public Module MyApplication  


Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

Public Declare UNICODE Function SetWindowTextW Lib "user32" (ByVal hwnd As IntPtr, ByVal lpString As String) As Integer

Sub Main()
On Error Resume Next
Dim CmdLine As String
Dim Ret as Integer
Dim A() as String
Dim hwindows as IntPtr

CmdLine = Command()
If Left(CmdLine, 2) = "/?" Then
    MsgBox("Usage:" & vbCrLf & vbCrLf & "SetText ""OldWindowTitle"" ""NewWindowTitle""")
Else
    A = Split(CmdLine, Chr(34), -1, vbBinaryCompare)
    hwindows = FindWindowW(vbNullString, A(1))
    Ret = SetWindowTextW(hwindows, A(3))
End If
End Sub
End Module


No comments:

Post a Comment