Problem Source: http://www.cnblogs.com/del/archive/2009/02/16/1392049.html#2011187
Program After running, F8 can save BMP and F9 can save PNG. The test directory is stored in c: \ temp.
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) Procedure formcreate (Sender: tobject ); procedure formdestroy (Sender: tobject); Private Procedure wmhotkey (var msg: twmhotkey); message wm_hotkey; public end; var form1: tform1; implementation {$ R *. DFM} uses pngimage; // PNG supports var hotkeyid: array [0 .. 1] of integer; // hotkey list // capture the current window and save it as BMP or pngprocedure getpicture (PNG: Boolean = false); var R: trect; BMP: tbitmap; begin getwindowrect (getforegroundwindow, R); BMP: = tbitmap. create; BMP. setsize (R. right-R. left, R. bottom-R. top); bitblt (BMP. canvas. handle, 0, 0, BMP. width, BMP. height, getdc (0), R. left, R. top, srccopy); If PNG then tpngimage (BMP ). savetofile ('C: \ temp \ 001.png ') else BMP. savetofile ('C: \ temp \ 001.bmp '); BMP. free; end; // register system hotkeys F8, f9procedure tform1.formcreate (Sender: tobject); var I: integer; begin for I: = low (hotkeyid) to high (hotkeyid) do hotkeyid [I]: = globaladdatom (pchar (inttostr (I); registerhotkey (handle, hotkeyid [0], 0, vk_f8); // F8 registerhotkey (handle, hotkeyid [1], 0, vk_f9); // f9end; // Processing System hotkey procedure tform1.wmhotkey (var msg: twmhotkey); begin if MSG. hotkey = hotkeyid [0] Then getpicture; // save BMP if MSG. hotkey = hotkeyid [1] Then getpicture (true); // store pngend; // destroy the system hotkey procedure tform1.formdestroy (Sender: tobject); var I: integer; begin for I: = low (hotkeyid) to high (hotkeyid) Do begin unregisterhotkey (handle, hotkeyid [I]); globaldeleteatom (hotkeyid [I]); end.