15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CRichEditCtrl question

junping li -- junping@infolytica.qc.ca
Friday, November 01, 1996



Environment: VC++ 4.2-flat, WinNT 4.0

Hello,
I am in trouble to figure out how to make a CRichEditCtrl on a property
page work properly.

I made a property page using the dialog resource editor. I placed an
 Edit Box control on the page and used the ClassWizard to create the wrapper
class and mapped the variable m_richEditControl to this Edit control.
Then I manually changed the type of this variable to CRichEditCtrl.
Later on, I did the following in a handler function of the page class
to change the text font in the edit control:

   CFontDialog dlg;
   CHARFORMAT charFormat;
   if(dlg.DoModal() == IDOK)
   {
      dlg.GetCharFormat(charFormat);
      m_richEditControl.SetSel(0, -1);
      m_richEditControl.SetDefaultCharFormat(charFormat);
      m_richEditControl.SetSelectionCharFormat(charFormat);
   }

Unfortunately, I found out that both SetDefaultCharFormat and
SetSelectionCharFormat calls failed and hence, the text font
in the edit control was not changed.

Am I missing some obvious points here?

How can you replace an existing CEdit control with a CRichEditCtrl
to make use of the extra functionality? 

I looked at the WORDPAD sample and searched on the MSDN and MFC-FAQ,
no answer was found.

Thanks for your hints!
  
--
Have a nice day!

Junping   

--
Have a nice day!

Junping   



Michael Iles -- michaeli@dra.com
Wednesday, November 06, 1996

[Mini-digest: 5 responses]

> Environment: VC++ 4.2-flat, WinNT 4.0
>
> Hello,
> I am in trouble to figure out how to make a CRichEditCtrl on a property
> page work properly.
>
> I made a property page using the dialog resource editor. I placed an
> Edit Box control on the page and used the ClassWizard to create the   
wrapper
> class and mapped the variable m_richEditControl to this Edit control.
> Then I manually changed the type of this variable to CRichEditCtrl.
> Later on, I did the following in a handler function of the page class
> to change the text font in the edit control:

Hi Junping,

An edit control and a rich edit control are two different things. Two   
ways to get a rich edit control onto a dialog (or property page) are: (1)   
insert it as an OLE control from the component gallery, or (2) create it   
dynamically when you're initialising your dialog. In my opinion (2) is   
easier and faster.

The way I do it is to put a static text control on my dialog where I want   
the rich edit control to be, with an ID of (for example) IDC_RICHEDIT.   
Then in the OnInitDialog of your dialog class, do

 // The IDC_RICHEDIT static text box is a placeholder for the rich edit
 // control
 CWnd* pwnd = GetDlgItem( IDC_RICHEDIT );
 ASSERT( pwnd );

 // Convert the screen co-ordinates to client co-ordinates
 CRect rect;
 pwnd->GetWindowRect( &rect );
 ScreenToClient( &rect );
 VERIFY( m_ctrlRichEdit.Create( ES_MULTILINE | ES_AUTOVSCROLL |
  ES_SUNKEN | ES_NOHIDESEL | WS_VISIBLE | WS_TABSTOP | WS_CHILD |
WS_BORDER, rect, this, IDC_RICHEDIT ) );

That's it!

Mike.
-----From: "Doug Brubacher" 

     Disclaimer: I apologize in advance in the likelihood that any or all 
     of the following may in some one offend anyone.  If you are easily 
     offended please, stop reading now, there are lots of other MFC-L 
     questions and responses for you to read.
     
     I'll try to refrain from any abuse here, but this clearly is not a 
     question from an advanced or even an intermediate MFC/Windows 
     developer and as such does not belong on this list.
     
     Just because you defined you member variable as CRichEditCtrl that 
     doesn't mean the Window you are attached to was created with the 
     "RichEdit" window class.  You could have just as easily "manually 
     changed the type of this variable to CRichEditCtrl" from CButton or 
     CListBox or CScrollBar.  And your surprised it doesn't work?
     
     In the words of .B ekiM, read the documentation!  Start with "Rich 
     Edit Controls" in the Win32 SDK documentation and the CreateWindowEx 
     function (or CRichEditCtrl::Create()).
     
     Regards,
     
     Doug Brubacher
     DouglasB@msn.com

-----From: browkl@inel.gov (Kenneth L Brown)

I've noticed a similiar problem that appears to be a bug but maybe
someone else could shed some light on this.  When I use
SetSelectionCharFormat on a selection that starts at position 0 it does
nothing.  If the selection starts at position 1 or greater it works
fine. I had to create a work around where I checked if the selection
started at 0 in which case I cleared the selection, placed the cursor at
0 and used SetDefaultCharFormat.  It seems a pretty lousy way to do this
but I've not found a decent answer to this yet.  Anyone else?

Kenneth Brown
browkl@inel.gov

-----From: "Michael R Thompson" 

You have to set the cbSize member of the CHARFORMAT structure.

Mike.

-----From: Dong Chen 

Try to pass your charFormat as the first parameter in your CFontDialog as:
CFontdialog dlg(charFormat, ....);
This might solve your problem.





| Вернуться в корень Архива |