erin021898
asked on
change Font Size & Color of Rich Edit during runtime
I want to develop a dialog based application with an rich edit control, whose Font Size and Color can be changed by pressing Buttons. I use the CHARFORMAT, SetDefaultCharFormat, SetSelCharFormat, and a custom function:
Format(CHARFORMAT &cf)
{
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD|CFM_COLOR;
cf.dwEffects =...
cf.yHeight = ...
.
.
}
After complier it, there appears a big "I" when the rich edit get focus. Moreover, the editor does not accept any input. What's wrong with it? Or someone can tell me another way to do the task?
Format(CHARFORMAT &cf)
{
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD|CFM_COLOR;
cf.dwEffects =...
cf.yHeight = ...
.
.
}
After complier it, there appears a big "I" when the rich edit get focus. Moreover, the editor does not accept any input. What's wrong with it? Or someone can tell me another way to do the task?
Note for both of ya: instead of typing all that code, note that there is an undocumented CFontDialog constructor that takes a CHARFORMAT structure as its first parameter. It is prototyped like this:
CFontDialog( const CHARFORMAT& charformat, DWORD dwFlags = CF_SCREENFONTS, CDC* pdcPrinter = NULL, CWnd* pParentWnd = NULL );
Then use the undocumented CFontDialog::GetCharFormat (...) to get the user selected CHARFORMAT.
The quickest way to do it is to the following steps (Error checking left out):
GetSelectionCharFormat( m_cfFormat );
pFontDlg = new CFontDialog( m_cfFormat );
if( pFontDlg -> DoModal() == IDOK )
{
pFontDlg -> GetCharFormat( m_cfFormat );
SetSelectionCharFormat( m_cfFormat );
}
This will NOT work with RichEdit2.0 (CHARFORMAT2 structure).
-=- James.
CFontDialog( const CHARFORMAT& charformat, DWORD dwFlags = CF_SCREENFONTS, CDC* pdcPrinter = NULL, CWnd* pParentWnd = NULL );
Then use the undocumented CFontDialog::GetCharFormat
The quickest way to do it is to the following steps (Error checking left out):
GetSelectionCharFormat( m_cfFormat );
pFontDlg = new CFontDialog( m_cfFormat );
if( pFontDlg -> DoModal() == IDOK )
{
pFontDlg -> GetCharFormat( m_cfFormat );
SetSelectionCharFormat( m_cfFormat );
}
This will NOT work with RichEdit2.0 (CHARFORMAT2 structure).
-=- James.
Almost forgot... If you want to have pre-set CHARFORMAT structures to apply formats with, create a little app that uses the CFontDialog stuff above, and when you get the CHARFORMAT that you want, store it someplace (file, registry, etc), and then you can use them in your application. No need for the user to select something.
-=- James.
-=- James.
ASKER
I want to "visual" change the char in the edit box. When the user click the button, the user can see the change at the same time.
You haven't specified your request clearly. I cannot answer a question whose owner isn't making it enough clear. May be next time I will try to help you, but this time, sorry.
Ahmed
Ahmed
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CFontDialog fntdlg;
if(fntdlg.DoModal()==IDOK)
{
TEXTMETRIC tm;
CClientDC dc(this);
GetTextMetrics(dc.m_hDC,&t
CHARFORMAT cf;
cf.cbSize=sizeof(CHARFORMA
cf.dwMask=CFM_BOLD|CFM_COL
cf.dwEffects=0;
if(fntdlg.IsBold())cf.dwEf
if(fntdlg.IsItalic())cf.dw
if(fntdlg.IsUnderline())cf
if(fntdlg.IsStrikeOut())cf
cf.yHeight=tm.tmHeight*fnt
cf.crTextColor=fntdlg.GetC
cf.bPitchAndFamily=fntdlg.
cf.szFaceName[LF_FACESIZE]
SetCharFormat(cf);
}
I have used this code in one of my projects and it worked.
Ahmed Kamal