EN_PROTECTED 和 RichEdit

发布于 2024-08-18 13:00:08 字数 220 浏览 9 评论 0原文

当尝试更改“受保护”文本时,EN_PROTECTED 通知消息将发送到 Rich Edit 控件的父级。这对我有用,我已经在 richedit20 和 richedit50 上尝试过了。对此受保护文本的任何更改都会立即触发 EN_PROTECTED 消息。 (设置它有点复杂,但我已经正确完成了。)

但是,文档说如果父级响应 EN_PROTECTED 消息返回非零,它将阻止受保护的文本被更改。这对我不起作用。

The EN_PROTECTED notify message is sent to the parent of a rich edit control when there is an attempt to change "protected" text. This works for me and I've tried it with both richedit20 and richedit50. Any change to this protected text immediately triggers the EN_PROTECTED message. (Its a little complicated to set it up, but I've done that correctly.)

However, the documentation says if the parent returns non zero in response to the EN_PROTECTED message, it will prevent the protected text from being changed. This is not working for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枉心 2024-08-25 13:00:08

我创建了一个简单的测试对话框测试应用程序,使用 MFC - 通过对话框编辑添加 richedit 控件,在应用程序初始化中添加对 AfxInitRichEdit 的调用,向对话框添加一些代码以将文本放入控件中(SetWindowText),选择第二个单词,应用CFE_PROTECTED效果,然后添加EN_PROTECTED的处理程序,在处理程序中我刚刚设置*pResult = TRUE

当我运行该应用程序时,一切正常;因为我无法修改受保护的单词,但我可以修改文本的其余部分。

不幸的是,这并没有让我们找到一个决定性的原因来解释为什么你的代码不起作用 - 从我看来它似乎是正确的。我想可能是 RichEdit20 dll 的版本 - 我的是 5.31.23.1224

I created a simple test dialog test app, using MFC - add the richedit control via the dialog edit, added a call to AfxInitRichEdit in the app initialization, added some code to the dialog to put text in the control (SetWindowText), selected the second word, applied the CFE_PROTECTED effects and then added a handler for EN_PROTECTED, in the handler i just set *pResult = TRUE.

When i ran the app it all worked fine; in that i was not able to modify the protected word but i could modify the rest of the text.

Unfortunately that really doesn't lead us to a conclusive reason as to why your code doesn't work - from what i can see it appears correct. Could be the version of the RichEdit20 dll i suppose - mine is 5.31.23.1224

素食主义者 2024-08-25 13:00:08

(致 Ruddy:下面的代码示例,如果它揭示了任何内容)

我最终只是从 EN_PROTECTED 处理程序中执行了 PostMessage(hwnd,EM_UNDO...) ,这就是我必须做的才能让它为我工作。返回 TRUE 从来没有完成任何事情,尽管我知道处理程序被击中并且仅针对受保护的文本。 (下面的ODS函数是OutputDebugString)。

但我在网上看到了多个示例(其中大多数是 MFC,有时是 DELPHI 或其他),据说只要在 EN_PROTECTED 处理程序中返回 TRUE 就可以阻止更改。

实际上,我的 Rich Edit 控件位于一个对话框中,但是使用 CreateWindowEx 创建的,因此我尝试通过 RC 文件对其进行初始化,但没有什么区别。 (诚​​然,我正在做的一些事情有点老派 - 对此感到抱歉。)但实际上,我尝试了一切方法来使 EN_PROTECTED 像其记录的那样工作,但没有任何效果 - 奇怪。

哦,好吧,EN_PROTECTED 处理程序中的 EM_UNDO 可以工作,所以我想我会坚持下去。

原始代码(添加了 EM_UNDO 调用):

case WM_NOTIFY: {

  NM_UPDOWN* nm = (NM_UPDOWN*)lParam;
  if ((nm->hdr.code == UDN_DELTAPOS) && (nm->hdr.idFrom == ID_UPD_ERR)) {
    int e = nm->iPos + nm->iDelta;
    SetWindowText(xml2->hStatMsg[1],xml2->ErrMsg(1,e));
    SetWindowText(xml2->hStatMsg[2],xml2->ErrMsg(2,e));
  }
  else if (wParam == ID_EDIT_A) {
    if (((LPNMHDR)lParam)->code == EN_PROTECTED) {
      ODS("EN_PROTECTED", (int)((ENPROTECTED*)lParam)->msg); 
      PostMessage(xml2->hImgXml2,EM_UNDO,0,0);
      return TRUE;
    }
    if (((LPNMHDR)lParam)->code == EN_SELCHANGE) {
      anchors_adjsel(xml2->hImgXml2);

    }      
  }

}
break;

(To Ruddy: code sample below if it reveals anything)

I eventually just did a PostMessage(hwnd,EM_UNDO...) from within the EN_PROTECTED handler and that is what I had to do to get this working for me. Returning TRUE never accomplished anything, though I know the handler was being hit and only for protected text. (the ODS function below is OutputDebugString).

But I've seen multiple examples on the web (most of them MFC however or sometimes DELPHI or something), where just returning TRUE in the EN_PROTECTED handler is said to prevent the change.

Actually, my Rich Edit Control was within a dialog but was being created with CreateWindowEx,so I tried intializing it through the RC file instead but it made no difference. (Some of the stuff I'm doing is kind of old school admittedly - sorry about that.) But actually I tried anything and everything to make EN_PROTECTED work like its documented and nothing worked - bizarre.

Oh well, EM_UNDO from within the EN_PROTECTED handler works, so guess I'll stick with that.

Original code (with the added EM_UNDO call):

case WM_NOTIFY: {

  NM_UPDOWN* nm = (NM_UPDOWN*)lParam;
  if ((nm->hdr.code == UDN_DELTAPOS) && (nm->hdr.idFrom == ID_UPD_ERR)) {
    int e = nm->iPos + nm->iDelta;
    SetWindowText(xml2->hStatMsg[1],xml2->ErrMsg(1,e));
    SetWindowText(xml2->hStatMsg[2],xml2->ErrMsg(2,e));
  }
  else if (wParam == ID_EDIT_A) {
    if (((LPNMHDR)lParam)->code == EN_PROTECTED) {
      ODS("EN_PROTECTED", (int)((ENPROTECTED*)lParam)->msg); 
      PostMessage(xml2->hImgXml2,EM_UNDO,0,0);
      return TRUE;
    }
    if (((LPNMHDR)lParam)->code == EN_SELCHANGE) {
      anchors_adjsel(xml2->hImgXml2);

    }      
  }

}
break;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文