Solved

Subclassing Notification

Posted on 1998-09-08
4
258 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 66
ODBC Connection Logging, ADO.NET 6 56
iSeries DB2 Query 2 91
method notes when mouse over in eclipse 5 83
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now