How to get middlemouse click event in C++

给你一囗甜甜゛ 提交于 2019-12-20 06:29:38

问题


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 it. I am also unfamiliar with callback functions so if it has to be used, can it be thoroughly explained? Can anyone show me how to implement the code for middle mouse click event?


回答1:


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.



来源:https://stackoverflow.com/questions/21801585/how-to-get-middlemouse-click-event-in-c

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