Board index » cppbuilder » Strange 'DragDetect' Problem....

Strange 'DragDetect' Problem....


2004-11-01 06:56:41 PM
cppbuilder42
Hi all,
I have ListBoxMouseDown() event function, as it is it's working very well!
But if i add this code to the function -
if ( DragDetect( ((TListBox *)Sender)->Handle, Point( X, Y ) ) )
{
int n = 0;
n = n;
}
then the function is called ONLY for the first click on a ListBox line. When i first
click on a line the code enter into the function, but if i then click again on a line
then the program not entering to the function (i have a breakpoint on the start of it).
If i remove the 'DragDetect()' command from the function code then the problem is gone!
What can be the problem??
Thanks!
Ramy
 
 

Re:Strange 'DragDetect' Problem....

Sorry i described the problem in a wrong way. this is the problem -
I have this 2 functions for all of my ListBoxes -
void __fastcall TBaseForm::ListBoxClick( TObject *Sender )
{
HandleListBoxLineClick();
}
void __fastcall TBaseForm::ListBoxMouseDown( TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y )
{
DragDetect( ((TListBox *)Sender)->Handle, Point( X, Y ) );
}
If the 'DragDetect()' line is enabled then the program NEVER enter into the
ListBoxClick() evetn function, but if i disabled this line then the code enters the
ListBoxClick() function time after time.
So what can it be?
Thanks,
Ramy
 

Re:Strange 'DragDetect' Problem....

"Ramy" < XXXX@XXXXX.COM >сообщи?сообщила ?новостях следующе?
Quote

Sorry i described the problem in a wrong way. this is the problem -

I have this 2 functions for all of my ListBoxes -

void __fastcall TBaseForm::ListBoxClick( TObject *Sender )
{
HandleListBoxLineClick();
}

void __fastcall TBaseForm::ListBoxMouseDown( TObject *Sender, TMouseButton
Button, TShiftState Shift, int X, int Y )
{
DragDetect( ((TListBox *)Sender)->Handle, Point( X, Y ) );
}

If the 'DragDetect()' line is enabled then the program NEVER enter into
the
ListBoxClick() evetn function, but if i disabled this line then the code
enters the
ListBoxClick() function time after time.

So what can it be?

Thanks,
Ramy

---but if i disabled this line then the code enters the ListBoxClick()
function time after time.
"Usually OnClick occurs when the user presses and releases the left mouse
button with the mouse pointer over the control. This event can also occur
when
The user selects an item in a list by pressing an arrow key." VCL help.
When you click on whitespace TListBox not send OnClick event .
Now look at this code:
procedure TControl.WMLButtonUp(var Message: TWMLButtonUp);
begin
inherited;
if csCaptureMouse in ControlStyle then MouseCapture := False;
if csClicked in ControlState then // draw attention !!!
begin
Exclude(FControlState, csClicked);
if PtInRect(ClientRect, SmallPointToPoint(Message.Pos)) then Click;
end;
DoMouseUp(Message, mbLeft);
end;
i think if you insert this code
((TListBox *)Sender)->ControlState<<csClicked;
in you OnMouseDown event handler then OnClick event occurs every time when
you clicking on ListView even when you click in whitespace if you realy need
this.
---If the 'DragDetect()' line is enabled then the program NEVER enter into
the ListBoxClick() evetn function
I think it happen because 'DragDetect()' caputure mouse and windows not send
some message.
But when you select some intems in list box using arrow key OnClick event
must occurs.
And it must be said 'DragDetect()' if return false windows dont send
WM_LBUTTONUP message so in this case you need manually call OnClick or
Click.
Hence, i think you code must look at this:
void __fastcall TBaseForm::ListBoxMouseDown( TObject *Sender, TMouseButton
Button, TShiftState Shift, int X, int Y )
{
if(DragDetect( ((TListBox *)Sender)->Handle, Point( X, Y ) ))
{
// do drag
}
else
HandleListBoxLineClick();
}
Good luck.
 

{smallsort}