VC simulation click other program button

Source: Internet
Author: User

Today, the inspector needs to provide an automatic application installation function, so he does not know how to write the parameters when writing sendmessage/postmessage.

 

If you are familiar with SDK programming, you must be clear about MSG, wparam, and lparam.
And other parameters, of course, it will also be easy to write, it is nothing more than findwindow, find1_wex, postmessage and other physical activity. The following code is tested by myself:

 

1. Test Procedure

Create a blank dialog box and add the message to the "OK" button:

Void cmsgboxdlg: onok () <br/>{< br/> // todo: add extra validation here <br/> MessageBox ("test mouse click successful! "); <Br/>}

 

2. VC simulated button

The above project is the button we need to simulate and the main program, and we will create a new dialog box to test the simulated button:

Void ctestdlg: onok () <br/>{< br/> // todo: add extra validation here <br/> hwndhwnd1, hwnd2; <br/> hwnd1 = :: findwindow (null, _ T ("msgbox"); <br/> If (! Hwnd1) <br/>{< br/> MessageBox ("run the program msgbox.exe first! "); <Br/> return; <br/>}< br/> hwnd2 =: find1_wex (hwnd1, null, _ T (" button "), null ); <br/> If (! Hwnd2) <br/>{< br/> MessageBox ("No/" OK/"button found! "); <Br/> return; <br/>}< br/> uint nctrlid =: getdlgctrlid (hwnd2); <br/>: postmessage (hwnd2, wm_command, (wparam) (bn_clicked <16 | nctrlid), (lparam) hwnd2); <br/>: postmessage (hwnd2, wm_mousemove, mk_lbutton, makelong (0, 0 )); <br/>: postmessage (hwnd2, wm_lbuttondown, mk_lbutton, makelparam (); <br/>: postmessage (hwnd2, wm_lbuttonup, mk_lbutton, makelparam )); <br/>}

 

3. program running effect:

 

You don't need to upload the Code. If you are interested, check it out!

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.