-
August 31st, 2009, 08:47 AM
#1
Question about RichEdit: the style of underline
Hi, every one:
I have a problem with the underline style of richedit.let me descrip it in detail:
1,I input "abc" in richedit.
2,Then, i set only "c" with underline style."ab" remains the old style.
3,I select "abc" and set the bold or italic style to all of them.
4,"abc" has the style of bold or italic, and all the three characters have the underline style.This is confusing.The reasonable result is only the "c" has the underline style.
the code snippet i use is:
//set underline style
INT nStart, nEnd;
SendMessage( EM_GETSEL, (WPARAM)&nStart, (LPARAM)&nEnd, NULL );
CHARFORMAT2W cf;
ZeroMemory( &cf, sizeof( cf ) );
cf.cbSize = sizeof( cf );
SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf, NULL );
cf.dwMask |= CFM_UNDERLINE;
cf.dwEffects |= CFE_UNDERLINE;
SendMessage( EM_SETSEL, nStart, nEnd, NULL );
SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf, NULL );
//set bold style
INT nStart, nEnd;
SendMessage( EM_GETSEL, (WPARAM)&nStart, (LPARAM)&nEnd, NULL );
CHARFORMAT2W cf;
ZeroMemory( &cf, sizeof( cf ) );
cf.cbSize = sizeof( cf );
SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf, NULL );
cf.dwMask |= CFM_BOLD;
cf.dwEffects |= CFE_BOLD;
SendMessage( EM_SETSEL, nStart, nEnd, NULL );
SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf, NULL );
Is there any bug in my code?please help me.
-
September 1st, 2009, 10:38 AM
#2
Re: Question about RichEdit: the style of underline
1. Is your project compiled for Unicode?
Anyway, instead of using CHARFORMAT2W, you could use CHARFORMAT2.
If you look in richedit.h, you will see
#ifdef UNICODE
typedef CHARFORMAT2W CHARFORMAT2;
#else
typedef CHARFORMAT2A CHARFORMAT2;
#endif
2. It seems that the italic flag is set after:
SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf, NULL );
If your selection includes the "c" character, then this is not completely illogical to have that flag set.
A solution would be to have a loop for each character, where the individual format of each character would be retrieved and changed to bold.
-
September 1st, 2009, 08:44 PM
#3
Re: Question about RichEdit: the style of underline
olivthill2, thanks for your reply.
I solved this problem today just now, the CHARFORMAT works. it is confusing too for me.
Is this a bug of richedit?
Tags for this Thread
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
|