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

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值始终为零????
...全文
68 点赞 收藏 6
写回复
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)行么?
回复
发动态
发帖子
Windows SDK/API
创建于2007-08-02

1202

社区成员

C++ Builder Windows SDK/API
申请成为版主
社区公告
暂无公告