Solved

Subclassing Notification

Posted on 1998-09-08
4
270 Views
Last Modified: 2013-11-20
In my dialog box I got 2 edit boxes. First one is subclassed
by CMyEdit ( a general class derived from CEdit ). In CMyEdit I've handled WM_KILLFOCUS. Now I need to handle the killfocus event of my first edit box in my dialog box also.
This is the situation. How do I give notification to
the dialog from CMyEdit class and how to handle it in my dialog class. please explain it in detail.
0
Comment
Question by:krpadman
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1321912
The dialog box is the parent window of the edit box. You may define a message and post it to the dialog box.

#define    WM_MYNOTIFICATION        (WM_APP + 1)

ON_MESSAGE(WM_MYNOTIFICATION, OnMyNotification)

LONG CMyDialog::OnMyNotification(UINT, LONG)
{
    //...
    return 0L;
}

void CMyEdit::OnKillFocus(CWnd *pNewWnd)
{
    //...
    CWnd *pWndParent = this->GetParent();
    if (pWndParent != NULL)
         pWndParent->PostMessage(WM_MYNOTIFICATION);
    //...
}
0
 

Author Comment

by:krpadman
ID: 1321913
Thank you for your response.
This is working. But since CMyEdit is a generic class, in some other dialog, we may
have to have more than one edit boxes to be subclassed with CMyEdit. In that case
the parent window may not be able to distinguish between the messages of the edit
boxes. So can you suggest any other way to solve this problem. What about ON_NOTIFY_REFLECT? can we use this here? Please give me the steps to implement this.

0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1321914
Pass the window handle and ID of the edit controls along with the notification message.

void CMyEdit::OnKillFocus(CWnd *pNewWnd)
{
    //...
    CWnd *pWndParent = this->GetParent();
    if (pWndParent != NULL)
         pWndParent->PostMessage(WM_MYNOTIFICATION, (WPARAM)(this->GetSafeHwnd()), (LPARAM)(this->GetDlgCtrlID()));
    //...
}

LONG CMyDialog::OnMyNotification(UINT wParam, LONG lParam)
{
    HWND hWndEdit = (HWND)wParam;
    int nIDEdit = (int)lParam;
    //...
    return 0L;
}

0
 

Author Comment

by:krpadman
ID: 1321915
Thank you very much.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 78
Replacement selected text 2 62
twoTwo  challenge 35 103
Path of Workbook 3 77
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question