消息处理程序未调用窗口过程

发布于 2024-11-25 00:11:29 字数 757 浏览 2 评论 0原文

我正在编写 Windows Api 包装器,但遇到了问题。我正在抽象窗口过程 (WndProc) 并编写一个静态 MsgHandler,它将调用我的 WinHandler 类的 WndProc。代码如下:

LRESULT CALLBACK WinHandle::MsgHandler(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    WinHandle* wnd = 0;

    if (msg == WM_NCCREATE)
    {
        ::SetWindowLong(hwnd,GWL_USERDATA,
                        long((LPCREATESTRUCT(lParam))->lpCreateParams));
    }

    wnd = (WinHandle*) (::GetWindowLong(hwnd,GWL_USERDATA));

    if (wnd)
        return wnd->WndProc(msg,wParam,lParam);
    else
        return ::DefWindowProc(hwnd,msg,wParam,lParam);
}

由于此函数是 static ,因此没有 this 指针,并且它与 WNDCLASSEX 完美配合,但由于某种原因它从不调用 wnd->WndProc() 并始终返回默认的窗口过程。需要帮助。怎么了?有谁知道更好的方法?

I am writing a Windows Api wrapper and I have run into a problem. I am abstracting the Window Procedure (WndProc) and wrote a static MsgHandler which would call the WndProc of my WinHandler class. Here is the code:

LRESULT CALLBACK WinHandle::MsgHandler(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    WinHandle* wnd = 0;

    if (msg == WM_NCCREATE)
    {
        ::SetWindowLong(hwnd,GWL_USERDATA,
                        long((LPCREATESTRUCT(lParam))->lpCreateParams));
    }

    wnd = (WinHandle*) (::GetWindowLong(hwnd,GWL_USERDATA));

    if (wnd)
        return wnd->WndProc(msg,wParam,lParam);
    else
        return ::DefWindowProc(hwnd,msg,wParam,lParam);
}

Since this functions is static , there is no this pointer and it works perfectly with WNDCLASSEX, but for some reason it never calls wnd->WndProc() and always returns the default window procedure. Need Help. What is wrong? Does anyone know a better approach?

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

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

发布评论

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

评论(1

风吹过旳痕迹 2024-12-02 00:11:29

当您收到 WM_CREATE 而不是 WM_NCCREATE 时调用 SetWindowLong。我认为 lpCreateParams 在 WM_NCCREATE 中无效。那是:

if (msg == WM_CREATE)
{
    ::SetWindowLong(hwnd,GWL_USERDATA,
                    long((LPCREATESTRUCT(lParam))->lpCreateParams));
}

Call SetWindowLong when you receive WM_CREATE, not WM_NCCREATE. I don't think lpCreateParams is valid in WM_NCCREATE. That is:

if (msg == WM_CREATE)
{
    ::SetWindowLong(hwnd,GWL_USERDATA,
                    long((LPCREATESTRUCT(lParam))->lpCreateParams));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文