Board index » cppbuilder » How can I get the mouse position?

How can I get the mouse position?


2004-02-04 11:26:29 PM
cppbuilder94
I want to Response the Event of TListView's checkbox, But how can I get the
Mouse Position(MousePosX, MousePosY)?
Thank you.
void __fastcall TFormMy::ListViewMyClick(TObject *Sender)
{
THitTests MyHitTest = ListViewMy->GetHitTestInfoAt(MousePosX,
MousePosY);
if(MyHitTest.Contains(htOnIcon))
{
Application->MessageBox("OnIcon", "info", MB_OK);
}
}
 
 

Re:How can I get the mouse position?

"person" < XXXX@XXXXX.COM >wrote:
Quote
[...] But how can I get the Mouse Position(MousePosX, MousePosY)?
Use GetCursorPos in conjunction with ScreenToClient.
~ JD
 

Re:How can I get the mouse position?

"person" < XXXX@XXXXX.COM >wrote:
Quote
I want to Response the Event of TListView's checkbox, But how
can I get the Mouse Position(MousePosX, MousePosY)?
Do you really need the mouse position, or do you want to know
which item was checked or unchecked? Will the OnClickCheck
event, using the State property take care of what you need?
void __fastcall TForm1::CheckListBox1ClickCheck(TObject *Sender)
{
for(int i = 0; i < CheckListBox1->Items->Count; ++i){
if(CheckListBox1->State[i] == cbChecked)
DoCheckedMethod(i);
else
DoUnCheckedMethod(i);
}
}
 

{smallsort}

Re:How can I get the mouse position?

"TerryC" < XXXX@XXXXX.COM >wrote in message
Quote
Will the OnClickCheck event, using the State property
take care of what you need?
There is no such event in TListView, which he is actually using.
OnClickCheck is only available in TCheckListBox.
Gambit
 

Re:How can I get the mouse position?

"person" < XXXX@XXXXX.COM >wrote in message
Quote
I want to Response the Event of TListView's checkbox, But
how can I get the Mouse Position(MousePosX, MousePosY)?
Use the OnMouseDown/Up events:
TPoint Pos = Point(-1, -1);
void __fastcall TFormMy::ListViewMyMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( Button == mbLeft )
Pos = Point(X, Y);
}
void __fastcall TFormMy::ListViewMyMouseUp(TObject *Sender, TMouseButton
Button, TShiftState Shift, int X, int Y)
{
if( Button == mbLeft )
Pos = Point(-1, -1);
}
void __fastcall TFormMy::ListViewMyClick(TObject *Sender)
{
THitTests MyHitTest = ListViewMy->GetHitTestInfoAt(Pos.x, Pos.y);
//...
}
Otherwise you need to calculate the coordinates manually:
void __fastcall TFormMy::ListViewMyClick(TObject *Sender)
{
TPoint p = ListView1->ScreenToClient(Mouse->CursorPos);
/*
or alternatively:
POINT p;
::GetCursorPos(&p);
::ScreenToClient(ListView1->Handle, &p);
*/
THitTests MyHitTest = ListViewMy->GetHitTestInfoAt(p.x, p.y);
//...
}
Gambit
 

Re:How can I get the mouse position?

I really want to response the event, so I can popup a confirm dialog.
"TerryC" < XXXX@XXXXX.COM >дʼ
Quote

"person" < XXXX@XXXXX.COM >wrote:
>I want to Response the Event of TListView's checkbox, But how
>can I get the Mouse Position(MousePosX, MousePosY)?

Do you really need the mouse position, or do you want to know
which item was checked or unchecked? Will the OnClickCheck
event, using the State property take care of what you need?

void __fastcall TForm1::CheckListBox1ClickCheck(TObject *Sender)
{
for(int i = 0; i < CheckListBox1->Items->Count; ++i){
if(CheckListBox1->State[i] == cbChecked)
DoCheckedMethod(i);
else
DoUnCheckedMethod(i);
}
}