jsFindWindow.gif (947 bytes) jsFindWindow

Given a window name, ie the window's caption, this component will find the associated window handle. It is a simple component but handy when you need to find a window handle.

Example:

   // look for a window caption that starts with 'Hello'
   // but is NOT 'Hello - Notepad'
jsFindWindow.windowName := 'Hello'; 

jsFindWindow.ignoreWindowName := 'Hello - Notepad';
hWnd := jsFindWindow.GetWindowHandle;  // now we have the window handle

    // now do something with hWnd
....

type TjsFindWindow = class(TComponent)
private
  FWindowName : String;
  FIgnoreWindowName : String;
  FszWindowName : PChar;  {window name (caption) to look for}
  FszIgnoreWindowName : PChar; { OPTIONAL WINDOW NAME TO IGNORE -- DONT RETURN A MATCH TO THIS NAME }
  FwindowHandle : hWnd;
protected
public
  constructor Create(AOwner : TComponent); override;
  destructor Destroy; override;
  function GetWindowHandle : hWnd;  { searches for matching window name, returned handle placed here }
published
  property windowName : String read FWindowName write FWindowName;
  property ignoreWindowName : String read FIgnoreWindowName write FIgnoreWindowName;
  property windowHandle : hWnd read FwindowHandle write FwindowHandle;
end;