Other processes of message sending control

Source: Internet
Author: User

Sometimes we want to control other processes by sending messages. The general knowledge point record is as follows:

1.You can use the spy ++ tool to view the window structure hierarchy.

1)HWND FindWindow(
  LPCTSTR lpClassName// pointer to class name
  LPCTSTR lpWindowName  // pointer to window name
);

Use this function to find the top-level window, but you cannot use this function to find the subwindow. Return the handle of the window.

2)HWND FindWindowEx(
  HWND hwndParent,     // handle to parent window
  HWND hwndChildAfter// handle to a child window
  LPCTSTR lpszClass,   // pointer to class name
  LPCTSTR lpszWindow   // pointer to window name
);

You can use this function to find both top-level windows and subwindows. The first parameter is the handle of the parent window of the window to be searched. If the top window is to be searched, it is set to null. The second parameter indicates the window from which to start searching, if it is null, It is searched from the first child window of the parent window. The third parameter indicates the Class Name of the window to be searched, and the last parameter indicates the window title of the window to be searched.

Sometimes some subwindows using this function cannot find the unknown reason. In this case, we can enumerate the subwindows and their descendants of the parent window in recursive mode, and then determine whether the window is the window we are looking.

The main function used in the enumeration window is getwindow.

2.Send a message to the menu

The Message Type sent from the menu is wm_command. You can use the spy ++ tool to capture the message loop and view the wparam and lparam values of the message to be sent. Then, use the sendmessage or postmessage function to send messages. The difference between the two functions is that after the sendmessage function sends a message, it waits until the message processing is complete, and the postmessage function returns the message immediately after it sends the message, regardless of whether the message is processed or not. Sending a click message to the button is similar to sending a message to the menu. wm_command is used.

3.Send messages to the tree control

Void csendmessagedlg: sendmessagetotreectrl (hwnd htree)

{

If (! Htree)

{

       Return;

}

// The root node of the message sending tree

Htreeitem hitem = (htreeitem): sendmessage (htree, tvm_getnextitem,

       Tvgn_root, 0x0 );

If (hitem)

{

       // Expand the root node for sending messages

       : Sendmessage (htree, tvm_expand, tve_expand, (long) hitem );

       // Select the next visible node for sending a message

       Hitem = (htreeitem): sendmessage (htree, tvm_getnextitem,

              Tvgn_nextvisible, (long) hitem );

       If (hitem)

       {

              : Sendmessage (htree, tvm_selectitem, tvgn_caret, (long) hitem );

       }

}

}

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.