views:

150

answers:

0

I am trying to use the PreMessageFilter method to do some basic logging to try and track down a "non reproducable" error we are having in a piece of our software.

I would like to be able to log when a user types text into a textbox, and when they change a selection in a combo box.

I have managed to use the WM_KEYDOWN message to log when something is typed into a text box, and the WM_LBUTTONDOWN to log when they are switching between controls. Having used the WM_LBUTTONDOWN, i can get the handle to the control they have selected and get the type of control.

I would like to trap the "SelectionChangeCommited" message and find out the value of the item that has been selected within the combo.

I have tried trapping WM_KILLFOCUS, and getting the details at that point, but for some reason this message never seems to be posted (even though Spy++ says that it is). Below is the code I am using

Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage

Select Case m.Msg
    Case &H100 ' KeyDown
        Dim conv As New KeysConverter
        AppendToStringBuilder(conv.ConvertFromInvariantString(m.WParam).ToString)
    Case &H202 'Mouse Up
        If thisControlsDictionary.ContainsKey(m.HWnd) Then
            Dim item As Control = thisControlsDictionary.Item(m.HWnd)
            AppendToStringBuilder(item.Name & " selected")
        End If
        Return False
    Case &H8 'WM_KILLFOCUS
         'This never seems to be hit.
         If TypeOf (item) Is ComboBox Then

         End If
    End Select

End Function

Does anyone know why I can not intercept this message, or if there is another message I should be looking for?