How to get middlemouse click event in C++

后端 未结 1 1609
别那么骄傲
别那么骄傲 2021-01-28 22:06

How can I respond to a middle mouse click in C++/OpenGL?

I know it may have to do with the WM_MBUTTONDOWN event however I am completely clueless with using

相关标签:
1条回答
  • 2021-01-28 22:57

    You can try and implement the oldschool version with the WM_ commands, but I think it'll be a lot easier to use GLUT (since it really makes life with OpenGL easier).

    #include <GL/glut.h>
    void myMouseHandleFunction(int button, int state, int x, int y){
       if(button==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) std::cout << "Pressed middle mouse button!";
    }
    
    
    int main(int argc, char *argv[]){
       glutInit(&argc, argv);
       glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
       glutInitWindowSize(500, 500);
       glutInitWindowPosition(300, 200);
       glutCreateWindow("Hello World!");
       glutMouseFunc(myMouseHandleFunction);
       glutMainLoop();
       return 0;
    }
    

    If you're doing a simple app, GLUT will be sufficient. If you wanna do something more complicated, try freeglut or openglut. The old, basic GLUT doesn't handle the mouse wheel, so if you want to check for that - you'll need one of those two.

    0 讨论(0)
提交回复
热议问题