The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on July 15, 2009, 10:48:43 AM

Title: Mouse movement
Post by: Farabi on July 15, 2009, 10:48:43 AM
Im making a mouse function, the task is I want to know if the value of X and Y are positive or negative and after it determined it the cursor reseted to the center of application, Its work, but when I set the cursor to the window center it keep give me a positive value. I am missing something?

.elseif uMsg==WM_MOUSEMOVE
mov eax,lParam
movzx edx,ax
mov MOUSE.x,edx
shr eax,16
movzx edx,ax
mov MOUSE.y,edx


invoke GetWindowRect,hWnd,addr r
invoke ClipCursor,addr r
invoke GetCursorPos,addr p
mov ecx,r.right
sub ecx,r.left
shr ecx,1
add ecx,r.left
mov px,ecx

mov ecx,r.bottom
sub ecx,r.top
shr ecx,1
add ecx,r.top
mov py,ecx

mov edx,px
cmp p.x,edx
jg no_need
fld rotY
fadd CFLT(0.1)
fstp rotY
invoke SetWindowText,hWnd,CADD("add")
jmp next_s
no_need:
fld rotY
fsub CFLT(0.1)
fstp rotY
invoke SetWindowText,hWnd,CADD("Sub")

next_s:

jmp next2
mov ecx,py
cmp p.y,ecx
jg @f
fld rotX
fadd CFLT(0.1)
fstp rotX
jmp next2
@@:
fld rotX
fsub CFLT(0.1)
fstp rotX
next2:

mov ecx,px
.if p.x!=ecx
invoke SetCursorPos,px,p.y
.endif
mov ecx,py
.if p.y!=ecx
invoke SetCursorPos,px,py
.endi .elseif uMsg==WM_MOUSEMOVE
mov eax,lParam
movzx edx,ax
mov MOUSE.x,edx
shr eax,16
movzx edx,ax
mov MOUSE.y,edx


invoke GetWindowRect,hWnd,addr r
invoke ClipCursor,addr r
invoke GetCursorPos,addr p
mov ecx,r.right
sub ecx,r.left
shr ecx,1
add ecx,r.left
mov px,ecx

mov ecx,r.bottom
sub ecx,r.top
shr ecx,1
add ecx,r.top
mov py,ecx

mov edx,px
cmp p.x,edx
jg no_need
fld rotY
fadd CFLT(0.1)
fstp rotY
invoke SetWindowText,hWnd,CADD("add")
jmp next_s
no_need:
fld rotY
fsub CFLT(0.1)
fstp rotY
invoke SetWindowText,hWnd,CADD("Sub")

next_s:

jmp next2
mov ecx,py
cmp p.y,ecx
jg @f
fld rotX
fadd CFLT(0.1)
fstp rotX
jmp next2
@@:
fld rotX
fsub CFLT(0.1)
fstp rotX
next2:

mov ecx,px
.if p.x!=ecx
invoke SetCursorPos,px,p.y
.endif
mov ecx,py
.if p.y!=ecx
invoke SetCursorPos,px,py
.endif
Title: Re: Mouse movement
Post by: ramguru on July 15, 2009, 11:04:40 AM
Of course it will give only positive values.
What do you expect :} you even prevent mouse cursor from moving outside client area (if I'm right .. with ClipCursor)
You'll get negative values only when you'll use SetCapture AND u r holding mouse button while moving AND mouse cursor is outside active window area
Title: Re: Mouse movement
Post by: Farabi on July 15, 2009, 01:11:08 PM
Quote from: ramguru on July 15, 2009, 11:04:40 AM
Of course it will give only positive values.
What do you expect :} you even prevent mouse cursor from moving outside client area (if I'm right .. with ClipCursor)
You'll get negative values only when you'll use SetCapture AND u r holding mouse button while moving AND mouse cursor is outside active window area

No I mean, a less value than the center of the application, I called that a negativ value or a jmp less.
Title: Re: Mouse movement
Post by: Farabi on July 15, 2009, 01:40:50 PM
Nevermind, I found the mistake.