Problem with Dialog Bar Message Map

I have developed my own sticky button class (CColourButton) derived from
CButton. When the button is clicked on with the mouse it pushes in and stays
pushed in. It is also repainted in a certain colour. When the button is
clicked on again it pops back out and is repainted in the standard button

The class works great when I subclass the CColourButton class to button controls
in a dialog application.

Problems occur though when I subclass the CColourButton class to button controls
in a dialog bar (CDialogBar). The dialog bar is attached to the frame of an
SDI application. Each time the mouse is clicked on a button, the CColourButton
class receives two BN_CLICKED notifications.

The CColurButton class is described below:

I am using message reflection so that my button class can handle the
BN_CLICKED notification message. It is from within the BN_CLICKED
notification handler that I determine whether to keep the button pushed in
or to pop it out.

Message reflection has been set up by adding the ON_CONTROL_REFLECT_EX macro
to the CColourButton message map as follows:


ON_CONTROL_REFLECT_EX is used instead of ON_CONTROL_REFLECT because I want
the owner of the button control to be able to process BN_CLICKED messages as

The OnClicked() member function is as follows:

BOOL CMyButton::OnClicked()
// TODO: Add your control notification handler code here

// Does some processing....

return FALSE;        // Returning false ensures that the parent also gets
to see the
                                 // BN_CLICKED message

Can someone please explain why I am receiving two BN_CLICKED messages when
subclassing to a button control in a dialog bar?

I believe there may be some problem with the dialog bar message map which is causing two BN_CLICKED messages to be posted each time the button is clicked.

Martin Hinchy

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you post your project somwhere I can take a look
I can try a try if you email your sample to me at

bcs0228Author Commented:
To speedup:

I have emailed my sample code to you.

To lucidity:

Let me know where you want the sample code posted or emailed.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.


Did you get an answer on this one. I'm using dialog bars "all over town" in my code and have never had the problem you describe. If you want, email me a copy and I'll see what I can do.

Tom Archer
bcs0228Author Commented:

I haven't been able to get an answer on this from anyone and I have posted the problem to numerous newsgroups and discussion boards.

What's your email address so I can email the code to you.


Hi Martin,



bcs0228Author Commented:

The code is on its way.



CDialogBars get two mouse clicks for some strange reason,(Probably on message sent from the window and another sent from the DialogBar) if you make a new calss specifically for your buttons in a CDialogBar that chages the state only after it has received two mouse clicks it should work. Its kind of a jury rig but oh well..

int ClickFlag=0;
  ClickFlag ++;
  if(ClickFlag == 2){
    SetState(); //blahblah
    ClickFlag = 0;

try overriding the MainWindow class so that it does not send messages destined for your buttons.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bcs0228Author Commented:
To Lucidity,

I don't really want to have one CColourButton class for dialog windows and another one for dialog bars. I'd rather just have one common class.

Your second option re: overriding the main window class sounds preferable. Can you please explain what you mean. Do you mean trapping all windows messages in CMainFrame using OnWndMsg()?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.