Question about RichEdit: the style of underline
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Question about RichEdit: the style of underline

  1. #1
    Join Date
    Feb 2009
    Posts
    6

    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.

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    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.

  3. #3
    Join Date
    Feb 2009
    Posts
    6

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center