dcsimg
Results 1 to 16 of 16

Thread: AutoComplete (Using the IAutoComplete interface)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    AutoComplete (Using the IAutoComplete interface)

    This project is intended to demonstrate how to implement the IAutoComplete interface to VB6.

    It provides more features than the "SHAutoComplete" API.

    For example to determine whether the drop-down list is dropped down or not.
    But the most important feature is that you can define custom sources. (by a simple string array)

    At design time (IDE) there is only one dependency. (AutoCompleteGuids.tlb)
    But for the compiled .exe there are no dependencies, because the .tlb gets then compiled into the executable.

    Notes:
    - There is no way to uninitialize the autocomplete object. You can only disable it. Setting the autocomplete object to nothing has therefore no effect and is not recommended. Anyhow, the autocomplete object will be automatically uninitialized when the TextBox (or any other edit control) receives the WM_DESTROY message.
    - Use modeless forms to enable the user to use the mouse on the drop-down suggest list as else only keyboard inputs will work on modal forms.

    List of revisions:
    Code:
    06-Nov-2018
    - Use of lightweight COM object IEnumString in AutoCompleteHandle.bas.
    - Modified AutoCompleteGuids.tlb. (compiled with same uuid)
      Unregister to old AutoCompleteGuids.tlb is not necessary, just overwrite the file.
    29-Dec-2013
    - Enhancement of the Disable and Enable method.
    13-Aug-2013
    - Fixed a bug that the application will crash when there is an empty string in the custom source.
    12-Aug-2013
    - First release.
    Attached Files Attached Files
    Last edited by Krool; Nov 6th, 2018 at 02:59 PM.

  2. #2
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,137

    Re: AutoComplete (Using the IAutoComplete interface)

    I've searched and searched for a solution to the custom lists issue but got nothing but a sniff with some C++ code on planet source code. I didn't understand the C++ code and I don't understand much of your vb6 code yet but you seem to have cracked it; well done! (so far...)
    Re. you comment 'The option flag 'AutoCompleteOptionUseTab' is not working when using the intrinsic VB TextBox control' can you expand on/ describe that fault at more length.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    Re: AutoComplete (Using the IAutoComplete interface)

    Quote Originally Posted by Magic Ink View Post
    Re. you comment 'The option flag 'AutoCompleteOptionUseTab' is not working when using the intrinsic VB TextBox control' can you expand on/ describe that fault at more length.
    The autocomplete object is subclassing the TextBox control.
    When the option flag 'AutoCompleteOptionUseTab' is set it watches for a tab key on the WM_KEYDOWN message.
    But the problem is that the intrinsic VB TextBox cannot trap the tab key. (Only when all control's TabStop properties are false; but that is not an option).

    This limitation can be solved when using a control that can trap such keys.
    For example in the TextBoxW control of my common controls project. There is a PreviewKeyDown event to solve this issue.

    Code:
    Private Sub TextBoxW1_PreviewKeyDown(ByVal KeyCode As Integer, IsInputKey As Boolean)
    If KeyCode = vbKeyTab Then IsInputKey = TestAutoComplete.DroppedDown()
    End Sub
    The ESC key can also be included. The autocomplete object notice this and closes the list without any activation of "Cancel" CommandButtons.

    Code:
    Private Sub TextBoxW1_PreviewKeyDown(ByVal KeyCode As Integer, IsInputKey As Boolean)
    If KeyCode = vbKeyTab Or KeyCode = vbKeyEscape Then IsInputKey = TestAutoComplete.DroppedDown()
    End Sub
    Last edited by Krool; Aug 15th, 2013 at 12:38 PM.

  4. #4
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,137

    Re: AutoComplete (Using the IAutoComplete interface)

    Thanks for that, and for info on the Esc key which was going to be the subject of my next question.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    Re: AutoComplete (Using the IAutoComplete interface)

    You may also include the Enter key (vbKeyReturn). Resulting that any "Default" CommandButton will not be fired when selecting an item from the drop-down list with the Enter key.

    Or another way: Allow the "Default" CommandButton to be fired when pressing Enter and trap the Enter key to inform the autocomplete object that the Enter key was pressed. (for correct behavior)
    But this solution is only necessary when there is any "Default" CommandButton on the form as else the enter key will be already treated as an input key.

    Code:
    Private Sub TextBoxW1_PreviewKeyDown(ByVal KeyCode As Integer, IsInputKey As Boolean)
    If KeyCode = vbKeyTab Or KeyCode = vbKeyEscape Or KeyCode = vbKeyReturn Then IsInputKey = TestAutoComplete.DroppedDown()
    End Sub
    
    ' The Call (or any other logic) should be within the KeyDown event and not in the PreviewKeyDown
    ' Do this only when there is any "Default" CommandButton.
    Private Sub TextBoxW1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then Call CommandDefault_Click
    End Sub
    Last edited by Krool; Aug 15th, 2013 at 12:37 PM.

  6. #6
    Junior Member
    Join Date
    Dec 2013
    Posts
    18

    Re: AutoComplete (Using the IAutoComplete interface)

    this is a very good attempt to handle the topic 'AutoComplete'.

    Concerning the way to uninitialize the autocomplete object ..

    The provided sub '.disable' is not working properly.
    It looks like that the "SHAutoComplete - API" is still active. (You could reproduce the situation very simple after a couple of inputs (and Key Down's))

    The SHAutoComplete - API could be disabled via the flag '&H20000000'.
    If you fire this flag with the api (SHAutoComplete) on the hwnd .. autocomplete is 100% dead.
    After this .. there is no way to turn it on again.
    Destroying the 'Autocomplete' (set to nothing / re .INIT) is not working properly as mentioned.

    In order to allow "toggle" at runtime .. 2 Textboxes are required. (-> Solution: Usercontrol)
    Is there a simple way to trigger the WM_DESTROY message - although the control is not destroyed?

    I appreciate your work here in the forum.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    Re: AutoComplete (Using the IAutoComplete interface)

    Quote Originally Posted by adix View Post
    The provided sub '.disable' is not working properly.
    I can't replicate the problem. When I use the sub '.Disable' the drop-down list is not anymore dropping down. The reference is indeed not terminated, only "disabled". That's why when you use the sub '.Enable' then it is like you never called '.Disable'.

  8. #8
    Junior Member
    Join Date
    Dec 2013
    Posts
    18

    Re: AutoComplete (Using the IAutoComplete interface)

    The Sub '.disable' is not 100% working .. when the type is FileSystem. (autocomplete list still pops up .. after a couple of folder - Inputs)
    A proper solution is to reset the options to 'AutoCompleteOptionNone' while you disable the autocomplete

    .Options = AutoCompleteOptionNone

    Now the Autocomplete works like a charm. Thank you

    [
    I've enhanced the AutoComplete.cls Enable / Disable Sub's.

    (Disable -> Backup current .options / set to None / Disable)
    (Enable -> Restore Options / Enable)
    ]

    I dont think that the used IE or shlwapi.dll is important.
    I could reproduce the effect on my primary Dev-Environment [Win XP SP3 (running within a VMWare instance)] and on my physical W7 / W8 Environments.
    Last edited by adix; Dec 24th, 2013 at 02:31 AM.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    Re: AutoComplete (Using the IAutoComplete interface)

    Quote Originally Posted by adix View Post
    The Sub '.disable' is not 100% working .. when the type is FileSystem. (autocomplete list still pops up .. after a couple of folder - Inputs)
    A proper solution is to reset the options to 'AutoCompleteOptionNone' while you disable the autocomplete
    Update released.
    Thanks

  10. #10
    New Member
    Join Date
    Sep 2014
    Posts
    1

    Re: AutoComplete (Using the IAutoComplete interface)

    hello, your Project is perfect, but in usercontrol keydow not work, not select in list, only mouse, do you know how do it

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    Re: AutoComplete (Using the IAutoComplete interface)

    Update released.

    Use of lightweight COM object IEnumString.
    Minor modification in TLB. (uuid the same; just replace file)

  12. #12
    Addicted Member
    Join Date
    May 2016
    Location
    China
    Posts
    131

    Re: AutoComplete (Using the IAutoComplete interface)

    Now only the first character can be used. Is there a way to drop down the list when entering any one character?
    QQ: 289778005

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    Re: AutoComplete (Using the IAutoComplete interface)

    Quote Originally Posted by ChenLin View Post
    Now only the first character can be used. Is there a way to drop down the list when entering any one character?
    What you mean with only first character? You can also drop down by code ".DroppedDown = True" or by key arrow down in the edit control.

  14. #14
    Addicted Member
    Join Date
    May 2016
    Location
    China
    Posts
    131

    Re: AutoComplete (Using the IAutoComplete interface)

    For example, the word Format, now only the input F will display the result, I mean to enter O or M, or any letter of the Format will display the result.
    QQ: 289778005

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,098

    Re: AutoComplete (Using the IAutoComplete interface)

    Quote Originally Posted by ChenLin View Post
    For example, the word Format, now only the input F will display the result, I mean to enter O or M, or any letter of the Format will display the result.
    And before the change to lightweight COM it was other or what?

  16. #16
    PowerPoster
    Join Date
    Oct 2013
    Posts
    3,214

    Re: AutoComplete (Using the IAutoComplete interface)

    I think ChenLin means that typing a single "O" should also jump to "Format" because of the "o" in it.
    But that's more a search function, not autocomplete.

    Autocomplete works as the following (to my knowledge!)

    Assuming the following auto complete list
    • Aqua
    • Black
    • Blue
    • Brown
    • Red


    If you type "B" the list scrolls to "Black"
    If then type "R" (giving the sequence "BR") the lists scrolls to "Brown"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width