Board index » cppbuilder » Problem subclassing with LBN_SELCHANGE message

Problem subclassing with LBN_SELCHANGE message


2004-02-19 11:41:47 AM
cppbuilder31
Hello,
I am using subclassing to catch the LBN_SELCHANGE message so that I know
when a listbox's item selection has changed (thanks to Remy for this
suggestion a couple of months ago). And all this time I thought it was
working until just a few minutes ago, when I realized that the LBN_SELCHANGE
message is getting sent to the control whenever the user clicks any item in
the listbox, not just when the selection changes! This doesn't make sense,
and of course, doesn't offer much over a standard OnClick event.
Can anyone provide me with some insight to this problem? I've included my
subclass function below:
// detect and handle LBN_SELCHANGE message for status listbox
void __fastcall THideDisplayColumnsDialog::LBStatWndProc(TMessage &Message)
{
if ( Message.Msg == CN_COMMAND )
{
if ( HIWORD(Message.WParam) == LBN_SELCHANGE )
{
UpdateColumnList(); <<< we get here even if the mouse click occured
on the currently selected item!
}
}
OldLBStatWndProc(Message);
}
Thanks,
- Dennis
 
 

Re:Problem subclassing with LBN_SELCHANGE message

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
Quote
And all this time I thought it was working until just a few minutes
ago, when I realized that the LBN_SELCHANGE message is
getting sent to the control whenever the user clicks any item in
the listbox, not just when the selection changes!
You could try taking the current mouse coordinates and issuing an
LB_ITEMFROMPOINT message to determing the item being clicked on, and then
see if that item is already selected, and if so then ignore the event.
Gambit
 

Re:Problem subclassing with LBN_SELCHANGE message

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
news:40343079$ XXXX@XXXXX.COM ...

>And all this time I thought it was working until just a few minutes
>ago, when I realized that the LBN_SELCHANGE message is
>getting sent to the control whenever the user clicks any item in
>the listbox, not just when the selection changes!

You could try taking the current mouse coordinates and issuing an
LB_ITEMFROMPOINT message to determing the item being clicked on, and then
see if that item is already selected, and if so then ignore the event.
Thanks for the suggestion, again, Remy. I suppose I could do that, along
with any number of other "hacks", but that's just it...it would be a "hack"
to get around a problem that shouldn't exist in the first place. Why is the
LBN_SELCHANGE message getting sent when it shouldn't be?
- Dennis
 

{smallsort}

Re:Problem subclassing with LBN_SELCHANGE message

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
Quote
Why is the LBN_SELCHANGE message getting sent
when it shouldn't be?
You will have to ask Microsoft that. The VCL is not the one issuing that
notification, Windows is.
Gambit