Title: Change a window caption
Question: How can I change the caption of a window that is not part of my program?
Answer:
We will be using 2 two functions to do this.
The first being Findwindow
FindWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName); //this gets a handle of a window
LPCTSTR lpClassName : points to a class name
LPCTSTR lpWindowName : points to the windows name(this is what we are using)
The second function is SetWindowText.
SetWindowText(HWND hWnd, LPCTSTR lpString); //this sets the caption of the window
HWND hWnd : this is the handle of the window, this is why we need the FindWindow function
LPCTSTR lpString : this is what we want the window caption to be
An example
procedure TForm1.Button1Click(Sender: TObject);
var window:hwnd;
begin
window:=findwindow(nil,'untitled - notepad');
setwindowtext(window,'Look it works');
end;