Solved

How to get a control's ID?

Posted on 2001-09-14
7
519 Views
Last Modified: 2013-11-20
I'm deriving a new class from CButton, and it's designed to handle the reflected BN_CLICKED notification itself. But I still want its parent window to react when it's clicked. So, in the message handler of the control, after finishing any works I want, I'm relaying the message to its parent:

GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(MyID, BN_CLICKED));

But I don't know how to get its own identification 'MyID'.

Hope anybody could help me!
Thanks in advance.

Max
0
Comment
Question by:min2max
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:pagladasu
ID: 6484403
int MyId=m_Button.GetDlgCtrlID( );
assuming that m_Button is an object of your derived CButton class.

0
 

Author Comment

by:min2max
ID: 6484443
I'v also got the answer:

GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)GetSafeHwnd());

and to avoid the button from a endless loop reacting the notification dent by itself, I used the following mechanism:

(CSelectColorButton id the derive class of mine from CButton.)

void CSelectColorButton::OnClicked()
{
     static bHandled = FALSE;

     if(!bHandled)
     {
     CColorDialog dlg;
     if(dlg.DoModal() == IDOK)
     {
          m_clr = dlg.GetColor();
          Invalidate();
     }
     bHandled = TRUE;
     GetParent()->SendMessage(WM_COMMAND,
          MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)GetSafeHwnd());
     }
     else bHandled = FALSE;
}

This will ensure the button to act once for every two notifications. But even so, the parent dialog cannot receive the notification sent by it.

Although I have had another method to solve the problem, I still want to find out what's wrong in this approach.

Maybe you are similar to me in finding things inside out?

Thank you for your attention.

0
 

Author Comment

by:min2max
ID: 6484446
The above code just prevent the the ColorDialog from endless appearing, but it make the SendMessage() useless.

The key of the problem is how to break the message map at runtime. That is how to, at a desired time, bypass the ON_CONTROL_REFLECT() message map entry, to allow the notification flow to its parent dialog, handler of which can process it then.

Max
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
vbk_bgm earned 50 total points
ID: 6485571
I guess you want to handle the BN_CLICKED notification in the control and the parent. For that you can use:
ON_CONTROL_REFLECT_EX(BN_CLICKED, MemberFxn)

BOOL CMyControl::MemberFxn(void)
{
  //do the processing for the child control
 
  return TRUE = bypass the parent
  return FALSE = the parent will also get the message
}
0
 

Author Comment

by:min2max
ID: 6489542
hello vbk_bgm,

That great! Thank you very much for your kind help!
That's exactly what I want.

Max
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9532249
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: vbk_bgm

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
Question regarding Copy/Paste 16 98
Replacement selected text 2 67
Whole sheet autoscrub still needed 19 54
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…
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 …
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.

730 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