Tuesday, September 29, 2009

How to change a window's caption

I've notice that a remarkable number of people are searching for a method to change a window's caption, well this can be achieved by a simple function called SetWindowText and it's defined as
function SetWindowText(hWnd: HWND; lpString: PWideChar): BOOL; external user32 name 'SetWindowTextW';

all you need to do is to know the caption of the window you want to change caption or have it's handle, i.e.
procedure ChangeNotepadCaption;
  hNotepad: HWND;
  hNotepad := FindWindow(nil, 'Untitled - Notepad');
  SetWindowText(hNotepad, 'Delphi 2010 change caption demo :)');

or if you only know a part of the caption(or the caption is constantly changing) which does not change no matter what then you can find that window with FindWindowExtd that can be found at an older post fallowing this link.

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)