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

Message maps / dynamically created controls

I have a dynamically created CObList of CEdits displayed on my view. How can I respond to messages e.g. EN_SETFOCUS?
As I undersatnd it...
I can't use ClassWizard because the controls don't exist at design time.
I can't manually modify the message map because I don't know how many edit boxes will be added.

Does anybody know if there is there a nice way of doing this?

Thanks in advance

  • 2
  • 2
1 Solution
Are all the controls (CEdits) going to be of the same window class, i.e are they the same "type" of control?  If so they will all share the same message map.  So just create the window class and modify its message map.  Then at run-time create as many _instances_ of this type of control as you need.  However, If they are supposed different types of controls, you will need to know their types at compile time and they will each have seperate message maps (and seperate window classes etc.)  But I suspect you will want them all to be the same type.

Let me know if you have any questions.
mark_sAuthor Commented:
I don't know how to edit a message map for a "type" of control, only for an individual ID.

If I create a control (ID 9999)

CEdit *myedit = new CEdit;
myedit->Create(WS_VISIBLE | ES_MULTILINE, CRect(10,10,200,30), this, 9999);

I can edit the message map
      ON_EN_CHANGE(9999, OnChangeEdit9999)

to handle the on change message for the edit box in  CMyFormView::OnChangeEdit9999()

I don't know MFC very well.  but assuming that MFC doesn't do anything "weird" in this case, you should handle it in the OnCommand() procedure.  See an edit control sends WM_COMMAND messages to its parent window to notify it of certain events like this.  The command messages will specify the type of notification that is being made in the high word of the WPARAM.  you should test this word to see if it is EN_CHANGE.  If so, one of the window's edit controls has had its text modified.  (The other information passed identifies which edit control, but that you don't seem to care about, right?)

Does that help?
mark_sAuthor Commented:
This is just what I need. thanks.
I would like to identify which edit control, and I see that the ID of the control is returned in LOWORD(wParam).
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

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

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