PeekMessage没有收到消息? [英] PeekMessage not getting the message?

查看:175
本文介绍了PeekMessage没有收到消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义消息类型,用于调整我的窗口,调用 WM_NEED_RESIZE 。我已经定义在我的.h文件,并在我的.cpp文件中初始化。我也注册了我的 WindowProc 函数接受消息。下面是这些项目的代码:

I've created a custom message type for use in resizing my Window, called WM_NEED_RESIZE. I've defined it in my .h file, and initialized in my .cpp file. I have also registered my WindowProc function to accept messages. Here is the code for these items:

const uint32 WindowsGLWindow::WM_NEED_RESIZE = WM_USER + 100;
LONG WINAPI WindowsGLWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static PAINTSTRUCT ps;// do I need this?
    static sint32 newWidth = 0;
    static sint32 newHeight = 0;
    bool res = false;

    switch (uMsg) {
        case WM_PAINT:
            //display();
            BeginPaint(hWnd, &ps);
            EndPaint(hWnd, &ps);
            return 0;

        case WM_SIZE:
            //glViewport(0, 0, LOWORD(lParam), HIWORD(lParam));
            res = PostMessage(hWnd, WindowsGLWindow::WM_NEED_RESIZE, wParam,     lParam);
            std::cout << "WM_SIZE: " << res << std::endl;
            return 0;

        case WindowsGLWindow::WM_NEED_RESIZE:
            std::cout << "WindowsGLWindow::WM_NEED_RESIZE" << std::endl;
            break;

        case WM_CHAR:
            switch (wParam) {
                case 27: /* ESC key */
                    PostQuitMessage(0);
                    break;
            }
            return 0;

        case WM_CLOSE:
            PostQuitMessage(0);
            return 0;
    }

    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

在另一个函数中,我通过 PeekMessage 。)以收集所有消息。这是消息泵的代码片段:

In another function I am running through PeekMessage(..) to collect all messages. Here is the snippet of the message pump:

    MSG msg;
    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE) == TRUE) // maybe use GetInputState(?)     as well?
    {
        if (msg.message == WM_QUIT)
            retVal = -1;

        if (msg.message == WindowsGLWindow::WM_NEED_RESIZE) {
            uint32 newWidth = LOWORD(msg.lParam);
            uint32 newHeight = HIWORD(msg.lParam);

            std::cout << "PeekMessage: WindowsGLWindow::WM_NEED_RESIZE" <<         std::endl;

            // call resize only if our window-size changed
            if ((newWidth != width_) || (newHeight != height_)) {
                resize(newWidth, newHeight);
            }

            PostMessage(msg.hwnd, WM_PAINT, 0, 0);
        }

        switch (msg.message) {
            case WM_MOUSEMOVE:
                // Retrieve mouse screen position
                //int x = (short) LOWORD(lParam);
                //int y = (short) HIWORD(lParam);

                // Check to see if the left button is held down:
                //bool leftButtonDown = wParam & MK_LBUTTON;

                // Check if right button down:
                //bool rightButtonDown = wParam & MK_RBUTTON;
                break;
            case WM_LBUTTONDOWN:
            case WM_RBUTTONDOWN:
            case WM_LBUTTONUP:
            case WM_RBUTTONUP:
            case WM_KEYUP:
            case WM_KEYDOWN:
                /*
                switch (msg.wParam) {
                    case 'W':
                        // w key pressed
                        break;
                    case VK_RIGHT:
                        // Right arrow pressed
                        break;
                    default:
                        break;
                }
                */
                break;
        }

        TranslateMessage(&msg);
        DispatchMessage(&msg);

    }

我的问题是 WM_NEED_RESIZE c> 之后,在消息队列中只发现一次消息。之后,在 PeekMessage 。)。我真的不知道为什么会发生这种情况。 ,但是 WindowProc(..)方法(这不是真的帮助我)。

My problem is that the WM_NEED_RESIZE message is only found once in the message queue when the window first opens, after which it is never found in the message queue by my PeekMessage(..). I'm really not sure why this is happening. It is, however, being received by the WindowProc(..) method (which doesn't really help me). I would appreciate any help you guys could provide.

感谢

Jarrett

推荐答案


  1. 不要使用std :: cout期望在调试器中看到输出,请使用OutputDebugString 。

  1. Dont use std::cout expecting to see that output in your debugger, insted use OutputDebugString(); .

您需要将类指针传递给CreateWindowEx调用的最后一个参数,然后从WM_CREATE的LPARAM中传递给您的LPCREATESTRUCT中检索该指针,你的类指针将在结构体的lpCreateParmas feild中。将clas指针设置为窗口的GWLP_USERDATA,在任何其他消息调用中,调用GetWindowsLong,检索类指针,然后将消息,wparam和lparam全部传递给内部类消息处理程序。

You need to pass your class pointer to the last parameter of your call to CreateWindowEx, then retrieve that pointer from the LPCREATESTRUCT passed to you in the LPARAM of WM_CREATE, your class pointer will be in the lpCreateParmas feild of the struct. Set your clas pointer to the GWLP_USERDATA of your window, and on any other message calls , call GetWindowsLong , retrieve your class pointer, then pass the message, wparam, and lparam all off to your internal class message handler.

http://msdn.microsoft.com/en-us/library/ff381400%28v=VS.85%29.aspx

这篇关于PeekMessage没有收到消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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