Solved

Handling ToolBar messages

Posted on 1998-05-25
14
253 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 91
dog bark java program 15 87
countEvens challenge 2 74
matchUp  challenge 6 52
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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

18 Experts available now in Live!

Get 1:1 Help Now