View Messages with spy ++

Source: Internet
Author: User

The spy ++ tool provided by VC has never been used. I found an article on the Internet. It feels better to share it.
Use spy ++ to view messages and send messages to the control program

Windows programs are based on message mechanisms, and each program has a variety of messages,

To control program running through messages, we only need to care about the command messages in the program.

(Wm_command). You can ignore other messages about the program interface. To view the process

Run messages in sequence using the tool spy ++ in Visual Studio.

Open spy ++, select spy | Windows, and all current windows will be displayed.

Some word windows in the main window will also be displayed, such as the toolbar window and editing window. In

Find the target window.

Below are some of the spy ++ windows displayed when I run spy ++, with the finereader window

001702a6-tooltips_class32

000c01fe-"M" msctfime ul

001c02a0-"Default ime" ime

002401do-tooltips_class32

003b009a-"Microsoft spy ++-
[Windows 2] "afx: 100000: 0: 10011: 0: 2600515

00300244-"M" msctfime ul

002e032e-finereadertipwindowclass

004f02b4-tooltips_class32

00410254-"untitled batch-abbyy finereader 7.0 Professional Edition"

Finereader7mainwindowclass

003e0370-"DDE Server window" oleddewndclass

005002dc-combolbox

000d02b6-combolbox

00270320-combolbox

00ab0366-combolbox

00a000a4-tooltips_class32

(Note: The above is the result captured by print screen and then identified by finereader)

Select finereader, right-click, and select "messages" in the pop-up menu to start

Listen to messages in this window. If you do this, you will find that there are a lot of messages and you cannot

Find the message you want to view. To select the desired message, we need to filter the message. Select

Messages | options: select the messages tab in the pop-up menu. You can see many message filtering options.

I want to listen to wm_command messages, so after I clear all, I only select general messages.

After the preceding settings, start listening to messages and click the read shortcut in the finereader window.

(After setting this button, finereader starts to recognize the selected image), then returns to spy ++ and listens

There are still a lot of messages, but you can find the messages we want to view. If you only press one button or

Menu, you should be able to find two wm_command messages, one sent
Message, a returned message. For more information, see the following description.

The following are the messages I have listened to in spy ++. One of them is a wm_command message.

<00039> 00410254 r...

<00040> 00410254 s ...... command V/policycode: 0 (sent from

Menu] wld: 4o2o3

<00041> 00410254 s ...... wm_gettext cchtextmax: 512

Lpsztext: 0012e200

<00042> 00410254 r ...... gettext cchcopied: 72

Lpsztext: 0012e200 f'u' L

(Note: The above is the result captured by print screen and then identified by finereader)

Double-click the wm_command message to view details about the message, as shown below:

Window handle 001f00aa // finereader window handle

Nesting level 2

Message 0111 (sent) // wm_command Message ID, which is the sent message

Wm_command

Wparam ipv9d0b // two parameters of the wm_command message

Lparam 00000000

Another wm_command message monitored in spy ++

<00089> 00410254 s ...... wm_gettext cchtextmax: 512

Lpsztext: 0012e1e0

<00090> 00410254 r ...... gettext cchcopied: 71

Lpsztext: 0012e1e0 (V ")

<00092> 00410254 s ...... wm_1_y idctrl: 177 pnmh: 0012f988

(Note: The above is the result captured by print screen and then identified by finereader)

Double-click the wm_command message to view details about the message, as shown below:

Window handle 001f00aa // finereader window handle

Nesting level 2

Message 0111 (return) // wm_command Message ID, which is the message

Wm_command

Wparam ipv9d0b // two parameters of the wm_command message

Lparam 00000000

Now that you can view the Message ID and parameters in the program, you can write

Program, send the corresponding message to the controlled program to control the program running.

Step 1: Open the target program in your program and use the API. For details, see msdn.

Hinstance ShellExecute (

Hwnd,

Lpctstr lpoperation,

Lpctstr lpfile,

Lptstr lpparameters,

Lpctstr lpdirectory,

Int nshowcmd

);

In my program, the target program is finereader. The code for opening the program is as follows:

Hinstance HRET = 0;

HRET = ShellExecute (m_hwnd,

Null,

"D: \ Program Files \ abbyy finereader 7.0 professional

Edition \ finereader.exe ",

Null,

Null,

Sw_hide );

If (INT) HRET <= 32)

{

MessageBox ("failed to open finereader! ");

}

Step 2: Find the target window and obtain the handle of the target window.

Cwnd * pwnd = NULL;

// The program may be slow to start. You need to try multiple times to find the target window.

While (pwnd = NULL)

{

Sleep (1000 );

Pwnd = findwindow (null, "batch-abbyy finereader 7.0 professional

Edition ");

}

Step 3: send a message to the target window.

When the finereader starts running, the last batch is automatically opened, so we only use

Send message,

Let finereader start identification. The wm_command identified by the finereader can be viewed through spy ++.

The information is as follows:

Message 0111 (sent)

Wm_command

Wparam rj9d0b

Lparam 00000000

Use sendmessage to send the message to the finereader in the following way.

Next step

: Sendmessage (pwnd-> getsafehwnd (), 0x0111, 0x9d0b, 0 );

After finereader recognition is complete, you can save the result as a file or send it to the clipboard.

Choose to make it

Send the recognition result to the clipboard. Similarly, use Spy ++ to listen for messages and their parameters, and then send the corresponding messages,

As follows:

Message 0111 (sent)

Wm_command

Wparam ipv9da1

Lparam 00000000

: Sendmessage (pwnd-> getsafehwnd (), 0x0111, 0x9da1, 0 );

After performing these operations, the finereader can identify the results directly from the clipboard,

The related code is as follows:

If (! Isclipboardformatavailable (cf_text ))

Return;

If (! Openclipboard ())

Return;

Hglobal hglb = getclipboarddata (cf_text );

If (hglb! = NULL)

{

Lptstr = (char *) globallock (hglb );

If (lptstr! = NULL)

{

MessageBox (lptstr, "recognition result ");

Globalunlock (hglb );

}

}

Emptyclipboard ();

Closeclipboard ();

Step 4: after the operation, close the target program and send the message.

First, I thought it was okay to directly send the wm_quit message. Later I found that it was not enough. I used spy ++ to listen and found that,

The wm_close message should be sent.

: Sendmessage (pwnd-> getsafehwnd (), wm_close, 0, 0 );

Now, the basic operation is implemented. In fact, I think that, as long as you do well, you can create an interface by yourself.

On behalf of the interface.


From: http://hi.baidu.com/chenfalei/blog/item/725c9a230237f640ac34de1e.html

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.