请帮忙看一下如下代码。。。。

cynwhm 2003-01-15 08:52:58

long PosX,PosY;
randomize();
PosX=random(this->Width);
PosY=random(this->Height);
SendMessage(this->Handle,WM_LBUTTONDOWN,PosX,PosY);
SendMessage(this->Handle,WM_LBUTTONUP,PosX,PosY);
为什么在鼠标按下的事件中Y值始终为零????
...全文
86 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingfish 2003-01-15
  • 打赏
  • 举报
回复
long PosX,PosY;
PosX = random(this->Width);
PosY = random(this->Height);
SendMessage(this->Handle,WM_LBUTTONDOWN,MK_LBUTTON,PosX + (PosY<<16));
SendMessage(this->Handle,WM_LBUTTONUP,MK_LBUTTON,PosX + (PosY<<16));
kingfish 2003-01-15
  • 打赏
  • 举报
回复
lParam
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

由于高位一直是0,所以Y值一直为0
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
randomize();
}

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
long pt = 0x00100020; //(16,32)
SendMessage(this->Handle,WM_LBUTTONDOWN,MK_LBUTTON,pt);
SendMessage(this->Handle,WM_LBUTTONUP,MK_LBUTTON,pt);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
ShowMessage("DOWN("+IntToStr(X)+","+IntToStr(Y)+")");
}
//---------------------------------------------------------------------------


void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
ShowMessage("UP("+IntToStr(X)+","+IntToStr(Y)+")");
}
//---------------------------------------------------------------------------

l_clove 2003-01-15
  • 打赏
  • 举报
回复
确实如此,每次都是把PosY的值当做X传进去,Y的值为0,是不是应该传一个Points进去?
cynwhm 2003-01-15
  • 打赏
  • 举报
回复
我就是找不到原因
kingfish 2003-01-15
  • 打赏
  • 举报
回复
不会啊

另外randomize不必每次都调用,放在formcreate中调用一次就行了
l_clove 2003-01-15
  • 打赏
  • 举报
回复
用MAKEWORD(PosY, PosX)行么?

1,222

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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