سؤال

I have very recently answered to the question about Creating TreeView with nodes and checkboxes.

While I was pondering how to properly process the case when treeview's node is checked when user pressing spacebar I ran into TVN_KEYDOWN notification.

My solution was tested in a dialog box and in a window procedure and both seem to work flawlessly.

Still, I have a dilemma of what should be my returned result. Here is the relevant excerpt from the documentation for TVN_KEYDOWN:

Return value

If the wVKey member of lParam is a character key code, the character will be used as part of an incremental search. Return nonzero to exclude the character from the incremental search, or zero to include the character in the search. For all other keys, the return value is ignored.

I have tried returning both results when testing if spacebar is pressed and haven't noticed any difference.

So I ask you the following questions:

  1. Can someone explain me what is the incremental search ?

  2. What is the difference when I include or exclude the tested character (spacebar) from incremental search ?

EDIT:

It seems that I have found an answer to first question. I have found an article on Wikipedia that explains what incremental search is.

It leaves only the second question to be answered.

END OF EDIT

Thank you.

Best regards.

هل كانت مفيدة؟

المحلول

It is most visible in a giant TreeView. The best example of one is the left panel in Regedit.exe. Expand HKCR and start typing to see the effect.

The implementation has changed across Windows versions, it used to be a lot less usable in XP. It is a UI blooper, there isn't any good way for the user to see that he mistyped a letter, to correct a typing mistake or to see that a search starts from scratch. Current versions of Windows use a timeout, automatically resetting the partially typed search phrase when you don't hit a key for a couple of seconds. Which is about as practical as it gets. It is certainly useful, just not very usable.

The only sane thing to do with TVN_KEYDOWN is nothing. Never add more ways to make it less predictable than it already is. Intentionally swallowing a keystroke of course makes it a lot less usable if it is a key the user really wanted to use. You certainly don't want to swallow a space, that's of course a valid character in tree node text. If the tree happens to not have any nodes with text that contains a space then you still don't want to swallow it, the control itself already does.

The notification would have been a lot more useful if it also passed the incremental search string that was collected or give a way to reset it. It just doesn't so that's water under the bridge. Consider handling it if you've created some kind of usability trap, very hard to come up with a practical example of one. You know it when you see it.

The only real use is to completely replace the search function. You'd then make your own rules and select a node yourself. And of course always return a non-zero value.

نصائح أخرى

You want only answer to the second question, so this is:

If you exclude spacebar from incremental search, you dont find trewview item with spacebar.

Note: You must disable TVS_CHECKBOXES style, because treeview wndproc handle spacebar different with this style set.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top