-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMouse.cpp
executable file
·70 lines (55 loc) · 1.41 KB
/
CMouse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "CMouse.h"
CMouse::CMouse()
{
leftButtonDown = false;
}
POINT CMouse::getMouseLocation(HWND windowHandle)
{
POINT mousePosition;
POINT mouseLoc;
if(SUCCEEDED(GetCursorPos(&mousePosition)))
{
int xCo = mousePosition.x;
int yCo = mousePosition.y;
//Title Bar Co-Ordinates
TITLEBARINFO titleBarInfo;
titleBarInfo.cbSize = sizeof(TITLEBARINFO);
GetTitleBarInfo(windowHandle, &titleBarInfo);
RECT titleBarRect = titleBarInfo.rcTitleBar;
int titleLeft = titleBarRect.left;
int titleRight = titleBarRect.right;
int titleTop = titleBarRect.top;
int titleBottom = titleBarRect.bottom;
//get window location
RECT windowLocation;
int windowLeft;
int windowTop;
int windowRight;
int windowBottom;
if(SUCCEEDED(GetWindowRect(windowHandle, &windowLocation)))
{
windowLeft = windowLocation.left;
windowTop = windowLocation.top;
windowRight = windowLocation.right;
windowBottom = windowLocation.bottom;
}
//Calculate real mouse co-ordinates
int realMouseX = xCo - windowLeft - (windowRight - titleRight);
int realMouseY = yCo - titleBottom;
mouseLoc.x = realMouseX;
mouseLoc.y = realMouseY;
}
return mouseLoc;
}
void CMouse::setLeftButtonDown()
{
leftButtonDown = true;
}
void CMouse::setLeftButtonUp()
{
leftButtonDown = false;
}
bool CMouse::isButtonDown()
{
return leftButtonDown;
}