如何在C ++中获取中间点击事件 [英] How to get middlemouse click event in C++

查看:156
本文介绍了如何在C ++中获取中间点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何回应C ++ / OpenGL中的中键鼠标?

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

我知道它可能与 WM_MBUTTONDOWN 事件有关,但是我完全无法使用它。我也不熟悉回调函数所以如果它必须使用,可以彻底解释吗?任何人都可以告诉我如何实现中间鼠标点击事件的代码?

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?

推荐答案

您可以使用 WM _ 命令尝试并实现旧版本,但我认为这将更容易使用 GLUT

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;
}

如果你正在做一个简单的应用程序,GLUT就足够了。如果您要执行更复杂的操作,请尝试 freeglut openglut 。旧的基本GLUT不处理鼠标滚轮,因此,如果您想检查是否需要其中一个。

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.

这篇关于如何在C ++中获取中间点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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