Rich Edit:CFM_LINK和CFE_LINK问题

时间:2015-01-19 17:19:25

标签: c++ windows winapi richedit

我尝试通过在CHARFORMAT2结构中发送带有CFM_LINK CFE_LINK值的字符格式化消息,将超链接添加到丰富的编辑控件中。

但似乎丰富的编辑不显示链接,如果我将一些其他值(如CFM_COLOR)与CFM_LINK一起发送,他们也不会产生任何影响....

这是我的代码:

LoadLibrary("Msftedit.dll");
/*rchwnd1 is a HWND, I declared it as a global variable*/
rchwnd1 = CreateWindowEx(0,"RICHEDIT50W",TEXT(""),
                         WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_READONLY|WS_VSCROLL, 
                         0, 30, rect.right, rect.bottom-30, 
                         hWnd, (HMENU)1, GetModuleHandle(NULL), NULL);
SendMessage(rchwnd1, EM_SETEVENTMASK, 0, ENM_LINK);

然后:

CHARFORMAT2 cf; CHARRANGE cr; cr.cpMax = -1; cr.cpMin = -1;
cf.dwMask = CFM_LINK; cf.dwEffects = CFE_LINK;
cf.cbSize = sizeof(CHARFORMAT2); 
SendMessage(rchwnd1,EM_EXSETSEL,0,(LPARAM)&cr); 
SendMessage(rchwnd1,EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf); //This function has returned 1, 
//so I think it wasn't failed, since if it fails it should return 0...
SendMessage(rchwnd1,EM_REPLACESEL,FALSE,(LPARAM)text.c_str()); //text is a std string which I've declared it before
/*If I write cf.dwMask = CFM_COLOR; cf.crTextColor = 0x0000FF;
  I will see a red text; but if I write
  cf.dwMask = CFM_COLOR|CFM_LINK; cf.crTextColor = 0x0000FF; dwEffects = CFE_LINK;
  I will not able to see a colored text...*/ 

我在WindowProc函数中编写了这些代码以检索EN_LINK通知:

    case WM_NOTIFY:{
        switch (((LPNMHDR)lParam)->code) {
            case EN_LINK: {
                //I wrote a MessageBox function there, so if WindowProc receive a EN_LINK message 
                //there would be a Message box, but actually it never appears
                break;
            }
        }
        break;
    }

0 个答案:

没有答案