大伙帮我看看这个API的调用,GetCursorPos!

tavor 2003-10-20 12:40:09
public Point p=new point(0,0);
[DllImport ("user32.dll", EntryPoint="GetCursorPos")]
public static extern bool GetCursorPos(Point lpPoint);
private void button1_Click(object sender, System.EventArgs e)
{
GetCursorPos(p);
MessageBox.Show (p.X +" "+p.Y );
}

可是MessageBox确显示结果为“0 0”,

而GetCursorPos在MSDN中这么说
The GetCursorPos function retrieves the cursor's position, in screen coordinates.

Syntax

BOOL GetCursorPos( LPPOINT lpPoint
);
Parameters

lpPoint
[out] Pointer to a POINT structure that receives the screen coordinates of the cursor.
Return Value

If the function succeeds, the return value is nonzero.

这里的意思应该是说,返回的结果是鼠标在当前屏幕的位置,并把这个存储到参数的lpoint中。

请大伙帮 忙给我看看。
...全文
102 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gump09 2003-10-20
  • 打赏
  • 举报
回复
[DllImport ("user32.dll", EntryPoint="GetCursorPos")]
public static extern bool GetCursorPos(ref POINT lpPoint);
public struct POINT
{
int X,Y;
public int XX
{
set{this.X=value;}
get{return this.X ;}
}
public int YY
{
set{this.Y=value;}
get{return this.Y ;}
}
}
tavor 2003-10-20
  • 打赏
  • 举报
回复
返回的是一个指向POINT结构的指针,指针在C#中用IntPtr来表示,那我现在怎么用这个IntPtr来指向一个Point对象呢。也就是说,他返回了一个IntPtr,而我怎么把一个point用IntPtr来表示呢。晕啊!!
tavor 2003-10-20
  • 打赏
  • 举报
回复
噢,我看错了,MSDN的意思是说返回一个指向POINT结构的指针,我看看能不能解决,还请高手继续指点,因为小弟可能还是做不出来!
tavor 2003-10-20
  • 打赏
  • 举报
回复
我用 private void button1_Click(object sender, System.EventArgs e)
{
bool haslicked=false;
haslicked=(p);
if(haslicked)
{
MessageBox.Show (p.X +" "+p.Y );
}
}
我添加了hasliced布尔变量来探测是不是已经调用了GetCursorPos,然而没有弹出MessageBox这就说明根本没有调用GetCursorPos成功返回。谁能告诉我这是什么原因呢?

110,501

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧