How to Monitor all ListBox messages?

Started by John Montenigro, July 13, 2009, 12:58:45 PM

Previous topic - Next topic

John Montenigro

I've got a ListBox, and I need to maintain a count of the total items, and a count of the selected items. These counts are to be displayed in 2 labels.

The following code does what I want, but only when the selection is changed by user mouse click. I need for these statements to be triggered whenever an item or selection count changes, even if changed by program code doing AddStrings...

My gut tells me I need a Callback Function, but I'm not sure how to implement one in FF.

(I actually looked on the ListBox Properties sheet, hoping to see a place to enter the name of a Callback function. Not there, but not a bad idea, eh? Would make it easy to tie a control to a custom callback routine...)


Any guidance would be appreciated!
Thanks,
-John

Function FRMMAIN_LSTDATES_LBN_SELCHANGE ( _
                                        ControlIndex  As Long,  _  ' index in Control Array
                                        hWndForm      As Dword, _  ' handle of Form
                                        hWndControl   As Dword, _  ' handle of Control
                                        idListBox     As Dword  _  ' identifier of listbox
                                        ) As Long
   FF_Control_SetText (HWND_FRMMAIN_LBLDATESINLIST, Str$(Listbox_GetCount(HWND_FRMMAIN_LSTDATES)))           
   FF_Control_SetText (HWND_FRMMAIN_LBLDATESSELECTED, Str$(Listbox_GetSelCount(HWND_FRMMAIN_LSTDATES)))       
End Function


John Montenigro

OK, so to answer my own question, here's what I've got working. It's not elegant, but it works.

I just wonder how busy my app will be with all that mouse checking...???
-John


Function FRMMAIN_CUSTOM ( _
                        hWndForm      As Dword, _  ' handle of Form
                        wMsg          As Long,  _  ' type of message
                        wParam        As Dword, _  ' first message parameter
                        lParam        As Long   _  ' second message parameter
                        ) As Long
   Select Case wMsg
   Case %WM_MOUSEMOVE   
   
         FF_Control_SetText (HWND_FRMMAIN_LBLDATESINLIST, Str$(Listbox_GetCount(HWND_FRMMAIN_LSTDATES)))           
         FF_Control_SetText (HWND_FRMMAIN_LBLDATESSELECTED, Str$(Listbox_GetSelCount(HWND_FRMMAIN_LSTDATES)))       
   End Select
End Function

John Montenigro

#2
I also figured out a solution that uses a Timer.

Would one of these solutions be preferred over the other?
-John

'--------------------------------------------------------------------------------
Function FRMMAIN_TIMER1_WM_TIMER ( _
                                 hWndForm      As Dword, _  ' handle of Form
                                 wTimerID      As Dword  _  ' the timer identifier
                                 ) As Long
'This code gets executed whenever the timer fires.
'The timer was set up by adding the Timer control to the form, and setting the interval (seconds) in the Properties tab.

   FF_Control_SetText (HWND_FRMMAIN_LBLDATESINLIST, Str$(Listbox_GetCount(HWND_FRMMAIN_LSTDATES)))           
   FF_Control_SetText (HWND_FRMMAIN_LBLDATESSELECTED, Str$(Listbox_GetSelCount(HWND_FRMMAIN_LSTDATES)))       
End Function

John Montenigro

Wow! when all three routines are active, the counters are VERY responsive!!
8)

TechSupport

Hi John,

I think that the Timer approach is a good one. I think that I would also create some Static or Global variables to track the ListBox count and Selection count. That way you can only update the Labels when the the counts change rather than everytime the Timer fires.

:)

John Montenigro

Hi Paul,
I understand the concept, but not the gains/benefits. Wouldn't comparing counters take as much time as just doing the counter updates?

OK, so maybe it's not for performance... ??

Or am I overloading some mechanism that I'm not aware of?

Thanks,
-John

TechSupport

Comparing the counters would save you having to update the Labels. The benefit to that is that if the Labels are updated, say every 200 milliseconds, then there will be a hell of a lot of screen flicker because the Labels will be redrawn constantly. You could keep the current approach but I know that sometimes screen flicker doesn't show on my development laptop as much as it does on some of my other computers. I guess that a lot of depends on the hardware you're using.

John Montenigro

Hadn't come across any flicker - on my laptop development machine  ;D

I'll play around with it.

Thanks!
-John