Board index » cppbuilder » Mouse up/down events

Mouse up/down events


2003-08-27 08:52:41 PM
cppbuilder65
My program should write the X coordinate of the mouse pointer when left
mouse
button is kept pressed and mouse is moved. The code for it is below:
...
bool down = false;
file://---------------------------------------------------------------------
------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
down = false;
}
file://---------------------------------------------------------------------
------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
down = true;
}
file://---------------------------------------------------------------------
------
void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
down = false;
}
file://---------------------------------------------------------------------
------
void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if(down)
Caption = "down";
else
Caption = "up";
if(!down)
return;
Label1->Caption = IntToStr(X);
}
void __fastcall TForm1::FormDblClick(TObject *Sender)
{
Form2->ShowModal();
down = false;
}
The problem occurs when user double-clicks the mouse button. After closing
Form2 down variable is equal to true and the program continues writing X
coordinate altough mouse button is not pressed. Setting down = false as
showed above does not solve the problem. Even calling FormMouseUp() manually
after Form2->ShowModal()
does not work. The program returns to normal operation only after pressing
and releasing the mouse button.
So, what's the solution, or is there a solution?
Thanks.
 
 

Re:Mouse up/down events

Quote
So, what's the solution, or is there a solution?
writing
void __fastcall TForm1::ListView2MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if(!Shift.Contains(ssLeft))
{
return;
}
...
}
has just solved the problem. Thanks anyway.