Use the mouse to obtain the handle of any window and use it as a "Godson"

Source: Internet
Author: User
First, it is recommended that beginners do not spend too much time on these tips. learning the basics is fundamental;
There are not many such things on my blog. This is what we are talking about when we get out of the box and know that there is such a feasibility and there is little practical value.

In this example:


In this example
Http://www.cnblogs.com/del/archive/2008/02/26/1081644.html encountered problems.

AllCodeAs follows (focus on the main form during testing ):

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) Panel1: tpanel; edit1: tedit; button1: tbutton; button2: tbutton; timer1: ttimer; procedure merge (Sender: tobject); Procedure button1click (Sender: tobject ); procedure button2click (Sender: tobject); End; Var form1: tform1; implementation {$ R *. DFM} {Here we mainly set the control location} procedure tform1.formcreate (Sender: tobject); begin panel1.align: = altop; panel1.height: = 30; edit1.top: = 4; edit1.left: = 12; edit1.width: = 72; edit1.clear; button1.top: = edit1.top-1; button1.left: = edit1.left + edit1.width + 12; button1.caption: = 'Confirm capture, press ENTER key'; button1.width: = canvas. textwidth (button1.caption) + 32; button1.default: = True; button2.top: = button1.top; button2.left: = panel1.clientwidth-button2.width-12; button2.anchors: = [akright]; button2.caption: = ''; timer1.interval: = 100; end; {capture window handle, displayed in title} procedure tform1.timer1timer (Sender: tobject); var PT: tpoint; begin if Boolean (getcursorpos (PT) then text: = inttostr (windowfrompoint (PT); end; {display the handle of the confirmed target window in edit1} procedure tform1.button1click (Sender: tobj ECT); begin edit1.text: = self. Text; end; {What is captured? For example, let it be your "Godson"} procedure tform1.button2click (Sender: tobject); var H: hwnd; {This is the handle of the captured window} r: trect; {This is the rectangle of the captured window} PW, pH: integer; {This is the width and height of the captured window} begin H: = strtoint (edit1.text); windows. setparent (H, self. handle); getwindowrect (H, R); PW: = R. right-R. left; Ph: = R. bottom-R. top; movewindow (H, 0, panel1.height, PW, pH, true); end.
 
   
 

I found that the calculator has not been closed yet. It is of little use and I will not redo it any more.

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.