Learn message (2): Send the wm_mousemove message

Source: Internet
Author: User
In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) Panel1: tpanel; button1: tbutton; button2: tbutton; button3: tbutton; Procedure panel1mousemove (Sender: tobject; shift: tshiftstate; X, Y: integer); Procedure button1click (Sender: tobject ); procedure button2click (Sender: tobject); Procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {when the mouse moves in Panel1, I did the following :} {1. Show coordinates of the mouse in Panel1} {2. show whether shift, Ctrl, ALT} procedure tform1.panel1mousemove (Sender: tobject; shift: tshiftstate; X, Y: integer); var list: tstringlist; begin list: = tstringlist. create; If ssshift in shift then list. add ('shift '); If ssctrl in shift then list. add ('ctrl '); If ssalt in shift then list. add ('alt'); If list. count> 0 then panel1.caption: = format ('% s: % d, % d', [list. commatext, X, Y]) else panel1.caption: = format ('% d, % d', [x, y]); list. free; end; {send wm_mousemove message to Panel1} {the first message parameter is 0, indicating that no secondary key is pressed} {the second message parameter is 0, it is equivalent to moving the mouse to the (0, 0) Coordinate} procedure tform1.button1click (Sender: tobject); begin panel1.perform (wm_mousemove, 0, 0); end; {send wm_mousemove message to Panel1} {the second message parameter represents the mouse Coordinate Position in the wm_mousemove message. The parameter is a 32-bit integer and the 16-bit lower is X, the 16-bit height is y} {the coordinates given here are the control center point} procedure tform1.button2click (Sender: tobject); var X, Y, lparam: integer; begin X: = panel1.clientwidth Div 2; Y: = panel1.clientheight Div 2; lparam: = y SHL 16 or X; panel1.perform (wm_mousemove, 0, lparam); end; {send wm_mousemove message to Panel1} {the first parameter of the message indicates which secondary key is being pressed and the state of the mouse} {the message sent here is: press shift and move the cursor to (20, 10)} procedure tform1.button3click (Sender: tobject); const x = 20; y = 10; begin panel1.perform (wm_mousemove, mk_shift, y SHL 16 or X); end.
 
   
 

Form file:

 Object form1: tform1 left = 0 Top = 0 caption = 'form1 'clientheight = 198 clientwidth = 255 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false pixelsperinch = 96 textheight = 13 object Panel1: tpanel left = 8 Top = 8 width = 237 Height = 121 caption = 'panel1' taborder = 0 onmousemove = panel1mousemove end object button1: tbutton left = 8 Top = 152 width = 75 Height = 25 caption = 'button1' taborder = 1 onclick = button1click end object button2: tbutton left = 89 Top = 152 width = 75 Height = 25 caption = 'button2' taborder = 2 onclick = button2click end object button3: tbutton left = 170 Top = 152 width = 75 Height = 25 caption = 'button3' taborder = 3 onclick = button3click endend

   

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.