Solved

Problem with Dialog Bar Message Map

Posted on 1998-06-03
9
669 Views
Last Modified: 2013-11-19
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
colours.

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(BN_CLICKED, OnClicked)

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
well.

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.

Regards
Martin Hinchy


0
Comment
Question by:bcs0228
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:lucidity
ID: 1315972
If you post your project somwhere I can take a look
0
 
LVL 1

Expert Comment

by:speedup
ID: 1315973
I can try a try if you email your sample to me at chenbo@supresoft.com.

0
 

Author Comment

by:bcs0228
ID: 1315974
To speedup:

I have emailed my sample code to you.

To lucidity:

Let me know where you want the sample code posted or emailed.
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315975
Martin,

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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:bcs0228
ID: 1315976
Tom,

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.

Regards

Martin
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315977
Hi Martin,

It's tma-ng@mindspring.com

Tom

0
 

Author Comment

by:bcs0228
ID: 1315978
Tom,

The code is on its way.

Regards

Martin

0
 
LVL 2

Accepted Solution

by:
lucidity earned 300 total points
ID: 1315979
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;
OnClick{
  ClickFlag ++;
  if(ClickFlag == 2){
    SetState(); //blahblah
    ClickFlag = 0;
  }
}


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


0
 

Author Comment

by:bcs0228
ID: 1315980
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()?

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

17 Experts available now in Live!

Get 1:1 Help Now