|
-
September 21st, 2010, 05:40 AM
#1
[RESOLVED] Can't enter text in my CRichEditCtrl
Hi,
I've created an SDI app with multiple views using VS 2008 on XP Pro.
The main view is CView on which I draw some stuff. I have two secondary views, both are to be Rich Edit views allowing the user to modify data.
Having created a CRichEditView app in the past, I was thinking this would be easy. I started trying to use CRichEditView and realized quickly that it seems to be highly dependent on the doc and the container classes. So I switched to CView with a CRichEditCtrl sized to the client area of the view. This seems to work and text (that I create in OnDraw) is displayed but my problem is that I don't get the blinking cursor and I can't enter data directly into the control. It's like the control is read only. Any ideas?
I declare the control in my secondary CView's header file.
CRichEditCtrl m_RichEditCtrl;
I create the control in the CView's implementation file's OnCreate,
CRect rect(0,0,0,0);
if (CView::OnCreate(lpCreateStruct) == -1) return -1;
m_RichEditCtrl.Create(ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_VSCROLL, rect, this, 1);
//AfxInitRichEdit2();
return 0;
I size the control to fit the client area in the CView's OnSize override,
CRect rect;
CView::OnSize(nType, cx, cy);
GetClientRect(rect);
m_RichEditCtrl.SetWindowPos(&wndTop, 0, 0, rect.right - rect.left,rect.bottom - rect.top, SWP_SHOWWINDOW);
long mask = m_RichEditCtrl.GetEventMask();
m_RichEditCtrl.SetEventMask(mask |= ENM_CHANGE );
and finally, in the CView's OnDraw,
m_RichEditCtrl.SetSel(0,-1);
m_RichEditCtrl.ReplaceSel("Hello World!");
Regards,
Lowell
-
September 22nd, 2010, 03:28 AM
#2
Re: Can't enter text in my CRichEditCtrl
 Originally Posted by lspecht
...
and finally, in the CView's OnDraw,
m_RichEditCtrl.SetSel(0,-1);
m_RichEditCtrl.ReplaceSel("Hello World!");
It was a serious mistake to put such a code in the CView's OnDraw method! 
Remove these lines. Or, at least move them to the CView's OnInitialUpdate method
Victor Nijegorodov
-
September 22nd, 2010, 05:05 AM
#3
Re: Can't enter text in my CRichEditCtrl
Thanks for responding, Victor.
I moved it to the end of my OnInitialUpdate override as you suggested but it did not fix my problem. My OnDraw override is now empty. I only have those lines in for debugging purposes, anyway .
Any other ideas on why I can't modify/add text in the control?
Regards,
Lowell
-
September 22nd, 2010, 05:20 AM
#4
Re: Can't enter text in my CRichEditCtrl
- Is there any particular reason to use "an SDI app with multiple views" instead of an MDI app?
- Why did you choose CView rather than the CFormView "with a CRichEditCtrl sized to the client area of the view"?
Victor Nijegorodov
-
September 22nd, 2010, 05:40 AM
#5
Re: Can't enter text in my CRichEditCtrl
Yes, there are reasons for not using an MDI app. My app is a front end for a database where of course, all the data is stored. The function that my app performs does not require multiple documents and I felt the overhead of managing the extra code for multiple documents was unecessary.
Is there an advantage to using CFormView over CView? In other words, why would I want to do that?
Regards,
Lowell
-
September 22nd, 2010, 06:31 AM
#6
Re: Can't enter text in my CRichEditCtrl
 Originally Posted by lspecht
Is there an advantage to using CFormView over CView? In other words, why would I want to do that?
I never used CRichEditCtrl in any CView other than CFormView. But I know that CRichEditCtrl placed in CFormView template does work without any problem. The same is for CRichEditView: it does work.
So I cannot understand why you had problems with it.
Besides, what did you meand by
 Originally Posted by lspecht
it seems to be highly dependent on the doc and the container classes.
Victor Nijegorodov
-
September 22nd, 2010, 06:45 AM
#7
Re: Can't enter text in my CRichEditCtrl
My comment was based on internet research and what others have said for using CRichEditView and looking at the CRichEditView code that contains the additional CRichEditCntrItem class and additional code in the doc for the container class. My first attempt was to use CRichEditView but when I selected the view from my app's menu, the entire client area of the CRichEditView was invalidated and I didn't see the control. That might actually be an easy fix, you think? I was not able to figure out how to fix it so I switched to the method we've been discussing.
While waiting for your response, I bit the bullet and created a CFormView and drew the rich edit control on that. The good news is that now I can modify the text in the control with the keyboard. The bad news, I can't select text or a new insertion point with the mouse. It's like the mouse is not recognized by the control. What's up with that? If I could fix that, I'd be happy and press on.
With respect to drawing my rich edit control on a CView, my main view is a CView and I draw CEdit controls on that view that function just fine. Before you ask why I didn't use a CFormView for that view, I draw other non-control stuff on my main view. So why will CEdit work on my primary CView but CRichEditCtrl won't work on my secondary CView?
Regards,
Lowell
-
September 22nd, 2010, 07:11 AM
#8
Re: Can't enter text in my CRichEditCtrl
 Originally Posted by lspecht
... created a CFormView and drew the rich edit control on that. The good news is that now I can modify the text in the control with the keyboard. The bad news, I can't select text or a new insertion point with the mouse. It's like the mouse is not recognized by the control. What's up with that? If I could fix that, I'd be happy and press on.
I never saw such a behavior! I've just created an SDI with CFormView, added reach edit control to it and run it: there is no any problem with text selection with mouse. 
Could you post *your* project (in zip archive and not including .ncb, .opt, .aps files nor Debug/Release folders) reproducing mouse selection problems?
Victor Nijegorodov
-
September 22nd, 2010, 07:43 AM
#9
Re: Can't enter text in my CRichEditCtrl
I'll see what I can do to post some code.
Regards,
Lowell
-
September 22nd, 2010, 07:53 AM
#10
-
September 22nd, 2010, 08:00 AM
#11
Re: Can't enter text in my CRichEditCtrl
I'll do that after I remove all the proprietary code from the project. In fact, I might just see if I can recreate the problem in a new project that has only the code to reproduce the problem. That would be easier and prove whether I've botched something up somewhere or something else is going on. I'll post when I have it.
Regards,
Lowell
-
October 5th, 2010, 09:17 AM
#12
Re: Can't enter text in my CRichEditCtrl
Sorry it took so long for me to get back on this. Life got in the way of coding. I hate it when that happens. 
I solved my problem. A thought had been nagging me that way back when I began this project, I had checked splitter windows though I had never implemented them. I commented out the CMainFrame::OnCreateClient override and Voila! Both mouse and keyboard work now for both CFormView and CScrollview versions of the Rich Edit Control. Probably works for the others as well. I appreciate the help.
Regards,
Lowell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|