Opengl GLUT功能键停止刷新

Opengl GLUT功能键停止刷新,opengl,freeglut,Opengl,Freeglut,我在Windows 7下使用FreeGLUT 3.0.0(使用MSVC 2013从源代码构建)创建OpenGL上下文已有相当长一段时间了,但今天我遇到了一些奇怪的行为:当我按下F10键时,窗口停止刷新。以下是在MSVC 2013 Windows 7下实现这种奇怪行为的最低限度代码: #define FREEGLUT_STATIC #include <gl/glut.h> #include <iostream> using namespace std; void ini

我在Windows 7下使用FreeGLUT 3.0.0(使用MSVC 2013从源代码构建)创建OpenGL上下文已有相当长一段时间了,但今天我遇到了一些奇怪的行为:当我按下
F10
键时,窗口停止刷新。以下是在MSVC 2013 Windows 7下实现这种奇怪行为的最低限度代码:

#define FREEGLUT_STATIC
#include <gl/glut.h>
#include <iostream>

using namespace std;

void init()
{
    glClearColor(1.0, 0.0, 0.0, 0.0);
}

void display()
{
    cout << "a" << endl;
    glClear(GL_COLOR_BUFFER_BIT);
    glutSwapBuffers();
    glutPostRedisplay();
}

void reshapeFunc(int width, int height)
{
    glViewport(0, 0, 640, 480);
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(0, 0);
    glutCreateWindow("What?");

    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshapeFunc);

    glutMainLoop();
    return 0;
}
#定义FREEGLUT#u静态
#包括
#包括
使用名称空间std;
void init()
{
glClearColor(1.0,0.0,0.0,0.0);
}
无效显示()
{
cout如建议:

F10是进入windows菜单的快捷键。它应该足以不传递有效的HMENU句柄。不过我还没有测试过。如果F10不起作用,您可能希望避免使用它

如果您坚持,您可以通过捕获WM_SYSKEYDOWN而不将消息传递给DefWindowProc来获得F10。

添加一个标志以跳过
DefWindowProc()
调用
SC\u键菜单
事件,似乎可以“修复”问题:

...

    case WM_SYSCOMMAND :  /* 0x0112 */
        {
            /* HACKITTY HACK HACK HACK */
            int skipDefWindowProc = 0;
            {
                /*
                * We have received a system command message.  Try to act on it.
                * The commands are passed in through the "wParam" parameter:
                * The least significant digit seems to be which edge of the window
                * is being used for a resize event:
                *     4  3  5
                *     1     2
                *     7  6  8
                * Congratulations and thanks to Richard Rauch for figuring this out..
                */
                switch ( wParam & 0xfff0 )
                {
                case SC_SIZE       :
                    break ;

                case SC_MOVE       :
                    break ;

                case SC_MINIMIZE   :
                    /* User has clicked on the "-" to minimize the window */
                    /* Turning off the visibility is handled in WM_SIZE handler */

                    break ;

                case SC_MAXIMIZE   :
                    break ;

                case SC_NEXTWINDOW :
                    break ;

                case SC_PREVWINDOW :
                    break ;

                case SC_CLOSE      :
                    /* Followed very closely by a WM_CLOSE message */
                    break ;

                case SC_VSCROLL    :
                    break ;

                case SC_HSCROLL    :
                    break ;

                case SC_MOUSEMENU  :
                    break ;

                case SC_KEYMENU    :
                    skipDefWindowProc = 1;
                    break ;

                case SC_ARRANGE    :
                    break ;

                case SC_RESTORE    :
                    break ;

                case SC_TASKLIST   :
                    break ;

                case SC_SCREENSAVE :
                    break ;

                case SC_HOTKEY     :
                    break ;

#if(WINVER >= 0x0400)
                case SC_DEFAULT    :
                    break ;

                case SC_MONITORPOWER    :
                    break ;

                case SC_CONTEXTHELP    :
                    break ;
#endif /* WINVER >= 0x0400 */

                default:
#if _DEBUG
                    fgWarning( "Unknown wParam type 0x%x", wParam );
#endif
                    break;
                }
            }
#endif /* !defined(_WIN32_WCE) */

            /* We need to pass the message on to the operating system as well */
            if( skipDefWindowProc == 0 )
            {
                lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
            }
            break;
        }

...

在a中编辑有关您的环境的详细信息(操作系统、FreeGLUT版本、FreeGLUT是从源代码构建的还是使用二进制文件等)。@genpfault Thx。我已经用最短的可运行代码编辑了这个问题,问题仍然存在。感谢genpfault,我已经尝试了这个方法,并且确实有效:)