11
11
12
12
// ----------------------------------------------------------------------------
13
13
14
- // This corresponds to the name of the Lua file (plugin_hwcursor.lua)
15
- // where the prefix 'CoronaPluginLuaLoad' is prepended.
16
14
CORONA_EXPORT int CoronaPluginLuaLoad_plugin_hwcursor (lua_State *);
17
15
18
16
// ----------------------------------------------------------------------------
19
17
20
18
CORONA_EXPORT
21
19
int luaopen_plugin_hwcursor (lua_State *L) {
22
-
23
- lua_CFunction factory = Corona::Lua::Open <CoronaPluginLuaLoad_plugin_hwcursor>;
24
- int result = CoronaLibraryNewWithFactory (L, factory, NULL , NULL );
25
-
20
+
21
+ lua_CFunction factory = Corona::Lua::Open<CoronaPluginLuaLoad_plugin_hwcursor>;
22
+ int result = CoronaLibraryNewWithFactory (L, factory, NULL , NULL );
23
+
26
24
if (result) {
27
25
const luaL_Reg kFunctions [] = {
28
26
{" initPlugin" , initPlugin},
27
+ {" freePlugin" , freePlugin},
29
28
{" loadCursor" , loadCursor},
30
29
{" freeCursor" , freeCursor},
31
30
{" showCursor" , showCursor},
32
31
{" hideCursor" , hideCursor},
33
32
{" resetCursor" , resetCursor},
34
33
{NULL , NULL }
35
34
};
36
-
35
+
37
36
luaL_register (L, NULL , kFunctions );
38
37
}
39
-
40
- return result;
38
+
39
+ return result;
41
40
}
42
41
43
42
// ----------------------------------------------------------------------------
44
43
45
44
HWND windowHandle;
46
- WNDPROC prevWndProc;
47
45
HCURSOR currentCursor;
48
46
bool cursorHidden = false ;
49
47
50
48
// ----------------------------------------------------------------------------
51
49
52
- LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
53
- LRESULT result;
54
-
55
- if (uMsg == WM_SETCURSOR) {
56
- if (currentCursor && !cursorHidden) {
57
- SetCursor (currentCursor);
58
- result = 1 ;
59
- }
60
- }
61
- else {
62
- if (uMsg == WM_NCDESTROY) {
63
- currentCursor = NULL ;
50
+ LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
51
+ if (uMsg == WM_SETCURSOR) {
52
+ if (currentCursor && !cursorHidden) {
53
+ SetCursor (currentCursor);
54
+ return true ;
64
55
}
65
- result = CallWindowProc (prevWndProc, hwnd, uMsg, wParam, lParam);
66
- }
67
-
68
- return result;
56
+ }
57
+ else if (uMsg == WM_DESTROY || uMsg == WM_NCDESTROY) {
58
+ RemoveWindowSubclass (windowHandle, &WindowProc, uIdSubclass);
59
+ }
60
+ return DefSubclassProc (hwnd, uMsg, wParam, lParam);
69
61
}
70
62
71
63
// ----------------------------------------------------------------------------
72
64
73
65
static int initPlugin (lua_State *L) {
74
66
windowHandle = GetForegroundWindow ();
75
- prevWndProc = (WNDPROC)SetWindowLongPtr (windowHandle, GWLP_WNDPROC, (LONG_PTR)&WindowProc);
67
+ SetWindowSubclass (windowHandle, &WindowProc, 1 , 0 );
68
+ return 0 ;
69
+ }
70
+
71
+ // ----------------------------------------------------------------------------
72
+
73
+ static int freePlugin (lua_State *L) {
74
+ RemoveWindowSubclass (windowHandle, &WindowProc, 1 );
76
75
return 0 ;
77
76
}
78
77
@@ -94,20 +93,20 @@ static int freeCursor(lua_State *L) {
94
93
// ----------------------------------------------------------------------------
95
94
96
95
static int showCursor (lua_State *L) {
97
- if (cursorHidden) {
98
- ShowCursor (true );
99
- cursorHidden = false ;
100
- }
96
+ if (cursorHidden) {
97
+ ShowCursor (true );
98
+ cursorHidden = false ;
99
+ }
101
100
return 0 ;
102
101
}
103
102
104
103
// ----------------------------------------------------------------------------
105
104
106
105
static int hideCursor (lua_State *L) {
107
- if (!cursorHidden) {
108
- ShowCursor (false );
109
- cursorHidden = true ;
110
- }
106
+ if (!cursorHidden) {
107
+ ShowCursor (false );
108
+ cursorHidden = true ;
109
+ }
111
110
return 0 ;
112
111
}
113
112
@@ -116,4 +115,4 @@ static int hideCursor(lua_State *L) {
116
115
static int resetCursor (lua_State *L) {
117
116
currentCursor = NULL ;
118
117
return 0 ;
119
- }
118
+ }
0 commit comments