How to Use System-level hotkeys to capture images saved as PNG in the current window-reply to the "Yunfeng" question

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.