How to get middlemouse click event in C++

岁酱吖の 提交于 2019-12-02 08:42:18

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!