You can use mouse_event to simulate some operations that are executed with the mouse. Next we will simulate the process of selecting a piece of text with the mouse in edit.
First, let's break down the mouse action of the selected text, which includes the basic aspects:
- Move the mouse to the specified position, the beginning of the text
- Press the mouse (wm_lbuttondown)
- Move the mouse to the specified position while pressing the mouse
- Release the left mouse button (wm_lbuttonup)
Now that we know this process, let's get throughProgramTo simulate it. During my experiment, I set up the dialog project, put a button and an edit button on the dialog, and write the program to the button event. The program is as follows:
Void ctestchkdlg: nbnclickedbutton1 ()
{
Rect;
Getdlgitem (idc_edit)-> getwindowrect (& rect );
Setcursorpos (rect. Left + 5, rect. Top + 5 );
Mouse_event (mouseeventf_absolute | mouseeventf_leftdown, rect. Left + 1, rect. Top + 1, 0, 0 );
Setcursorpos (rect. Left + 60, rect. Top + 10 );
// Mouse_event (mouseeventf_absolute | mouseeventf_move, 500,600 );
Mouse_event (mouseeventf_absolute | mouseeventf_leftup, rect. Left + 60, rect. Top + 5, 0, 0 );
}
The first thing we need to do is to get the edit position, and then move the mouse over there (setcursorpos). Adding 5 here allows the mouse to be inside the edit, because the edit has an edge, if you cannot select the rect value, use mouseeventf_leftdown to press the mouse, move the mouse to the specified position of the text, and then release the mouse.
The text is selected.
Since we can simulate the real mouse action through a program, it is not difficult to write some automatic installation programs. I remember that our company used Lotus software to copy the work and needed to swipe the card on it. Haha, since the mouse can be simulated, this method can be used to write a program to help you swipe your card. You will never be late. Of course, if you do, you will be at your own risk.