Problem with ownerdrawn listbox

Started by Anonymous, June 02, 2004, 05:46:03 PM

Previous topic - Next topic

Anonymous

I'm most probably doing this incorrectly, but I can't figure out what's wrong so I need to ask for advice.

I've put an ownerdrawn listbox onto a form. The listbox has integral ownerdrawn checkboxes. I've used the Form_CUSTOM() routine to send the right ownerdrawn messages to a Proc() which handles the ownerdrawn stuff - works perfectly, I get a nicely painted listbox with checkboxes.

However, I'm trying to trap on the left mouse button or space bar in order to set/reset the checkboxes in the listbox, and I'm having problems with this.

The WM_LBUTTONDOWN and WM_KEYDOWN events do not appear in the Form_CUSTOM() event procedure, so I can't intercept them there.

There is a WM_LBUTTONDOWN event available for the form. But that doesn't receive the button event if the click happens inside the listbox.

There is a Listbox_WM_LBUTTONDOWN event, but that doesn't pass me the pointer to the DRAWITEMSTRUCT structure that I need to figure out whether the mouse is over the checkbox or not. I can't find information on where the DRAWITEMSTRUCT is held in memory either. Presumably somewhere in Windows extra bytes associated with the control?

There is no WM_KEYDOWN event available in FireFly, either at the form or control level, and as I'm not seeing that event in other Procs() that I've tried trapping within I'm into head-scratching mode about how I can ever trap for specific key presses!

I'm probably being blinded by being too close to the coal face, but I appear to be up a gum tree without a paddle here. I can handle the raw  WndProc() messages no problem - but FireFly appears to put a layer in above the message level and doesn't expose all of the messages which I would normally trap for.

Andrew

TechSupport

Hi Andrew,

I know exactly what you're talking about and have done so for portions of FireFly code.

I will email you some code to look at. Hopefully it will make things clearer for you.

Anonymous

Thanks for the code Paul. I was actually using a copy of that code anyway. I am still having problems.

Paraphrasing the code I am using:

Function LBproc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

  select case wMsg
     case %WM_DRAWITEM
        ... draw listbox item.

     case %WM_KEYDOWN
        ... key pressed.

     case %WM_LBUTTONDOWN
        ... left mouse button clicked.
  end select

  function = %FALSE
End Function

Then the custom event for my form:

Function MYFORM_CUSTOM (hWndForm As Dword, wMsg As Long, wParam As Dword, lParam As Long) As Long

  If wParam = IDC_MYFORM_MYLISTBOX Then
     Call LBproc(HWND_MYFORM, wMsg, wParam, lParam)
  End If
End Function

The %WM_DRAWITEM message works perfectly. But the %WM_KEYDOWN and %WM_LBUTTONDOWN never appear.

I have used WinSight to try and trace what is going on, and focussed on the messages for the ownerdrawn listbox. I am seeing no messages at all regarding key presses or mouse clicks, though the listbox properly responds to clicking on a new item etc.

I'm obviously missing something obvious!

Andrew

Anonymous

Further information....

I added some code to see if WM_KEYDOWN or WM_LBUTTONDOWN were being passed to the CUSTOM event for the form - using a BEEP statement to indicate that the message had been received, and no such messages were passed to the CUSTOM event.

I then instigated a BEEP statement in the forms WM_LBUTTONDOWN event, and got the required beep when I clicked somewhere on the form (but not in the listbox...).

No form event available for selection for WM_KEYDOWN so I can't try that.

This suggest to me as though FireFly might be stubbing out messages that it hasn't been explicitly requested to deal with. If that's right then using an ownerdrawn listbox containing checkboxes can never work. Maybe I'm inferring this wrong however.....

Andrew

Anonymous

I have spent 2 days trying to resolve this ownerdrawn listbox problem and I'm out of ideas on what to do next.

I'm wondering if anyone has actually managed to get an ownerdrawn listbox with checkboxes working with FireFly?

Andrew

TechSupport

... I am looking into it right now. I'll give you more comments shortly.

Anonymous

I'll remove the rope from the lamppost pending your reply..... ;)

Andrew

TechSupport

Andrew,

Something that just jumped out at me.....

Why are you dealing with the keypress of the FORM, when you should be handling the keypresses of the LISTBOX ??????

For example, you are capturing the messages in the MYFORM_CUSTOM message. No wonder you are not getting the ListBoxes messages.

The DRAWITEM message gets posted to the parent window (FORM), but other messages like KEYDOWN and LBUTTONDOWN get sent right to the ListBox.

I bet that if you add this code the the MYFORM_MYLISTBOX_CUSTOM message then you should be back in the game:



     Call LBproc(HWND_MYFORM_MYLISTBOX, wMsg, wParam, lParam)



Also, in your LBproc make sure you realize that the incoming HWnd may be the Form handle or the ListBox handle depending on which CUSTOM message has called it.

Please let me know if any of this makes sense.....

Anonymous

Thanks Paul!
A huge improvement - I am now getting the WM_LBUTTONDOWN message and updating the checkbox in the listbox exactly as I want.

However the WM_KEYDOWN event seems to be still missing in action. I've tried trapping for it in the CUSTOM code for both dialog and listbox, but it doesn't appear to be exposed by FireFly. There is no WM_KEYDOWN event in the dropdown combobox so it doesn't appear as though I can respond to that message.

Andrew

TechSupport

Quote from: kazmaxHowever the WM_KEYDOWN event seems to be still missing in action. I've tried trapping for it in the CUSTOM code for both dialog and listbox, but it doesn't appear to be exposed by FireFly. There is no WM_KEYDOWN event in the dropdown combobox so it doesn't appear as though I can respond to that message.

I just created a new, simple, project with just a Command button and a ListBox. I click ont he Command button which loads 10 strings into the ListBox (via ff_listbox_addstring).

I added the following code to the editor:


Function FORM1_LIST1_CUSTOM (ControlIndex As Long, hWndForm As Dword, hWndControl As Dword, wMsg As Long, _
        wParam As Dword, lParam As Long) As Long

If wMsg = %WM_KEYDOWN Then  '%WM_CHAR Then
  Beep
End If

End Function


If I use the %WM_KEYDOWN code then I get a beep whenever a key is pressed (including the arrow keys). If the %WM_CHAR is used then only non-virtual keys such as letters, numbers, spacebar, etc... generate a beep.

You are not subclassing the ListBox in your code, are you???? If you are, then there is no need for you to subclass the ListBox.

Anonymous

Thanks Paul - I'll look into this. The forest is beginning to clear a bit now.

I'm not subclassing the listbox. Tried that, didn't work, went off and did something else instead.

Andrew