Confused for adding message handler for runtime created static controls?

Posted on 2004-04-26
Last Modified: 2013-11-20
I have a 10 runtime create static controls with resource ID; like 100, 101, 102, 103, 104,105,106
107,108,109. I want to have a function to do something for each control when the control is clicked with mouse left button down. What I have done is to add this line to MESSAGE_MAP
ON_COMMAND_RANGE(100, 109, OnClick)and add  afx_msg void OnClick(UINT nID) to header file.
It works.

The one thing that I am little confused about it is  how ON_COMMAND_RANGE knows only
to work when left button is clicked which is exactly what I want! why not work when
RBUTTONDOWN, or MOUSEMOVE, or LBUTTONUP..............................

Even ON_COMMAND_RANGE(100, 109, OnClick) works for me, is it correct to use it?
If not , what is correct message that I should use.


Question by:Hanqian
  • 2
  • 2
LVL 44

Accepted Solution

AndyAinscow earned 50 total points
ID: 10919095
The command range uses COMMAND ID's.  They are not the ID's of your controls.
you need
ON_CONTROL_RANGE( wNotifyCode, id1, id2, memberFxn )
The notification code to which your handler is responding.   ****** here is the LBUTTONDOWN

Command ID at the beginning of a contiguous range of control IDs.

Command ID at the end of a contiguous range of control IDs.

The name of the message-handler function to which the controls are mapped.


Expert Comment

ID: 10919136
You can as well use ON_NOTIFY_RANGE( wNotifyCode, id, idLast, memberFxn )

Specify any of these values of your interest for wNotifyCode
NM_CLICK User clicked left mouse button in the control
NM_DBLCLK User double-clicked left mouse button in the control
NM_RCLICK User clicked right mouse button in the control
NM_RDBLCLK User double-clicked right mouse button in the control

id The first ID of the static control
id last  ...The last ID of the static control

On_NOTIFY_RANGE(NM_CLICK, 100, 110, OnClick)

Expert Comment

ID: 10919176
oops please ignore my comments..AndyAinscow is right. Seems i am saturated for today

Author Comment

ID: 10919461
When I compile, it complains:

On_NOTIFY_RANGE' : undeclared identifier

Author Comment

ID: 10919475
ON_CONTROL_RANGE( wNotifyCode, id1, id2, memberFxn )
 works well.



Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 158
no14 challenge 14 66
mapAB Challlenge 35 142
Path of Workbook 3 74
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

14 Experts available now in Live!

Get 1:1 Help Now