1

I can get a handle to a window by title by using FindWindow, but if the window is minimized I can not get the window handle. How do you get the handle to a minimized window?

hWindow := FindWindow(nil, iWindowTitle);
Bill
  • 2,993
  • 5
  • 37
  • 71

1 Answers1

5

FindWindow does not care whether or not the window is minimized. If your call to FindWindow returns zero then that means that there is no top-level window with that title.

To demonstrate that this is the case, open an instance of Notepad and minimize it. Then run this program:

{$APPTYPE CONSOLE}

uses
  Windows;

begin
  Writeln(FindWindow(nil, 'Untitled - Notepad'));
  Readln;
end.

Clearly what is going on is that when the window you are hunting for is minimized, it does not have the title that you think it does. You'll likely need to use a tool like Spy++ to debug this.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Yes you are correct. Since I posted my question I found the real problem was my attempt to capture a bitmap of the window was failing because the window was minimized not because of no window handle. Can you restore a window by its handle so, my screen capture code functions or should I post that as a different question. – Bill Jul 07 '14 at 20:35
  • Call `ShowWindow` passing `SW_RESTORE`. See this question if you wish to avoid animations: http://stackoverflow.com/questions/6078799/minimize-restore-windows-programmatically-skipping-the-animation-effect – David Heffernan Jul 07 '14 at 20:44
  • @David... Thanks... I have my screen capture working now even if the window is minimized... – Bill Jul 07 '14 at 20:57