VC Programming controls other applications

Source: Internet
Author: User
Tags ukey

The ukey Production Line of the factory requires serial numbers. The serial numbers on the housing are marked by the laser marking machine. Because the serial numbers and the marking are different, the internal serial numbers of the ukey are inconsistent with those of the shell, two people are required to work,

If the marking machine numbers the ukey at the same time, the above problems are solved. Because the Laser Marking Machine Software has no interface, and the manufacturer's support cannot keep up, I thought of writing VC software to control the marking software. The procedure is as follows:

1. Download spy ++ online first;

2. Find the main window: hwnd =: findwindow (null, m_strtitle); // m_strtitle is the title of the window.

3. Find the subwindow hwnd hwnd1 =: find1_wex (hwnd, null, "afxcontrolbar42", "");

In spy ++, locate the class and title of the required subwindow.

4. Find multiple child windows of the same type (in a parent window, there are multiple child windows without window titles, and 3rd child windows are required)

Hwnd hwnd5 =: find1_wex (hwnd4, null, "#32770", ""); // The first subwindow

Hwnd hwnd6 =: find1_wex (hwnd4, hwnd5, "#32770", ""); // The second subwindow

Hwnd hwnd7 =: find1_wex (hwnd4, hwnd6, "#32770", ""); // The third subwindow

5. Find the edit box: hwnd hedit =: getdlgitem (hwnd7, 0x65c); // 0x65c is the ID of this control in spy ++.

6. Set focus:

: Sendmessage (hwnd, wm_setfocus, null, null );
: Sendmessage (hedit, wm_setfocus, null, null );
7. assign a value to the edit box

: Sendmessage (hedit, wm_settext, (wparam) 255, (lparam) sztext); sleep (100 );

8. Send "Click message" to the button

: Sendmessage (hwndbtn, bm_click, null, null); sleep (100 );
: Sendmessage (hwndbtn2, bm_click, null, null );

 

Example:

Void ctestdlg: onok ()
{
// Todo: add extra validation here
Char sztext [256];
// Hwnd =: findwindow (null, "Han's laser marking software 5.3.3-[SKP]");
// If (hwnd): MessageBox (null, "find", "TJ", 0 );
Hwnd =: findwindow (null, "Calculator"); // m_strtitle = "Calculator", which is different in different languages

/* Hwnd hedit1 =: getdlgitem (hwnd, 0x193 );
: Sendmessage (hedit1, wm_char, '1', 0 );
Sleep (500 );
: Sendmessage (hedit1, wm_char, '2', 0 );
Return;
*/
Hwnd hedit1 =: getdlgitem (hwnd, 125); // the ID of Button 1, which can be observed in spy ++.
Hwnd heditmul =: getdlgitem (hwnd, 0x5b); // the ID of the multiplication number, which can be observed in spy ++.
Hwnd hediteq =: getdlgitem (hwnd, 0x70); // ID of the equal sign, which can be observed in spy ++.
: Sendmessage (hedit1, bm_click, null, null); sleep (500 );
: Sendmessage (hedit1, bm_click, null, null); sleep (500 );
: Sendmessage (hedit1, bm_click, null, null); sleep (500 );
: Sendmessage (heditmul, bm_click, null, null); sleep (500 );
: Sendmessage (hedit1, bm_click, null, null); sleep (500 );
: Sendmessage (hedit1, bm_click, null, null); sleep (500 );
: Sendmessage (hedit1, bm_click, null, null); sleep (1000 );
: Sendmessage (hediteq, bm_click, null, null); sleep (500 );
Hwnd hedit =: getdlgitem (hwnd, 0x193 );
:: Sendmessage (hedit, wm_gettext, (wparam) 256, (lparam) sztext );
Strcpy (sztext, "12345678 ");
: Sendmessage (hedit, wm_settext, (wparam) 256, (lparam) sztext );
: MessageBox (null, sztext, "TJ", 0 );
}

 

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.