Solved

How to get a control's ID?

Posted on 2001-09-14
7
531 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 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