C + + Custom control controls send a corresponding message to the parent form

Source: Internet
Author: User

Send a message to the parent form, here only send wm_notify message, the other message is the same

To set a program that sends messages in a function in a control

First, define a dedicated structure for the WM_NOTIFY message.

123456;  // here is the message of the difference code nm.hwndfrom = m_hwnd; // This is the HWND handle of the control Nm.idfrom = GetDlgCtrlID (); // This is the ID of the resulting dialog box
cwnd*  pWnd;     = GetParent ();  Gets the parent form    window if (pWnd! = NULL)    {        pWnd->sendmessage (wm_notify, Nm.idfrom , (LPARAM) &nm);  Send a message to the parent form    }

This allows the message to be sent to the parent form.

In the code of the parent form, only the WM_NOTIFY message needs to be processed, that is, the virtual function that implements the On_notify

BOOL cmycontroldlg::onnotify (WPARAM WPARAM, LPARAM LPARAM, lresult* pResult) {    if (UINT) WPARAM = = idc_custom2)    {        AfxMessageBox (_t (" success "));    }     return cdialogex::onnotify (WParam, LParam, PResult);}

Idc_custom2 This is an ID number that any resource will have

Can be found in the following way

C + + Custom control controls send a corresponding message to the parent form

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.