Send message from subclassed ctrl to parent dlg? 
Author Message
 Send message from subclassed ctrl to parent dlg?

Quote:

> Hello all-

>   Forgive me if this is a simple question- I'm relatively new to MFC and
> windows programming.

>   I subclassed CComboBox as "CKeyDropComboBox", and placed an instance
> of it on my main dialog (of my wizard-generated dialog-based
> application), called CComboTestDlg.  When a certain even happens on the
> subclassed combo box, I would like a function to be called on the main
> dlg.  If I understand the MSDN correctly, I should use a user message.
> Where I've gotten stuck is on how to send the message, and how to set up
> the handler on the dialog.

> Here's how I'm sending from the subclassed combobox:
>   GetParent()->SendMessage(KDCB_SELCHANGED, 0, 0);

> I don't need to send any parameters just yet.  Is this the correct way?

> I also gather that I need to use ON_MESSAGE in the message map and write
> a handler, but these attempts have failed.

> Does anyone have a simple example they'd be willing to share?

> Thanks,
> Korey Atterberry

Here's a sample:

#define WM_NEWCFG (WM_APP+123)

afx_msg LONG OnNewCfg(UINT, LONG);

   ....}}AFX_MSG_MAP     // put it after this
   ON_MESSAGE(WM_NEWCFG, OnNewCfg)
END_MESSAGE_MAP()        // put it before this

LONG CComboTestDlg::OnNewCfg(UINT, LONG)
{
   return 0;

Quote:
}

--
Scott McPhillips [VC++ MVP]


Mon, 19 May 2003 03:00:00 GMT  
 Send message from subclassed ctrl to parent dlg?

Thank you Scott-

  That did the trick.  I had been using WM_USER instead of WM_APP, which
caused my handler to be called at improper times.  Presumably the combo
box is using that same value for some other message.

Thanks again,
Korey



Quote:

> > Hello all-

> >   Forgive me if this is a simple question- I'm relatively new to MFC
and
> > windows programming.

> >   I subclassed CComboBox as "CKeyDropComboBox", and placed an
instance
> > of it on my main dialog (of my wizard-generated dialog-based
> > application), called CComboTestDlg.  When a certain even happens on
the
> > subclassed combo box, I would like a function to be called on the
main
> > dlg.  If I understand the MSDN correctly, I should use a user
message.
> > Where I've gotten stuck is on how to send the message, and how to
set up
> > the handler on the dialog.

> > Here's how I'm sending from the subclassed combobox:
> >   GetParent()->SendMessage(KDCB_SELCHANGED, 0, 0);

> > I don't need to send any parameters just yet.  Is this the correct
way?

> > I also gather that I need to use ON_MESSAGE in the message map and
write
> > a handler, but these attempts have failed.

> > Does anyone have a simple example they'd be willing to share?

> > Thanks,
> > Korey Atterberry

> Here's a sample:

> #define WM_NEWCFG (WM_APP+123)

> afx_msg LONG OnNewCfg(UINT, LONG);

>    ....}}AFX_MSG_MAP     // put it after this
>    ON_MESSAGE(WM_NEWCFG, OnNewCfg)
> END_MESSAGE_MAP()        // put it before this

> LONG CComboTestDlg::OnNewCfg(UINT, LONG)
> {
>    return 0;
> }

> --
> Scott McPhillips [VC++ MVP]

Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 20 May 2003 03:00:00 GMT  
 Send message from subclassed ctrl to parent dlg?

I have a follow-up question: if I put two of this same control on my
dialog, when I receive the message in the dlg, how can I differentiate
between the controls so that I know which of the combo boxes sent the
message?

Korey



Quote:

> > Hello all-

> >   Forgive me if this is a simple question- I'm relatively new to MFC
and
> > windows programming.

> >   I subclassed CComboBox as "CKeyDropComboBox", and placed an
instance
> > of it on my main dialog (of my wizard-generated dialog-based
> > application), called CComboTestDlg.  When a certain even happens on
the
> > subclassed combo box, I would like a function to be called on the
main
> > dlg.  If I understand the MSDN correctly, I should use a user
message.
> > Where I've gotten stuck is on how to send the message, and how to
set up
> > the handler on the dialog.

> > Here's how I'm sending from the subclassed combobox:
> >   GetParent()->SendMessage(KDCB_SELCHANGED, 0, 0);

> > I don't need to send any parameters just yet.  Is this the correct
way?

> > I also gather that I need to use ON_MESSAGE in the message map and
write
> > a handler, but these attempts have failed.

> > Does anyone have a simple example they'd be willing to share?

> > Thanks,
> > Korey Atterberry

> Here's a sample:

> #define WM_NEWCFG (WM_APP+123)

> afx_msg LONG OnNewCfg(UINT, LONG);

>    ....}}AFX_MSG_MAP     // put it after this
>    ON_MESSAGE(WM_NEWCFG, OnNewCfg)
> END_MESSAGE_MAP()        // put it before this

> LONG CComboTestDlg::OnNewCfg(UINT, LONG)
> {
>    return 0;
> }

> --
> Scott McPhillips [VC++ MVP]

Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 20 May 2003 03:00:00 GMT  
 Send message from subclassed ctrl to parent dlg?

Quote:

> I have a follow-up question: if I put two of this same control on my
> dialog, when I receive the message in the dlg, how can I differentiate
> between the controls so that I know which of the combo boxes sent the
> message?

You're welcome.  Probably the easiest way would be to have the control pass its
ID in wParam or lParam in the PostMessage call.  A control can get its own ID
with GetWindowLong

--
Scott McPhillips [VC++ MVP]



Tue, 20 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Send message from subclassed ctrl to parent dlg?

2. How to send NM_CLICK message to the parent

3. Sending a message to parent

4. PRB: List control doesn't send notification messages to CView parent

5. Sending a message to a parent CView from a child CWnd

6. Send message to parent

7. sending CTRL-TAB message

8. How to send CTRL+F9 message to the window

9. Subclassed Static Control Lose Its Parent Attribute

10. Notification to parent from Subclassed control

11. transparent text in a subclassed richedit ctrl

12. colors and subclassed treeview ctrl

 

 
Powered by phpBB® Forum Software