ReactOS 0.4.15-dev-8127-g6338913
SetCursorPos.c File Reference
#include "precomp.h"
Include dependency graph for SetCursorPos.c:

Go to the source code of this file.

Classes

struct  _test_info
 

Macros

#define TEST(s, x, y)   ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);
 

Functions

LRESULT CALLBACK MouseLLHookProc (int nCode, WPARAM wParam, LPARAM lParam)
 
LRESULT CALLBACK MouseHookProc (int nCode, WPARAM wParam, LPARAM lParam)
 
static LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static HWND CreateTestWindow ()
 
void Test_SetCursorPos ()
 
void Test_DesktopAccess ()
 
 START_TEST (SetCursorPos)
 

Variables

static HHOOK hMouseHookLL
 
static HHOOK hMouseHook
 
static struct _test_info info []
 
static struct _test_info results [8]
 
static int test_no = 0
 

Macro Definition Documentation

◆ TEST

#define TEST (   s,
  x,
  y 
)    ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);

Function Documentation

◆ CreateTestWindow()

static HWND CreateTestWindow ( )
static

Definition at line 55 of file SetCursorPos.c.

56{
57 MSG msg;
58 WNDCLASSA wclass;
61
62 wclass.lpszClassName = "MouseInputTestClass";
63 wclass.style = CS_HREDRAW | CS_VREDRAW;
64 wclass.lpfnWndProc = WndProc;
65 wclass.hInstance = hInstance;
66 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
67 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
68 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
69 wclass.lpszMenuName = 0;
70 wclass.cbClsExtra = 0;
71 wclass.cbWndExtra = 0;
72 RegisterClassA( &wclass );
73 /* create the test window that will receive the keystrokes */
74 hWndTest = CreateWindowA( wclass.lpszClassName, "MouseInputTestTest",
83
84 /* flush pending messages */
85 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
86
87 return hWndTest;
88}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: SetCursorPos.c:47
#define msg(x)
Definition: auth_time.c:54
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define assert(x)
Definition: debug.h:53
static HWND hWndTest
Definition: input.c:63
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define CS_VREDRAW
Definition: winuser.h:658
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define SW_SHOWMAXIMIZED
Definition: winuser.h:773
#define COLOR_WINDOW
Definition: winuser.h:918
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define HWND_TOPMOST
Definition: winuser.h:1208
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4315
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOMOVE
Definition: winuser.h:1244
#define CS_HREDRAW
Definition: winuser.h:653
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define IDC_ARROW
Definition: winuser.h:687
#define SWP_NOSIZE
Definition: winuser.h:1245
#define IDI_APPLICATION
Definition: winuser.h:704
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
HWND WINAPI SetFocus(_In_opt_ HWND)
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE hInstance, _In_ LPCSTR lpIconName)
Definition: cursoricon.c:2091
#define PM_REMOVE
Definition: winuser.h:1196
BOOL WINAPI UpdateWindow(_In_ HWND)
#define PeekMessage
Definition: winuser.h:5830
#define CW_USEDEFAULT
Definition: winuser.h:225
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2121

Referenced by Test_SetCursorPos().

◆ MouseHookProc()

LRESULT CALLBACK MouseHookProc ( int  nCode,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 41 of file SetCursorPos.c.

42{
43 results[test_no].hook_called++;
44 return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
45}
static HHOOK hMouseHook
Definition: SetCursorPos.c:10
static int test_no
Definition: SetCursorPos.c:32
static struct _test_info results[8]
Definition: SetCursorPos.c:31
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)

Referenced by Test_SetCursorPos().

◆ MouseLLHookProc()

LRESULT CALLBACK MouseLLHookProc ( int  nCode,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 35 of file SetCursorPos.c.

36{
37 results[test_no].ll_hook_called++;
39}
static HHOOK hMouseHookLL
Definition: SetCursorPos.c:10

Referenced by Test_SetCursorPos().

◆ START_TEST()

START_TEST ( SetCursorPos  )

Definition at line 200 of file SetCursorPos.c.

201{
204}
void Test_DesktopAccess()
Definition: SetCursorPos.c:159
void Test_SetCursorPos()
Definition: SetCursorPos.c:90

◆ Test_DesktopAccess()

void Test_DesktopAccess ( )

Definition at line 159 of file SetCursorPos.c.

160{
161 HDESK hDesk, hDeskInitial;
162 POINT curPoint, initialPoint;
163 BOOL ret;
164
165 hDeskInitial = GetThreadDesktop(GetCurrentThreadId());
166 ok(hDeskInitial != NULL, "Failed to retrieve the initial desktop\n");
167
168 ret = GetCursorPos(&initialPoint);
169 ok(ret == TRUE, "GetCursorPos should succed\n");
170
171 hDesk = CreateDesktopW(L"testDesktop", NULL, NULL, 0, 0x01ff, NULL);
172 ok(hDesk != 0, "Failed to create a new desktop\n");
173 SetThreadDesktop(hDesk);
174 ok(GetThreadDesktop(GetCurrentThreadId()) == hDesk, "SetThreadDesktop had no effect\n");
175
176 SetLastError(0xdeadbeef);
177
178 ret = GetCursorPos(&curPoint);
179 ok(ret == FALSE, "GetCursorPos should fail\n");
180
181 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
182 "Expected ERROR_ACCESS_DENIED or 0xdeadbeef, got 0x%lx\n", GetLastError());
183 SetLastError(0xdeadbeef);
184
185 ret = SetCursorPos(2,2);
186 //ok(ret == FALSE, "SetCursorPos should fail\n"); // FIXME: fails on WHS testbot
187
188 ok(GetLastError() == 0xdeadbeef, "Wrong last error, got 0x%lx\n", GetLastError());
189
190 ret = GetCursorPos(&curPoint);
191 ok(ret == FALSE, "GetCursorPos should fail\n");
192
193 SetThreadDesktop(hDeskInitial);
194
195 ret = GetCursorPos(&curPoint);
196 ok(ret == TRUE, "GetCursorPos should succed\n");
197 //ok(curPoint.x == initialPoint.x && curPoint.y == initialPoint.y, "Mouse position changed\n");
198}
#define ok(value,...)
Definition: atltest.h:57
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned int BOOL
Definition: ntddk_ex.h:94
#define L(x)
Definition: ntvdm.h:50
int ret
HDESK WINAPI CreateDesktopW(LPCWSTR lpszDesktop, LPCWSTR lpszDevice, LPDEVMODEW pDevmode, DWORD dwFlags, ACCESS_MASK dwDesiredAccess, LPSECURITY_ATTRIBUTES lpsa)
Definition: desktop.c:473
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
HDESK WINAPI GetThreadDesktop(_In_ DWORD)
BOOL WINAPI SetThreadDesktop(_In_ HDESK)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2701
BOOL WINAPI SetCursorPos(_In_ int, _In_ int)
Definition: cursoricon.c:2693

Referenced by START_TEST().

◆ Test_SetCursorPos()

void Test_SetCursorPos ( )

Definition at line 90 of file SetCursorPos.c.

91{
92 HWND hwnd;
93 MSG msg;
94 int i;
95
98 ok(hMouseHook!=NULL,"failed to set hook\n");
99 ok(hMouseHookLL!=NULL,"failed to set hook\n");
100
101 test_no = 0;
102 SetCursorPos(1,1);
103 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
104
105 test_no = 1;
106 mouse_event(MOUSEEVENTF_MOVE, 2,2, 0,0);
107 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
108
111
112 test_no = 2;
113 SetCursorPos(50,50);
114 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
115
116 test_no = 3;
117 mouse_event(MOUSEEVENTF_MOVE, 100,100, 0,0);
118 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
119
120 test_no = 4;
121 SetCursorPos(50,50);
122 SetCursorPos(60,60);
123 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
124
125 test_no = 5;
126 SetCursorPos(50,50);
127 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
128 SetCursorPos(60,60);
129 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
130
131 test_no = 6;
132 mouse_event(MOUSEEVENTF_MOVE, 50,50, 0,0);
133 mouse_event(MOUSEEVENTF_MOVE, 60,60, 0,0);
134 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
135
136 test_no = 7;
137 mouse_event(MOUSEEVENTF_MOVE, 50,50, 0,0);
138 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
139 mouse_event(MOUSEEVENTF_MOVE, 60,60, 0,0);
140 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
141
142 for(i = 0; i< 8; i++)
143 {
144#define TEST(s,x,y) ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);
145 TEST("WH_MOUSE_LL", info[i].ll_hook_called, results[i].ll_hook_called);
146 /* WH_MOUSE results vary greatly among windows versions */
147 //TEST("WH_MOUSE", info[i].hook_called, results[i].hook_called);
148 //TEST("WM_MOUSEMOVE", info[i].mouse_move_called, results[i].mouse_move_called);
149 }
150
153
156
157}
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: SetCursorPos.c:41
#define TEST(s, x, y)
static HWND CreateTestWindow()
Definition: SetCursorPos.c:55
LRESULT CALLBACK MouseLLHookProc(int nCode, WPARAM wParam, LPARAM lParam)
Definition: SetCursorPos.c:35
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
HWND WINAPI SetCapture(_In_ HWND hWnd)
void WINAPI mouse_event(_In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ ULONG_PTR)
HHOOK WINAPI SetWindowsHookExW(_In_ int, _In_ HOOKPROC, _In_opt_ HINSTANCE, _In_ DWORD)
#define SetWindowsHookEx
Definition: winuser.h:5856
#define MOUSEEVENTF_MOVE
Definition: winuser.h:1183
#define WH_MOUSE_LL
Definition: winuser.h:44
#define WH_MOUSE
Definition: winuser.h:37
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by START_TEST().

◆ WndProc()

static LRESULT CALLBACK WndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 47 of file SetCursorPos.c.

48{
49 if(msg == WM_MOUSEMOVE)
50 results[test_no].mouse_move_called++;
51
52 return DefWindowProcA( hWnd, msg, wParam, lParam );
53}
HWND hWnd
Definition: settings.c:17
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_MOUSEMOVE
Definition: winuser.h:1775

Referenced by CreateTestWindow().

Variable Documentation

◆ hMouseHook

HHOOK hMouseHook
static

Definition at line 10 of file SetCursorPos.c.

Referenced by MouseHookProc(), and Test_SetCursorPos().

◆ hMouseHookLL

HHOOK hMouseHookLL
static

Definition at line 10 of file SetCursorPos.c.

Referenced by MouseLLHookProc(), and Test_SetCursorPos().

◆ info

Initial value:
=
{
{0,0,0},
{1,1,0},
{0,1,1},
{1,1,1},
{0,1,1},
{0,2,2},
{2,1,1},
{2,2,2},
}

Definition at line 19 of file SetCursorPos.c.

◆ results

◆ test_no

int test_no = 0
static

Definition at line 32 of file SetCursorPos.c.

Referenced by MouseHookProc(), MouseLLHookProc(), Test_SetCursorPos(), and WndProc().