Solved

Handling ToolBar messages

Posted on 1998-05-25
14
257 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 75
Shell script to login to remote m/c and execute commands 10 78
while loop over for loop 7 103
Change to event 1 112
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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