Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Handling ToolBar messages

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
fidodido
Asked:
fidodido
1 Solution
 
chensuCommented:
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
 
fidodidoAuthor Commented:
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
 
chensuCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fidodidoAuthor Commented:
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
 
chensuCommented:
You have to add a reflected message handler manually.
0
 
fidodidoAuthor Commented:
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
 
chensuCommented:
The macro for WM_COMMAND notifications is ON_CONTROL_REFLECT.
0
 
fidodidoAuthor Commented:
hi chensu,

ON_CONTROL_REFLECT takes wNotifyCode. What should be this value?
0
 
t004024Commented:
Wouldn't it just be BN_CLICKED???
0
 
LucidityCommented:
could try something like this guy does
http://209.66.99.126/toolbar/ctrls_in_tb.shtml
0
 
fidodidoAuthor Commented:
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
 
chensuCommented:
You may try CWnd::GetCurrentMessage in the handler of reflected message to get the actual WM_COMMAND message and check its parameters.
0
 
fidodidoAuthor Commented:
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
 
chensuCommented:
So, the answer is to use ON_CONTROL_REFLECT(BN_CLICKED) and CWnd::GetCurrentMessage.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now