How to autodetect urls in RichEdit 2.0?

后端 未结 3 656
一个人的身影
一个人的身影 2021-01-28 21:26

When we have a RichEdit control and send it an EM_AUTOURLDETECT message with WPARAM set to TRUE, it nicely hightlights the detected URLs and sends the EN_LINK

3条回答
  •  温柔的废话
    2021-01-28 22:02

    Without knowing the format of the text you are trying to add to the control with SetWindowText and EM_STREAMIN I'm going to take a guess and say this might have something to do with the control's text mode. After setting the contents of the control try sending it a EM_GETTEXTMODE message and see if the TM_PLAINTEXT bit is set. If this is the case then try sending a EM_SETTEXTMODE message followed by EM_AUTOURLDETECT. Your code should look something like this:

    UINT textmode = (UINT)::SendMessage(handle_to_control, EM_GETTEXTMODE, 0, 0);
    if(textmode & TM_PLAINTEXT) {
        textmode &= ~TM_PLAINTEXT;    // Clear the TM_PLAINTEXT bit
        textmode |= TM_RICHTEXT;      // Set the TM_RICHTEXT bit
        if(::SendMessage(handle_to_control, EM_SETTEXTMODE, textmode, 0) != 0) {
            // Failed to set the text mode
        }
    }
    ::SendMessage(handle_to_control, EM_AUTOURLDETECT, TRUE, 0);
    

提交回复
热议问题