动态禁用窗口的消息系统 [英] Dynamically disabling message system of a window

查看:108
本文介绍了动态禁用窗口的消息系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有机会在运行时动态禁用特定窗口的消息传递系统?查看我的应用程序,我有一个CEdit控件(比如说Edit1)和一个处理程序例程,该例程将在EN_CHANGE通知中调用.

消息处理程序现在调用SetWindowTextW(或SetDlgItemTextW [都尝试过]),后者将WM_SETTEXT消息发布给其他CEdit控件(比如说Edit2).这是功能的一部分,必须按照提及的方式实施.

由于面向对象的设计,Edit2的EN_CHANGE消息处理程序与上面的子句相同.调用SetWindowTextW/SetDlgItemTextW,它为Edit1调用(相同的)消息处理程序,依此类推,等等……堆栈溢出.

这就是为什么我的问题是在调用SetWindowTextW/SetDlgItemTextW并随后启用消息处理之前禁用CEdit控件的消息处理.这样可以实现仅设置CEdit控件的Text,而不发出另一个WM_SETTEXT消息.

感谢您的提前帮助.

koni

Hi,

is there a chance to disable the messaging system for a particular window dynamically during runtime? Looking at my application, I have got a CEdit control (lets say Edit1) and a handler routine which will be called on EN_CHANGE notification.

The message handler now invokes SetWindowTextW (or SetDlgItemTextW [both tried]) which issues WM_SETTEXT message to other CEdit controls (lets say Edit2). This is part of the functionality and has to be implemented as mentioned.

The EN_CHANGE message handler for the Edit2 is the same as in the clause above due to objective oriented design. SetWindowTextW/SetDlgItemTextW is called which invokes the (same) message handler for Edit1 and so on and so on .... stack overflow.

Thats why my question to disable the message handling for an CEdit control before calling SetWindowTextW/SetDlgItemTextW and enabling the message handling afterwards. This would achieve that only the Text of the CEdit control will be set, but not issuing another WM_SETTEXT message.

Thanks for your help in advance.

koni

推荐答案

我没有完全理解您的问题.但据我所知,您正在这样做.

I did not completely understood your question.But upto my understanding you are doing this.

ON_EN_CHANGE(IDC_EDIT1, &CTestCEdit1Dlg::OnEnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, &CTestCEdit1Dlg::OnEnChangeEdit2)


在OnEnChangeEdit1中,您正在更改EDIT2的文本;在OnEnChangeEdit2中,您正在更改EDIT1的文本. 在对话框构造函数中声明一个Bool变量m_bool并将其初始化为true.after


in OnEnChangeEdit1 you are changing the text of EDIT2 and in OnEnChangeEdit2 you are changing the text of EDIT1.if it is then,
Declare a Bool variable m_bool and initialise it to true in dialog constructor.after

void CTestCEdit1Dlg::OnEnChangeEdit1()
{
    // TODO:  If this is a RICHEDIT control, the control will not
    // send this notification unless you override the CDialog::OnInitDialog()
    // function and call CRichEditCtrl().SetEventMask()
    // with the ENM_CHANGE flag ORed into the mask.
    if(m_bool == TRUE)
    {
        m_bool = FALSE;
        m_Edit2.SetWindowTextW(_T("Hi2"));
    }
     else
    {
        m_bool = TRUE;
    }
    // TODO:  Add your control notification handler code here
}







and

void CTestCEdit1Dlg::OnEnChangeEdit2()
{
    // TODO:  If this is a RICHEDIT control, the control will not
    // send this notification unless you override the CDialog::OnInitDialog()
    // function and call CRichEditCtrl().SetEventMask()
    // with the ENM_CHANGE flag ORed into the mask.
    if(m_bool == TRUE)
    {
        m_bool = FALSE;
        m_Edit1.SetWindowTextW(_T("Hi1"));
    }
    else
    {
        m_bool = TRUE;
    }
    // TODO:  Add your control notification handler code here
}
}


好吧,一种快速的方法是从同一个基类派生您的类,但不要将SetWindowText()包含到辅助CEdit中.

具有类似这样的派生方式(其中CEdit是您想要的通用基础):
Well, one quick way of doing this is to just derive your classes from the same base but don''t include the SetWindowText() to the secondary CEdit in one.

With a derivation sort of like this (where CEdit is whatever common base you want):
class CEditSetTxt : public CEdit
class CEditFinal  : public CEdit


覆盖PreTranslateMessage并按您的方式处理消息.

提示:最好是在最后调用默认的PreTranslateMessage
overwrite PreTranslateMessage and handle the messages your way.

Tip: best is to call the default PreTranslateMessage at the end


这篇关于动态禁用窗口的消息系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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