?
Solved

How to get a control's ID?

Posted on 2001-09-14
7
Medium Priority
?
535 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Accepted Solution

by:
vbk_bgm earned 200 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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 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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 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