Solved

How to get a control's ID?

Posted on 2001-09-14
7
470 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
7 Comments
 
LVL 4

Expert Comment

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

0
 

Author Comment

by:min2max
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Accepted Solution

by:
vbk_bgm earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

11 Experts available now in Live!

Get 1:1 Help Now