Hi there
How can I set my top left screen coordinate to a negative number? For example that the middle of my screen will return 0,0 when I get a mouse move/click reading.
Is there a way I can limit the positive and negative to a certain size?, also for example much larger than the current screen. Lets say my current screen gives -300, 300 for top left hand corner, can I limit that corner to -1000, 1000? How do I "see" the hidden place of the coordinates then? For example centre the screen now around -500,500
Hope my explenation is clear enough
Regards
Piet
Posted on 2004-03-09 04:18:17 by Pieter
Hi,
You can use "GetClientCrect" to get the usable screen dimensions of your window.
The upper left corner will be (0,0). Now you can start calculating:



invoke GetClientRect,hWnd,addr theRect
mov eax,theRect.right ; get width
shr eax,1 ; width / 2 = centerX
mov centerX,eax
mov eax,theRect.bottom ; get height
shr eax,1 ; height / 2 = centerY
mov centerY,eax

You want your center defined as (0,0):


push centerX
pop theRect.right
push centerY
pop theRect.bottom
neg centerX ; get negative value X
neg centerY ; get negative value Y
push centerX
pop theRect.left
push centerY
pop theRect.top
neg centerX ; restore the centerX value
nex centerY ; restore the centerY value

This rect manipulating could be useful for mathematical claculations.

If the mouse moves (similar to clicking):


LOCAL mouseposX:DWORD
LOCAL mouseposY:DWORD
...
.elseif uMsg==WM_MOUSEMOVE
mov eax,lParam ; coordinates are stored here
push ebx ; store ebx
xor ebx,ebx ; clear ebx
movzx ebx,ax ; get real x coordinate
sub ebx,centerX ; substract centerX
mov mouseposX,ebx ; our new X coordinate
shr eax,16 ; to HIWORD
xor ebx,ebx ; clear ebx
movzx ebx,ax ; get real y coordinate
sub ebx,centerY ; substract centerY
mov mouseposY,ebx ; our new Y coordinate
pop ebx ; restore ebx

At this point, you are able to display the needed coordinates. You can display them for example, in a taskbar.

Invisible coordinates - hidden screen parts:
If you use scrollbars (horizontal and vertical), you have to define the maximum dimensions. Here is the workflow:

- define maximum screensize, including hidden parts and store them in a rect structure
- generate the correct coordinate system (as shown above; center the middle as 0,0)
- store the middle in centerX/centerY
- get min/max values of each scrollbar
- get position of horizontal and vertical scrollbar (it's your factor for X/Y)
- get the visible area and store it in a rect (shown above; GetClientRect)
- with factors of X/Y, generate the coorinate rect for visible screen part
- calculate the mouse position as shown above (WM_MOUSEMOVE...)

If you change the view by using the scrollbars, the visible coordinate system will be calculated new.
If you have a size bordered window, don't forget to recalc the dimensions after WM_RESIZE etc. occurs.

Hope this will help you,
Pegasus

P.S.: the shown code may contain bugs...
Posted on 2004-03-09 05:55:14 by cu.Pegasus