Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I trap CRichEditCtrl messages?

Posted on 1999-08-02
6
Medium Priority
?
369 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:SixString
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 3

Accepted Solution

by:
Shay050799 earned 100 total points
ID: 1312391
start with subclass !
create new class using the wizard, derive it from CRichEdit.
in your dialog InitDialo do this:
ctrlclass.SubclassDlgItem(IDC_MYRICHEDIT_CTRL,this)
ctrlclass= instance of your new class (CRichEdit)
IDC_MYRICHEDIT_CTRL= the richedit resource name.

now all the messages you handle in this new class, same way as u do in a view or a dialog, go to classwizard, and create new message, lets say WM_LBUTTONDOWN, everytime u click the left button, you'll run the code from within your richedit class, and not the dialog clas

cheers
shay

0
 

Author Comment

by:SixString
ID: 1312392
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

0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1312393
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)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:SixString
ID: 1312394
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.
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1312395
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 ?
0
 

Author Comment

by:SixString
ID: 1312396
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.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

660 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