• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Confused for adding message handler for runtime created static controls?

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.


  • 2
  • 2
1 Solution
AndyAinscowFreelance programmer / ConsultantCommented:
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.

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)
oops please ignore my comments..AndyAinscow is right. Seems i am saturated for today
HanqianAuthor Commented:
When I compile, it complains:

On_NOTIFY_RANGE' : undeclared identifier
HanqianAuthor Commented:
ON_CONTROL_RANGE( wNotifyCode, id1, id2, memberFxn )
 works well.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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