469,573 Members | 1,296 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,573 developers. It's quick & easy.

ATL Richedit text change events

Hi
In trying to create a RICHEDIT-derived ActiveX control in ATL, I've managed
to successfully implement the stock font property, thanks for all your help
on this.
I'm now stuck on receiving notification that the text has changed.
I selected a stock Text property when creating the control, which put an
OnTextChanged event handler into my control's main class. This never seems to
get called, even when I put code to set the event mask appropriately in the
OnCreate, which now looks like this:
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL&
/*bHandled*/)
{
RECT rc;
GetWindowRect(&rc);
rc.right -= rc.left;
rc.bottom -= rc.top;
rc.top = rc.left = 0;
m_hLibRichEdit = LoadLibrary(_T("RICHED32.DLL"));
m_ctlRichEdit.Create(m_hWnd, rc);

DWORD dwEvents = m_ctlRichEdit.SendMessage(EM_GETEVENTMASK);
m_ctlRichEdit.SendMessage(EM_SETEVENTMASK, 0, dwEvents | ENM_CHANGE);
return 0;
}
I tried another tack - selected the control's main class in Class view, went
to properties, chose messages, and added a handler through the wizard for
WM_CHAR. It never gets called either, even when I've noticed that while I'm
pressing keys to type text into the RICHEDIT, it is receiving WM_CHAR
messages as shown by Spy++. (The WM_CHAR handler is as shown below)

LRESULT Ctextchange::OnChar(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
/*lParam*/, BOOL& /*bHandled*/)
{

ATLTRACE(_T("OnChar fired!")); //never gets called.

return S_OK;
}

I'm now at a loss, so can anybody suggest anything? Thanks ever so.

Nov 17 '05 #1
10 2884
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com
In trying to create a RICHEDIT-derived ActiveX control in ATL, I've
managed to successfully implement the stock font property, thanks for
all your help on this.
I'm now stuck on receiving notification that the text has changed.
I selected a stock Text property when creating the control, which put
an OnTextChanged event handler into my control's main class. This
never seems to get called, even when I put code to set the event mask
appropriately in the OnCreate, which now looks like this:


Do you have an event handler for EN_CHANGE notification in your message
map? Show this entry.
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Nov 17 '05 #2
Read up on CHAIN_MSG_MAP and see what it does.

Brian
Nov 17 '05 #3
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com
This is the whole message map:

BEGIN_MSG_MAP(Ctextchange)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
CHAIN_MSG_MAP(CComControl<Ctextchange>)
MESSAGE_HANDLER(EN_CHANGE, OnChange) //this is what I added


EN_CHANGE is a notification sent in the form of WM_COMMAND message. You
want

COMMAND_CODE_HANDLER(EN_CHANGE, OnChange)

LRESULT OnChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL&
bHandled);

And move it before CHAIN_MSG_MAP
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Nov 17 '05 #4
That's great - cheers... how do you get to know these things?
Is there somewhere I could have looked it up?
"Igor Tandetnik" wrote:
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com
This is the whole message map:

BEGIN_MSG_MAP(Ctextchange)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
CHAIN_MSG_MAP(CComControl<Ctextchange>)
MESSAGE_HANDLER(EN_CHANGE, OnChange) //this is what I added


EN_CHANGE is a notification sent in the form of WM_COMMAND message. You
want

COMMAND_CODE_HANDLER(EN_CHANGE, OnChange)

LRESULT OnChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL&
bHandled);

And move it before CHAIN_MSG_MAP
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage

Nov 17 '05 #5
Ok I will cheers.
"Brian Muth" wrote:
Read up on CHAIN_MSG_MAP and see what it does.

Brian

Nov 17 '05 #6
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com
That's great - cheers... how do you get to know these things?


By reading the docs. EN_CHANGE documentation quite clearly states, and I
quote: The parent window of the edit control receives this notification
message through a WM_COMMAND message.
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Nov 17 '05 #7
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com
That's great Igor, it works, thanks.
All I'm wondering now, is what is the difference between, say,
WM_CREATE / OnCreate that MESSAGE_HANDLER is able to route it in the
correct way, to EN_CHANGE / OnChange, that needs COMMAND_CODE_HANDLER
to make it fire? I'm thinking in SDK terms where a message is just a
message, nothing special about it, just a UINT that's passed as a
parameter to a WNDPROC.....?


Which part of "EN_CHANGE is not a message, it is a notification sent via
WM_COMMAND" do you have difficulty understanding?
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Nov 17 '05 #8
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com
Yes, I get that... so a WM_COMMAND message gets sent to the *parent*'s
wndproc, with EN_CHANGE being one of the parameters.
But how are you supposed to know that you need to use
COMMAND_CODE_HANDLER in order to respond to it?
By reading the documentation, in this case

http://msdn.microsoft.com/library/en...emapmacros.asp
Not trying to be ignorant - just wanting to be less reliant on the
ngs if I don't have to be.
How did *you* find that out?, when you were learning it did it not
confuse you?


With any new area of technology, I find it useful to read a book (I
usually jump straight into the thickest and most advanced book on the
subject I can find, skipping the "in 14 days" and "for dummies" titles)
to get some orientation. The book lets me know what can be done with the
technology, and where to get more information. Then I study the docs and
the source code (if available) as the need arises.

For ATL, I recommend "ATL Internals" by Rector and Sells. For COM stuff
not specific to any particular implementation or library, consider
"Essential COM" by Don Box. Both are pretty advanced.
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Nov 17 '05 #9
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com
When you're referring to something in help, if you post the url at
the top of the help browser, I can see what you're referring to.
e.g. if you look at:

ms-help://MS.MSDNQTR.2003FEB.1033/shellcc/platform/commctls/editcontrols
/editcontrolreference/editcontrolmessages/en_change.htm

Unfortunately, these URLs are specific to the version of MSDN one has
installed. E.g., from the URL I see you have February 2003 version. I
have July 2004 version, this URL does not work for me. However, I expect
anybody intelligent enough to figure out how to post to a newsgroup to
be able to plug a term into the Index or Search field in MSDN viewer.
Apparently you have no difficulty with this task, so please allow me to
continue with my usual practice of giving doc references. Thank you for
your understanding, and sorry for the inconvenience.
it
does say then, "The parent window of the edit control receives this
notification message through a WM_COMMAND message".
There's no reference to COMMAND_CODE_HANDLER on that page though.


Because this documentation is for raw Win32 API, and is not specific to
any particular library. Different frameworks have different ways of
handling messages (e.g. COMMAND_CODE_HANDLER in ATL, ON_EN_CHANGE in
MFC), and some people choose to code directly to Win32 API without using
any framework.
--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Nov 17 '05 #10
But it should be clear that you cannot place it before the MESSAGE_HANDLER
line. ie. it is acting as a "Goto"

Brian
Nov 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by murlbrown | last post: by
1 post views Thread by Peter Taylor | last post: by
1 post views Thread by Patty O'Dors | last post: by
2 posts views Thread by gsb58 | last post: by
1 post views Thread by swethak | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.