Solved

Subclassing Notification

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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