EN_UPDATE 不发送到子类编辑框过程 [英] EN_UPDATE does not send to the subclassed edit box procedure

查看:39
本文介绍了EN_UPDATE 不发送到子类编辑框过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经子类化了编辑控制窗口过程,然后发现它不再发送了 EN_UPDATE.

I have subclassed Edit control window procedure and then found out it no longer sent the EN_UPDATE.

我是否遗漏了什么,有人可以建议我解决这个问题吗?

Am I missing something , and could somebody suggest me a workaround on this one?

LRESULT CALLBACK EditBoxProc_textbox3( HWND hwnd, UINT message , WPARAM wParam, LPARAM lParam )
{
  int previous_position = 0 ;
  WCHAR previous_text [1024];
  WCHAR current_text [1024];


  switch (message)
  {

    case WM_CREATE:
       previous_text[0] = L'\0';
       current_text[0] = L'\0';
       break;

    case EN_SETFOCUS:
      // :TODO: read the current text of the textbox3 and update textbox2 
      // text according to it.                                             //
      Edit_Enable(hwndTextBox2,FALSE);
      break;

    case EN_UPDATE:
      MessageBox(NULL,L"EN_UPDATE", lpszAppName,MB_OK);
      GetWindowText( hwndTextBox3,  current_text ,1024);
      if( is_valid_textbox3(current_text))
      {
        wcscpy(previous_text,current_text);
        previous_position = LOWORD(Edit_GetSel(hwndTextBox3));
        update_textbox2(NULL);

      }else
      {
        SetWindowText(hwndTextBox3, previous_text );
        Edit_SetSel(hwndTextBox3,previous_position, previous_position);
      }  
      break;

    case EN_KILLFOCUS:
      Edit_Enable(hwndTextBox2,TRUE);
      break;
    default:
      break;
  }
  return CallWindowProc(edit_old_wndproc_textbox3,hwnd,message,\
           wParam,lParam);
}

推荐答案

然后发现它不再发送 EN_UPDATE

and then found out it no longer sent the EN_UPDATE

它从一开始就没有发送 EN_UPDATE.它是一条实际作为 WM_COMMAND 消息发送的通知消息.并且它被发送到 Edit 控件的父级,而不是控件本身.EN_SET/KILLFOCUS 也是如此.

It never sent EN_UPDATE in the first place. It is a notification message that's actually sent as a WM_COMMAND message. And it is sent to the parent of the Edit control, not the control itself. Same goes for EN_SET/KILLFOCUS.

这里的设计理念是编辑控件可以简单地放在对话框上.使对话框以某种方式运行的自定义代码写在父窗口的过程中,不需要对控件进行子类化.这很好,但它使创建具有自己行为的自定义编辑控件变得困难.或者换句话说,它很难组件化编辑控件.EN_SET/KILLFOCUS 通知不是问题,您可以简单地检测它们对应的 WM_SET/KILLFOCUS 消息.但是你会在 EN_UPDATE 上碰壁,控件不会向自己发送任何类似的消息.只有父窗口可以检测到它.

The design philosophy here is that an Edit control can simply be put on, say, a dialog. And the custom code that makes the dialog behave in a certain way is written in the parent window's procedure with no requirement to subclass the control. Which is fine but it makes it difficult to create a customized edit control that can have its own behavior. Or in other words, it makes it hard to componentize an edit control. The EN_SET/KILLFOCUS notifications are not a problem, you can simple detect their corresponding WM_SET/KILLFOCUS messages. But you'll hit the wall on EN_UPDATE, the control doesn't send any message like that to itself. Only the parent window can detect it.

将编辑控件组件化是非常可取的,并且由 Winforms 和 Qt 等面向对象的类库积极追求.他们有一个控件的类包装器(TextBox、QLineEdit),它有一个可以被覆盖的虚拟方法(OnTextChanged、changeEvent),以便可以将控件自定义为具有自己行为的派生类.并生成一个任何人都可以订阅的事件(又名信号),而不仅仅是父级(TextChanged、textChanged).为了使这项工作,父窗口需要参与.当它收到 WM_COMMAND 消息时,它必须将通知回显给子控件.通过发送回特殊消息或调用子类上的虚拟方法.

Componentizing an edit control is pretty desirable and actively pursued by object-oriented class libraries like Winforms and Qt. They have a class wrapper for the control (TextBox, QLineEdit) that has a virtual method that can be overridden (OnTextChanged, changeEvent) so that the control can be customized into a derived class with its own behavior. And generate an event (aka signal) that anybody can subscribe to, not just the parent (TextChanged, textChanged). To make that work, the parent window needs to participate. When it gets the WM_COMMAND message, it must echo the notification back to the child control. Either by sending a special message back or by calling a virtual method on the child class.

您当然也可以自己实现,尽管您有责任重新发明这样的类库.考虑改用现有的.

You can of course implement this yourself as well, albeit that you are liable of reinventing such a class library. Consider using an existing one instead.

这篇关于EN_UPDATE 不发送到子类编辑框过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆