graphics.h之鼠标
一、头文件
#include <graphics.h>
二、鼠标功能
以下截取自graphics.h的117行到145行
// Old mouse related functions旧鼠标相关功能 // Mouse message这个对应下面的UINT uMsg // WM_MOUSEMOVE Mouse moves鼠标移动 // WM_MOUSEWHEEL Mouse wheel is rotated鼠标滚轮旋转 // WM_LBUTTONDOWN Left mouse button is pressed按下鼠标左键 // WM_LBUTTONUP Left mouse button is released鼠标左键被释放 // WM_LBUTTONDBLCLK Left mouse button is double-clicked双击鼠标左键 // WM_MBUTTONDOWN Middle mouse button is pressed按下鼠标中键 // WM_MBUTTONUP Middle mouse button is released // WM_MBUTTONDBLCLK Middle mouse button is double-clicked // WM_RBUTTONDOWN Right mouse button is pressed // WM_RBUTTONUP Right mouse button is released // WM_RBUTTONDBLCLK Right mouse button is double-clicked struct MOUSEMSG { UINT uMsg; // Mouse message鼠标消息,对应上面Mouse message,就是不同的状态,用== != bool mkCtrl :1; // Indicates whether the CTRL key is pressed指示是否按下了 CTRL 键 bool mkShift :1; // Indicates whether the SHIFT key is pressed bool mkLButton :1; // Indicates whether the left mouse button is pressed指示是否按下鼠标左键 bool mkMButton :1; // Indicates whether the middle mouse button is pressed bool mkRButton :1; // Indicates whether the right mouse button is pressed short x; // The x-coordinate of the cursor光标的 x 坐标 short y; // The y-coordinate of the cursor short wheel; // The distance the wheel is rotated, expressed in multiples or divisions of 120轮转动的距离,以120的倍数或除数表示 }; _EASYX_DEPRECATE bool MouseHit(); // Indicates whether there are mouse messages表示是否有鼠标消息 _EASYX_DEPRECATE_WITHNEW(getmessage) MOUSEMSG GetMouseMsg(); // Get a mouse message. if mouse message queue is empty, wait.获取鼠标消息。 如果鼠标消息队列为空,请等待。 _EASYX_DEPRECATE_WITHNEW(peekmessage) bool PeekMouseMsg(MOUSEMSG *pMsg, bool bRemoveMsg = true); // Get a mouse message and return immediately获取鼠标消息并立即返回 _EASYX_DEPRECATE_WITHNEW(flushmessage) void FlushMouseMsgBuffer(); // Empty the mouse message buffer清空鼠标消息缓冲区
三、应用实例
MOUSEMSG m; // 定义鼠标消息 while (MouseHit()) // 检测当前是否有鼠标消息 { m = GetMouseMsg(); if (m.uMsg == WM_MOUSEMOVE) // 到鼠标移动时 { person.update(m.x, m.y); // person的位置等于鼠标所在的位置//自己定义的person.update } }