News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Combo Boxes and CBN_DROPDOWN

Started by Jimg, April 05, 2007, 03:35:15 PM

Previous topic - Next topic

Jimg

Sometimes when I receive the CBN_DROPDOWN message for a combo box, I want to present the user with a browse window rather than the dropdown list.  What is the proper method for canceling the dropdown list so it doesn't show?  I've tried sending the control a CB_SHOWDROPDOWN,FALSE message but it doesn't seem to have any effect.  e.g.
.elseif word ptr[wParam+2]==CBN_DROPDOWN
    .if word ptr[wParam]==MyComboBoxID
        inv SendMessage,hStartingFolder,CB_SHOWDROPDOWN,FALSE,0
        inv BrowseForFile
        xor eax,eax
        ret


Edit:
ok, I've found that if I use PostMessage rather thaan Sendmessage for the SHOWDROPDOWN message, it closes the dropdown, but the combobox still has control and thinks it is still getting input.  If I try to type in another control in this state, the cursor disappears and I'm really messed up.  I guess what I really need is a way to send a cancel to the control after getting the CBN_DROPDOWN message and I just can't seem to find it.

zooba

Have you tried sending CBN_SELENDCANCEL? (Goes to the parent via WM_COMMAND)

Alternatively, you may want to try posting (ie. PostMessage) the CB_SHOWDROPDOWN message followed by a user message which will call the BrowseForFile. This gives the window a chance to handle the messages involved before blocking (I assume BrowseForFile blocks). This also reduces the risk of creating a recursive condition.

In terms of the 'proper' method for what you are doing, the 'correct' way (correct meaning most intuitive for everyone involved) is to hide the combobox and replace it with a textbox and a button with '...' as the caption. As for the proper way to cancel a dropdown, I doubt there is one. If a user comes across a dropdown that doesn't behave like a dropdown, they'll get confused :wink

Cheers,

Zooba :U

Jimg

QuoteHave you tried sending CBN_SELENDCANCEL? (Goes to the parent via WM_COMMAND)
I got the impression that this was something the combo box sent out and would not respond to.

QuoteAlternatively, you may want to try posting (ie. PostMessage) the CB_SHOWDROPDOWN message followed by a user message which will call the BrowseForFile. This gives the window a chance to handle the messages involved before blocking (I assume BrowseForFile blocks). This also reduces the risk of creating a recursive condition.
This is what I tried when I got in the condition I described in my edit above.  I commented out the BrowseForFile call entirely but the combo still thinks it's active.

QuoteIn terms of the 'proper' method for what you are doing, the 'correct' way (correct meaning most intuitive for everyone involved) is to hide the combobox and replace it with a textbox and a button with '...' as the caption. As for the proper way to cancel a dropdown, I doubt there is one. If a user comes across a dropdown that doesn't behave like a dropdown, they'll get confused :wink
This was the first thing I did and is my preferred method, but I just couldn't get it to look any good visually.  The shadowing where the textbox is sunken and the button raised just looks ungood when next to each other.  Putting the button over the end of the textbox to try to make it look like the combobox wasn't very successful either with trying to keep the button on top of the textbox when the user clicks in the textbox.  This is, however, the simpler method if I can get it to look better without too much fiddling around.

But thanks for the suggestions, keep 'em comming.

Jimg

In vb it's as simple as
Private Sub Combo1_DropDown()
Text1.SetFocus  ' close the dropdown
End Sub

It seems like I really should be able to do this in assembly! Changing the focus in masm leaves the dropdown on the screen.  There is just something very basic (no pun intended) I'm missing here.

Jimg

#4
Zooba-

QuoteAlternatively, you may want to try posting (ie. PostMessage) the CB_SHOWDROPDOWN message followed by a user message which will call the BrowseForFile. This gives the window a chance to handle the messages involved before blocking (I assume BrowseForFile blocks). This also reduces the risk of creating a recursive condition.

I don't know why this didn't work the first time I tried it, but it seems to be working now.  Many thanks  :U

p.s.
The CB_SHOWDROPDOWN is totally unnecessary.  Simply setting the focus elsewhere in the code for the user message does the trick.

zooba

Another way of constructing the textbox with the button is to use a static control with SS_ETCHEDFRAME and SS_WHITERECT, then put an edit control just inside it (without specifying a border) leaving space for the button.

Alternatively, try creating your window with WS_CLIPCHILDREN or the edit control with WS_CLIPSIBLINGS. You may also have to play with EM_SETMARGINS to stop the text from going underneath the button.

Cheers,

Zooba :U

Jimg

I gave the static WS_EX_CLIENTEDGE and turned it off for the edit.  Lined everything up and it looks just like the combo box.  Yesterday I was just so frustrated I forgot to look at the ex_styles and so couldn't get anywhere.  Amazing what a good nights sleep will do.  Thanks for prodding me along, Zooba, I appreciate it :wink