Solved

Handling ToolBar messages

Posted on 1998-05-25
14
250 Views
Last Modified: 2013-11-20
hi,

I have a CToolBar derived class in my application. This toolbar is the child of mainframe window and is dockable. In my derived class (lets call it CMyToolBar) I have overridden OnChildNotify, so that all messages sent ot parent from this toolbar can be captured. When a button is clicked on the toolbar though OnChildNotify is called I am not able to interpret what message it is. OnChildNotify has 'message', 'wParam', 'lParam' as parameters.

Anyone knows how to interpret these parameter values so that I can detect which button on the toolbar is clicked.

I also tried to declare message maps in the CMyToolBar for these button clicks. But these functions are not called when I click the button,only the parent's(ie mainframe's) handlers are called.

any solutions?
Thanks
0
Comment
Question by:fidodido
14 Comments
 
LVL 23

Expert Comment

by:chensu
Comment Utility
The messages are WM_COMMAND and WM_NOTIFY.

WM_COMMAND
wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam);         // item, control, or accelerator identifier
hwndCtl = (HWND) lParam;      // handle of control

WM_NOTIFY
    idCtrl = (int) wParam;
    pnmh = (LPNMHDR) lParam;

0
 

Author Comment

by:fidodido
Comment Utility
Hi Chensu,
Thanks for the info. Still I have some problems.

Basically what I want to achieve is that, load a toolbar into my application using a dll (which I am able to do successfully). I want to handle all the button clicks on this toolbar in my DLL itself (that is in CMyToolBar class) and not in the mainframe window (which will require me to declare message maps in mainframe and I want to avoid this).
How can this be achieved ? Is there any alternate way ? It would be very heplful if some example code is provided.

Note: My toolbar buttons donot have corresponding command on applications menu.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
You can achieve it by using the message reflection provided by MFC. Look into the MFC Technical Notes "TN062: Message Reflection for Windows Controls".
0
 

Author Comment

by:fidodido
Comment Utility
hi,
I have gone through this article. But when I tried to use class wizard to add reflected message handler for my class(CMyToolBar), the are not dispalyed in the message list(as article says the will be prefixed by '='). What is the problem.

All I need to achieve is identify which button is clicked on the toolbar in the CMyToolBar class.

Thankyou.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
You have to add a reflected message handler manually.
0
 

Author Comment

by:fidodido
Comment Utility
hi chensu,
  but to detect which button is clicked what reflected message should I handle ? If possible please give some example code.

thank you.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
The macro for WM_COMMAND notifications is ON_CONTROL_REFLECT.
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:fidodido
Comment Utility
hi chensu,

ON_CONTROL_REFLECT takes wNotifyCode. What should be this value?
0
 

Expert Comment

by:t004024
Comment Utility
Wouldn't it just be BN_CLICKED???
0
 

Expert Comment

by:Lucidity
Comment Utility
could try something like this guy does
http://209.66.99.126/toolbar/ctrls_in_tb.shtml
0
 

Author Comment

by:fidodido
Comment Utility
hi,

thankyou for suggestions.

As t004024 said BN_CLICKED works. But problem is how to detect which button is clicked because the handler of reflected message doesn't give any parameter. How to solve this?

Lucididty, the article you specified describes how to add controls to toolbar. my problem differs from this. anyway thanks.

fidodido

0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
You may try CWnd::GetCurrentMessage in the handler of reflected message to get the actual WM_COMMAND message and check its parameters.
0
 

Author Comment

by:fidodido
Comment Utility
Hi Chensu,

That works atlast! the message's wParam contains the Button ID. so I am able to detect which botton it is! That solved my problem

Thankyou very much.
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
Comment Utility
So, the answer is to use ON_CONTROL_REFLECT(BN_CLICKED) and CWnd::GetCurrentMessage.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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 shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

10 Experts available now in Live!

Get 1:1 Help Now