Control.MousePosition OK on emulator but wonky on device?

M

Mark

Hi all, I am relatively new to .NET CF but quite experienced otherwise. I
have noticed an odd behaviour in the result I get from Control.MousePosition
depending on whether I am running my project on the Pocket PC emulator or on
a real PPC. I have "applied" the relevent CF 1 SP2 .Cab files to both
environments too.

Here is what I am trying to do, I have a DataGrid and a ContextMenu for it.
In the ContextMenu Popup event, I am looking at Control.MousePosition to try
and work out where in the DataGrid the ContextMenu was instigated so that I
can customise the menu to the data that the user put the pen down on. I do
some offset calcs to map from the Screen co-ordinates that
Control.MousePosition gives you, back to control relative co-ordinates that
I then pass to the DataGrid.HitTest method. The code all works fine on the
emulator and correctly calculates the row of the datagrid that the
ContextMenu orignated from etc. but on a real PPC the results are all over
the place. If I dump out the physical screen co-ords into an entry in the
ContextMenu, the real PPC is just inexplicably wierd in the results I see.

If anyone seen this problem and have any wisdom for me, I would greatly
appreciate it.

Thanks for taking the time to read this.
 
G

Guest

I remember a person from MS (Kathy?) mentioned something on the problems of getting mouse pos on some devices related to the call GetMouseMovePoints API. You can try to use GetCursorPos. Something like that:

POINT pt = new POINT();

GetCursorPos(ref pt);

int x = pt.x;
int y = pt.y;
.....

public struct POINT
{
public int x;
public int y;
}

[DllImport("coredll.dll")]
public static extern int GetCursorPos(
ref POINT lpPoint );

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com|www.opennetcf.org

----- Mark wrote: -----

Hi all, I am relatively new to .NET CF but quite experienced otherwise. I
have noticed an odd behaviour in the result I get from Control.MousePosition
depending on whether I am running my project on the Pocket PC emulator or on
a real PPC. I have "applied" the relevent CF 1 SP2 .Cab files to both
environments too.

Here is what I am trying to do, I have a DataGrid and a ContextMenu for it.
In the ContextMenu Popup event, I am looking at Control.MousePosition to try
and work out where in the DataGrid the ContextMenu was instigated so that I
can customise the menu to the data that the user put the pen down on. I do
some offset calcs to map from the Screen co-ordinates that
Control.MousePosition gives you, back to control relative co-ordinates that
I then pass to the DataGrid.HitTest method. The code all works fine on the
emulator and correctly calculates the row of the datagrid that the
ContextMenu orignated from etc. but on a real PPC the results are all over
the place. If I dump out the physical screen co-ords into an entry in the
ContextMenu, the real PPC is just inexplicably wierd in the results I see.

If anyone seen this problem and have any wisdom for me, I would greatly
appreciate it.

Thanks for taking the time to read this.
 
B

bic

Alex Yakhnin said:
I remember a person from MS (Kathy?) mentioned something on the problems of getting mouse pos on some devices related to the call GetMouseMovePoints API. You can try to use GetCursorPos. Something like that:

POINT pt = new POINT();

GetCursorPos(ref pt);

int x = pt.x;
int y = pt.y;
....

public struct POINT
{
public int x;
public int y;
}

[DllImport("coredll.dll")]
public static extern int GetCursorPos(
ref POINT lpPoint );

I having same problem too.. I tried this in VB.NET

<DllImport("coredll.dll")> _
Public Shared Function GetCursorPos(ByRef lpPoint As myPOINT) As Integer
End Function

Public Structure myPOINT
Public x As Int16
Public y As Int16
End Structure

Dim pt As myPOINT = New myPOINT
GetCursorPos(pt)

But pt always produced 0,0 as the coordinate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top