简体   繁体   English

CallWindowProc-奇怪的行为

[英]CallWindowProc - strange behavior

It definetly works, but in a strange way. 它确实可以工作,但是以一种奇怪的方式。

I'm replacing RichEdit control's procedure with 我用替换RichEdit控件的过程

    WNDPROC g_OrigREditText = 
(WNDPROC)SetWindowLongPtr( g_hwnd_RichEdit, GWLP_WNDPROC, (LONG_PTR)REditWndProc);

Then, I SendMessage to RichEdit control using EM_REPLACESEL msg, and the text appears in the RichEdit control as it should. 然后,我使用EM_REPLACESEL msg将消息发送到RichEdit控件,并且文本应按原样出现在RichEdit控件中。 But when I replace standard procedure with my own, and process EM_REPLACESEL in mine own procedure, then the following scenario happens. 但是,当我用自己的程序替换标准过程,并在我自己的过程中处理EM_REPLACESEL时,就会发生以下情况。 Here's the code: 这是代码:

LRESULT CALLBACK REditWndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
{
    switch( msg )
    {

    case EM_REPLACESEL:
    {
        int sdfsdf = 0;

        CallWindowProc( (WNDPROC)g_OrigREditText, hwnd, msg, wp, lp );
        break;
    }


    default:
        return DefWindowProc( hwnd, msg, wp, lp);
        break;
    }

    return 0;

}

Ok, I send an EM_REPLACESEL message to the RichEdit as usual and it works well, cos I catch operation pointer in "case EM_REPLACESEL" block. 好的,我像往常一样向RichEdit发送EM_REPLACESEL消息,并且运行良好,因为我在“ case EM_REPLACESEL”块中捕获了操作指针。

Then CallWindowProc should do its job by passing parameters to the next procedure in the chain, but instead nothing happens, the text doesn't appear in a RichEdit control. 然后,CallWindowProc应该通过将参数传递给链中的下一个过程来完成其工作,但是什么也没有发生,因此文本不会出现在RichEdit控件中。 Looks like something prevent the message to be passed to old procedure, but! 看起来有些东西阻止消息传递到旧程序,但是! if I replace g_OrigREditText with REditWndProc, then I catch the same UINT msg again, so it definetely pass parameters further, like it should. 如果我用REditWndProc替换g_OrigREditText,那么我会再次捕获相同的UINT消息,因此它像定义的那样进一步明确地传递参数。

So what's wrong with CallWindowProc or with my code, where should I dig to fix the problem? 那么,CallWindowProc或我的代码出了什么问题,我应该在哪里挖掘以解决问题?

The whole thing is called "subclassing" and this can be useful . 整个过程称为“子类化”, 很有用。

usually there are more events that occurs in relating with one message so change your code to this 通常,与一条消息相关的事件更多,因此将代码更改为此

LRESULT CALLBACK REditWndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
{
    if( msg == EM_REPLACESEL)
    {
        // whatever you want
        return TRUE;// comment this 
                    // if you want to give it to the original proc.
    }

    return CallWindowProc( g_OrigREditText, hwnd, msg, wp, lp );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM