Link to home
Start Free TrialLog in
Avatar of SixString
SixString

asked on

How do I trap CRichEditCtrl messages?

I am running VC++ 4.0, Win 98.

I'm something of a newbie and suspect I'm missing something obvious.  If not, I'd be glad to increase the points on this.

I have a dialog box with a RichEdit control.  I am able to put the text in the control, format it, etc. with no trouble.

When the user clicks (or double-clicks) on a word in the control, I want to trap which word he clicked on and act on it in my dialog class.

I would like to either trap the X, Y point of the mouse cursor when the user clicked, or possibly just grab the word (if he double-clicked on it).

How can I trap LBUTTONDOWN, LBUTTONUP, SELCHANGE, etc. messages in the dialog class, or is there another way to do this?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Shay050799
Shay050799

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SixString
SixString

ASKER

Ok, I tried that, but get a Debug Assertion Fail.  Here is the code.  (I had to create a CEdit control, then "overwrite" it with a CRichEdit control, since VC++ 4 studio doesn't let me create a RichEditCtrl.)

m_richEdit is of class CMyRichEditCtrl, which is derived from CRichEditCtrl.
**************************

// Get a pointer to the existing plain edit window
CWnd* pWnd = GetDlgItem (IDC_EDIT_ARRANGE);       
ASSERT(pWnd != NULL);

// Find its location
CRect rect;
pWnd->GetWindowRect (rect);
ScreenToClient (rect);

// Destroy the existing window
pWnd->DestroyWindow();

// Create the new window
DWORD dwStyle = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | ES_MULTILINE;
m_richEdit.Create (dwStyle, rect, this, IDC_EDIT_ARRANGE);

VERIFY (m_richEdit.SubclassDlgItem (IDC_EDIT_ARRANGE, this));

********************
I get a Debug Assertion Failed error on the last line.
Debug tells me m_richEdit is of class CMyRichEditCtrl, with a handle hWnd=0x00000df4.  m_hWndOwner is 0x00000000

go to the crichedit class you just created and put the following function in there from the claswizard:
PreSubClassWindow()

take off the VERIFY, and out a breakpoint in the PreSubClassWindow() function
see if its got there.
make sure the control is built using the Create function, see if you see it by using
m_richEdit->ShowWindow(WS_SHOW)
I added the PreSubclassWindow function and put a breakpoint in it.  Yes, it is getting there.  The Debug assertion happens after that, but before the dialog box appears.

I did not understand your last comment, about using SW_SHOW.

By the way, does it matter where all this RichEdit code is in the OnInitDialog function; that is, before or after the CDialog::OnInitDialog() call?

Thanks.
suppose to be after OnInitDialog()
the SW_SHOW is a flag to show a window, check if the edit is get shown, in other words, does your edit control created at all.

are u using Dialog/CForm ?
if so, why u are using Create, and u do not place them on the Dialog itself ?
any reasin ?
I know what WM_SHOW does, I just didn't understand your request.  Let me recap:

The dialog and RichEdit control were working fine before I added the subclassing; I just wanted to trap commands.

Now that I'm subclassing, I get an Assertion failure BEFORE the dialog is displayed, but sometime AFTER the call to the PreSubclassWindow function you had me add.  If I Ignore the Debug Assertion error, the programs continues fine; the dialog and controls are created and the button commands are trapped, just like I need.

I just need to get rid of the Assertion failure.

I don't know what Dialog/CForm is.  I am using Create because I got the code here on Ex-exchange from someone else who had a similar question:  how to create a RichEditCtrl when you're using VC++ 4, which has only a standard EditCtrl button in Developer Studio.

Thanks.