C # Use spy for Simulation

Source: Internet
Author: User

I was helpless. I wrote it for a long time. When I finally saved it, the webpage lost its response. It was really terrible. I wanted to give up on this, but I still want to roughly rewrite it once. I hope it will be helpful to my friends in the future.

The Microsoft. spy tool is a basic tool. Let's briefly introduce how to use it:

Spy comes with Vs and can be downloaded directly from the Internet.

Open the spy tool. The main interface is as follows:

Today, we use VNC as an example.

The target is to write 192.168.2.200 to the server, and click the second button of options.

Step 1: Obtain the VNC form and use spy to find the form

Drag the search tool icon to the desired interface.

In this way, we can find the required form.

Findwindow can be used to search for the first main form and class name or title.

Findjavaswex allows you to find controls in the form.

Sendmessage sends a message to the form.

Enable and window search and search controls.

1 [dllimport ("user32.dll", entrypoint = "findwindow", setlasterror = true)] 2 // parameter 1: Class Name. Parameter 2 refers to the Title name of the window. The two must have at least one 3 Public static extern intptr findwindow (string lpclassname, string lpwindowname); 4 5 6 [dllimport ("user32.dll", setlasterror = true, charset = charset. auto)] 7 public static extern intptr find1_wex (intptr parenthandle, intptr childafter, string lclassname, string windowtitle); 8 9 [dllimport ("user32.dll", entrypoint = "sendmessage ", setlasterror = true, charset = charset. auto)] 10 public static extern intptr sendmessage (intptr hwnd, uint wmsg, int wparam, string lparam); 11 12 [dllimport ("user32.dll", entrypoint = "sendmessage ", setlasterror = true, charset = charset. auto)] 13 public static extern intptr sendmessage (intptr hwnd, uint wmsg, int wparam, int lparam );

 

1 intptr win = findwindow (null, "VNC Viewer: connection details"); 2 if (win! = Intptr. Zero) 3 {4 intptr wincombobox = find1_wex (Win, new intptr (), "ComboBox", null); 5 If (wincombobox! = Intptr. zero) 6 {7 intptr winedit = find1_wex (wincombobox, new intptr (), "edit", null); 8 9 intptr resultedit = sendmessage (winedit, 0xc, 0, "192.168.2.100"); 10 11 12 // get the first button 13 intptr button1 = find1_wex (Win, new intptr (), "button", "& options... "); 14 15 if (button1! = Intptr. Zero) 16 sendmessage (button1, 0xf5, 0, 0); // Click Event 17 18 if (winedit! = Intptr. zero) 19 {20 MessageBox. show ("find edit box"); 21} 22 // MessageBox. show ("find drop-down box"); 23} 24 else25 {26 // MessageBox. show ("drop-down box not found"); 27} 28 29 30 MessageBox. show ("found form"); 31} 32 else33 {34 MessageBox. show ("no form found"); 35} 36}


The execution result is as follows:

 

 

If there are no titles for multiple buttons, you can only obtain them one by one, as shown below:

If any of you have other methods, please kindly advise.

1 IntPtr button1 = FindWindowEx(win, new IntPtr(), "Button", null);2 IntPtr button2 = FindWindowEx(win, button1, "Button", null);

 

C # Use spy for Simulation

Related Article

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.