Jump to content

Recommended Posts

Posted

I try to learn from predicttext.udf example.

when I try use GuiCtrlCreateEdit like shown below, it works
 

#include-once
#include <GUIConstants.au3>
#include 'PredictText.au3'

$hGUI = GUICreate('Predict Text + GUI Learn', 220, 60)

$Input_Payment_Method = GUICtrlCreateEdit("",10, 10, 200, 50)
    ;GUICtrlSetData($Input_Payment_Method, "Wood|Metal|Plastic", "")

GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState()

Local $iGUIGetMsg
While 1
    $iGUIGetMsg = GUIGetMsg()
    Switch $iGUIGetMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    If _WinAPI_HiWord($wParam) = $EN_SETFOCUS Then

        Local $_Words1[3] = ['Wood', 'Metal', 'Plastic']

        Switch $lParam
            Case GUICtrlGetHandle($Input_Payment_Method)
                _RegisterPrediction($lParam, $_Words1)
        EndSwitch

    EndIf
    Return $GUI_RUNDEFMSG

EndFunc

But, if I change it to GuiCtrlCreateCombo like shown below, it doesn't work
 

#include-once
#include <GUIConstants.au3>
#include 'PredictText.au3'

$hGUI = GUICreate('Predict Text + GUI Learn', 220, 60)

$Input_Payment_Method = GUICtrlCreateCombo("",10, 10, 200, 50)
    GUICtrlSetData($Input_Payment_Method, "Wood|Metal|Plastic", "")

GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState()

Local $iGUIGetMsg
While 1
    $iGUIGetMsg = GUIGetMsg()
    Switch $iGUIGetMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    If _WinAPI_HiWord($wParam) = $EN_SETFOCUS Then

        Local $_Words1[3] = ['Wood', 'Metal', 'Plastic']

        Switch $lParam
            Case GUICtrlGetHandle($Input_Payment_Method)
                _RegisterPrediction($lParam, $_Words1)
        EndSwitch

    EndIf
    Return $GUI_RUNDEFMSG

EndFunc


How to make it works?

Thank You

Posted

Hey HezzelQuartz

Just had a quick look, and it looks like the UDF is specific to edit controls unfortunately. 

The UDF works by subclassing. So in a nutshell, all messages sent to a "registered" control are intercepted by _New_WndProc, and that is where the magic happens . 
_New_WndProc contains a bunch of code that is specific to edit controls.

So yeah, it's probably possible to get comboboxes working, but it involves modifying the guts of the UDF.

PS.  Just a quick hint if you're still having a play - EN_SETFOCUS is a notification specific to edit controls, so this block of code won't fire for a combobox!

4 hours ago, HezzelQuartz said:
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    If _WinAPI_HiWord($wParam) = $EN_SETFOCUS Then

        Local $_Words1[3] = ['Wood', 'Metal', 'Plastic']

        Switch $lParam
            Case GUICtrlGetHandle($Input_Payment_Method)
                _RegisterPrediction($lParam, $_Words1)
        EndSwitch

    EndIf
    Return $GUI_RUNDEFMSG

EndFunc
Posted

Yep, good call Nine,

That mechanism should be a bit simpler to modify too if you ever had the need.

Just because I got caught out...
The example in the helpfile references <Extras\WM_NOTIFY.au3>. If you click "open this script"  from the helpfile it'll work, otherwise the library lives here:
"C:\Program Files (x86)\AutoIt3\Examples\Helpfile\Extras\WM_NOTIFY.au3"

Posted

💡 Just as further information:
Related post, regarding <Extras\WM_NOTIFY.au3>: 

@water mentioned the issue (and ticket) with the missing Extras\WM_NOTIFY.au3 file.

Best regards
Sven

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted

In fact WM_NOTIFY.au3 is not needed for _GUICtrlComboAutoComplete.  Only WM_COMMAND is required and only $CBN_EDITCHANGE is to be intercepted.  The example is way too complicated for absolutely no reason.  You could simplify the winproc as this :

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  If _WinAPI_GetClassName($lParam) = "ComboBox" And _WinAPI_HiWord($wParam) = $CBN_EDITCHANGE Then _GUICtrlComboBox_AutoComplete($lParam)
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...