Solved

Handling ToolBar messages

Posted on 1998-05-25
14
258 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
ID: 1314787
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
ID: 1314788
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
ID: 1314789
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:fidodido
ID: 1314790
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
ID: 1314791
You have to add a reflected message handler manually.
0
 

Author Comment

by:fidodido
ID: 1314792
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
ID: 1314793
The macro for WM_COMMAND notifications is ON_CONTROL_REFLECT.
0
 

Author Comment

by:fidodido
ID: 1314794
hi chensu,

ON_CONTROL_REFLECT takes wNotifyCode. What should be this value?
0
 

Expert Comment

by:t004024
ID: 1314795
Wouldn't it just be BN_CLICKED???
0
 

Expert Comment

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

Author Comment

by:fidodido
ID: 1314797
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
ID: 1314798
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
ID: 1314799
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
ID: 1314800
So, the answer is to use ON_CONTROL_REFLECT(BN_CLICKED) and CWnd::GetCurrentMessage.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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