Solved

How to get a control's ID?

Posted on 2001-09-14
7
486 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 106
dog bark java program 15 87
Fibonacci challenge 11 108
Excel file not created as expected 7 46
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

914 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

12 Experts available now in Live!

Get 1:1 Help Now