Jump to content

Windows Message ID (WM_MSG)


Recommended Posts

First I admit the WM_MSG topic is new for me, so there is a lot I am not familiar with.

In the attached script I have 2 MSG. One for the drop down combo box, the other for the input box.

Combo box - to autofill when user begins typing.

Input box - to ensure only numbers are accepted as input.

When input box is satisfied with constraint, the combo box gets the focus and autofills when user types.

Problem:

When the MSG for inputbox is functional, the autofill for the combo box will NOT work.  I have commented OUT the MSG for the input box so you can see the combo box auto fill works. Uncomment the MSG for the input box and see it impacts the combo box.

Excuse all the #includes, I just stripped out all the code not concerned.

 

I was thinking I should just combine the two and use a "switch" for the $iCode. With such little knowledge of the MSG commands I don't know if it would work or if there are unintended issues I am not knowledgeable of.

Any help would be appreciated both to getting this to work and expanding my understanding the MSG (the help file ran over me).

Hobbyist

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
#include <GuiButton.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <GuiDateTimePicker.au3>
#include <Sound.au3>
#include <GuiScrollBars.au3>

Local $main = GUICreate("Log File", 680, 515, 150, 100);?
Local $combo_b = GUICtrlCreateCombo("", 10, 26, 75, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE));?
GUICtrlSetState($combo_b, $GUI_HIDE)

Local $AEamounts = GUICtrlCreateInput("$$$", 96, 26, 70, 21);?


Local $hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE));?
GUICtrlSetData(-1, "dog|cat|mouse")

;------------------------------------------------------------
;command  for  $hcombo  to auto fill when user starts typing
;this command works as expected WHEN the MY_WM_COMMAND(below) is NOT functioning.
;when the MY_WM_COMMAND is functioning, the autofill will NOT work.
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;--------------------------------------------------------------

;--------------------------------------------------------------
;command for ensuring the amount input box only excepts NUMBERS.
;when active, the WM_COMMAND will NOT autofill the $hcombo combo box
;GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")  ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;--------------------------------------------------------------

Global $fComboSelected = False
Global $tInfo, $fComboActive = False
Global $fComboActive2 = False
Local $cEnterPressed = GUICtrlCreateDummy();x;?

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)


GUISetState(@SW_SHOW)

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)
Local $hEdit_2 = DllStructGetData($tInfo, "hEdit")

$listswitch =1

GUISetState()


While 1

    Local $iMsg = GUIGetMsg() ;?

    Switch $iMsg


        Case $GUI_EVENT_CLOSE

            Exit

                    Case $AEamounts ;<> ""
                        if  GUICtrlRead($AEamounts) <> "" Then
                        $AEmoney = GUICtrlRead($AEamounts)
                            GUICtrlSetState($hcombo, $GUI_FOCUS)
                            EndIf

                    Case $cEnterPressed

                        Switch $listswitch

                            case 1

                                Switch _WinAPI_GetFocus()

                                    Case $hEdit_2
                                        If GUICtrlRead($hcombo)  Then
                                        $value = GUICtrlRead($hcombo)
                                        EndIf
                                        EndSwitch
                        EndSwitch


    EndSwitch

WEnd

Func _Edit_Changed(ByRef $hcombo, ByRef $combo_b)
    _GUICtrlComboBox_AutoComplete($hcombo)

EndFunc   ;==>_Edit_Changed


;this function with the _Edit_Change autofills the $hcombo
Func WM_COMMAND($hWnd, $iMsg, $iwParam) ;$hWnd, $iMsg,
    #forceref $hWnd, $iMsg
    Local $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word ;?
    Local $iCode = BitShift($iwParam, 16) ; Hi Word ;?
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo, $combo_b)

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND


;------------- below script to ensure amount value is always a number in the input box------------
;uncomment this function and see the impact on the $hcombo box not autofilling
;uncomment line 50 as well

;~ Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
;~  #forceref $hWnd, $iMsg,$wParam, $lParam
;~  Local $iIDFrom2 = BitAND($wParam, 0xFFFF);LoWord
;~  Local $iCode2 = BitShift($wParam, 16) ;HiWord
;~  If $iIDFrom2 = $AEamounts And $iCode2 = $EN_CHANGE Then
;~      $AEmoney = GUICtrlRead($AEamounts)

;~      If Not StringRegExp($AEmoney, '^[\d-]?\d*(?:\.\d*)?$') Then
;~          GUICtrlSetData($AEamounts, StringTrimRight($AEmoney, 1))
;~          If GUICtrlRead($AEamounts) = "$$" Then
;~              GUICtrlSetData($AEamounts, "$$$")
;~          EndIf
;~      Else
;~          GUICtrlSetData($AEamounts, StringRegExpReplace($AEmoney, '^(-?)\.', '${1}0.'))
;~      EndIf
;~  EndIf


;~ EndFunc   ;==>MY_WM_COMMAND

 

 

Link to comment
Share on other sites

1 hour ago, Hobbyist said:

I was thinking I should just combine the two and use a "switch" for the $iCode

and you were right  :)
Here it is - very raw, should be done cleaner

Func WM_COMMAND($hWnd, $iMsg, $iwParam) ;$hWnd, $iMsg,
    #forceref $hWnd, $iMsg
    Local $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word ;?
    Local $iCode = BitShift($iwParam, 16) ; Hi Word ;?
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo, $combo_b)
            EndSwitch

      Case $EN_CHANGE
      $AEmoney = GUICtrlRead($AEamounts)

     If Not StringRegExp($AEmoney, '^[\d-]?\d*(?:\.\d*)?$') Then
         GUICtrlSetData($AEamounts, StringTrimRight($AEmoney, 1))
          If GUICtrlRead($AEamounts) = "$$" Then
             GUICtrlSetData($AEamounts, "$$$")
          EndIf
     Else
         GUICtrlSetData($AEamounts, StringRegExpReplace($AEmoney, '^(-?)\.', '${1}0.'))
      EndIf

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Link to comment
Share on other sites

mikell

Thank you for the quick reply and guidance to my question.  As I said, my thought was perhaps the two be combined, so based upon your example I am also now believing I should be able to combine multiple MSG commands - with the use of switches.

I will incorporated your example within my script and give it a run.

Hobbyist

Link to comment
Share on other sites

@mikell

I got around to making the changes and using the example you showed.

I came across an unintended result and therefore an additional question.

A positive number is a possible entry, but so is a negative entry.

The (-) sign gets blanked out.  The StringRe... has me totally confused now.

I thought maybe:

If StringRegExp($AEamount, '[^\d\.\-]') Then $AEamount = StringRegExpReplace($AEamount, "[^\d\.]", "")

but that screws the result.

 

Hobbyist

 

Link to comment
Share on other sites

It's difficult to answer without seeing the script.
You shouldn't get trouble with the regex as the original sample code (below) works well

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

GUICreate("Input Filter", 300, 30, -1, -1)
Global $inTest = GUICtrlCreateInput("", 5, 5, 290)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord
    Local $iCode = BitShift($wParam, 16)    ;HiWord

    If $iIDFrom = $inTest And $iCode = $EN_CHANGE Then
      $Read_Input = GUICtrlRead($inTest)
      If not StringRegExp($Read_Input, '^[\d-]?\d*(?:\.\d*)?$') Then 
            GUICtrlSetData($inTest, StringTrimRight($Read_Input, 1))
      Else
            GUICtrlSetData($inTest, StringRegExpReplace($Read_Input, '^(-?)\.', '${1}0.'))
      EndIf
    EndIf
EndFunc;==>_WM_COMMAND

 

Link to comment
Share on other sites

Went back and looked some more.

Here is the script so you can see that is was incorporating your suggestion.

Please look at line 74.  I have now included :

If  StringRegExp(GUICtrlRead($AEamounts), '\d') Then .......

 I think my script  was incorrect  see the ;commented out .

If  GUICtrlRead($AEamounts) <> "" Then  ..........  ;I think was causing my problem.

Seems to work now, with your script suggestion and the  '\d'

Any suggestions or comments appreciated and definitely helps me learn a little more.

 

Hobbyist

 

 

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
#include <GuiButton.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <GuiDateTimePicker.au3>
#include <Sound.au3>
#include <GuiScrollBars.au3>

Local $main = GUICreate("Log File", 680, 515, 150, 100);?
Local $combo_b = GUICtrlCreateCombo("", 10, 26, 75, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE));?
GUICtrlSetState($combo_b, $GUI_HIDE)

Local $AEamounts = GUICtrlCreateInput("$$$", 96, 26, 70, 21);?


Local $hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE));?
GUICtrlSetData(-1, "dog|cat|mouse")

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Global $fComboSelected = False
Global $tInfo, $fComboActive = False
Global $fComboActive2 = False
Local $cEnterPressed = GUICtrlCreateDummy();x;?

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)


GUISetState(@SW_SHOW)

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)
Local $hEdit_2 = DllStructGetData($tInfo, "hEdit")

$listswitch =1

GUISetState()


While 1

    Local $iMsg = GUIGetMsg() ;?

    Switch $iMsg


        Case $GUI_EVENT_CLOSE

            Exit

                    Case $AEamounts 

                        If  StringRegExp(GUICtrlRead($AEamounts), '\d') Then   ;I think this is what I needed.  Any comment????

                        ;if  GUICtrlRead($AEamounts) <> "" Then    ;I think was the problem.
                        
                        $AEmoney = GUICtrlRead($AEamounts)
                            GUICtrlSetState($hcombo, $GUI_FOCUS)
                            EndIf

                    Case $cEnterPressed

                        Switch $listswitch

                            case 1

                                Switch _WinAPI_GetFocus()

                                    Case $hEdit_2
                                        If GUICtrlRead($hcombo)  Then
                                        $value = GUICtrlRead($hcombo)
                                        EndIf
                                        EndSwitch
                        EndSwitch


    EndSwitch

WEnd

Func _Edit_Changed(ByRef $hcombo, ByRef $combo_b)
    _GUICtrlComboBox_AutoComplete($hcombo)

EndFunc   ;==>_Edit_Changed



Func WM_COMMAND($hWnd, $iMsg, $iwParam) ;$hWnd, $iMsg,
    #forceref $hWnd, $iMsg
    Local $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word ;?
    Local $iCode = BitShift($iwParam, 16) ; Hi Word ;?
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo, $combo_b)
            EndSwitch

      Case $EN_CHANGE
      $AEmoney = GUICtrlRead($AEamounts)

     If Not StringRegExp($AEmoney, '^[\d-]?\d*(?:\.\d*)?$') Then
         GUICtrlSetData($AEamounts, StringTrimRight($AEmoney, 1))
          If GUICtrlRead($AEamounts) = "$$" Then
             GUICtrlSetData($AEamounts, "$$$")
          EndIf
     Else
         GUICtrlSetData($AEamounts, StringRegExpReplace($AEmoney, '^(-?)\.', '${1}0.'))
      EndIf

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Link to comment
Share on other sites

I included 2 comments

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
#include <GuiButton.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <GuiDateTimePicker.au3>
#include <Sound.au3>
#include <GuiScrollBars.au3>

Local $main = GUICreate("Log File", 680, 515, 150, 100);?
Local $combo_b = GUICtrlCreateCombo("", 10, 26, 75, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE));?
GUICtrlSetState($combo_b, $GUI_HIDE)

Local $AEamounts = GUICtrlCreateInput("$$$", 96, 26, 70, 21);?
Local $hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE));?
GUICtrlSetData(-1, "dog|cat|mouse")

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Global $fComboSelected = False
Global $tInfo, $fComboActive = False
Global $fComboActive2 = False
Local $cEnterPressed = GUICtrlCreateDummy();x;?

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

GUISetState(@SW_SHOW)

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)
Local $hEdit_2 = DllStructGetData($tInfo, "hEdit")

$listswitch =1

GUISetState()


While 1
    Local $iMsg = GUIGetMsg() 
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit

;>>>>>> The "Case $AEamounts" content (if really necessary) should be managed in the WM_COMMAND, it's not recommended to use both
    ;    Case $AEamounts 
    ;         If  StringRegExp(GUICtrlRead($AEamounts), '\d') Then   ;I think this is what I needed.  Any comment????
     ;         ;if  GUICtrlRead($AEamounts) <> "" Then    ;I think was the problem.           
     ;         $AEmoney = GUICtrlRead($AEamounts)
     ;         GUICtrlSetState($hcombo, $GUI_FOCUS)
     ;         EndIf

       Case $cEnterPressed
             Switch $listswitch
                     case 1
                            Switch _WinAPI_GetFocus()

                                    Case $hEdit_2
                                        If GUICtrlRead($hcombo)  Then
                                        $value = GUICtrlRead($hcombo)
                                        EndIf
                             EndSwitch
             EndSwitch
    EndSwitch
WEnd


Func _Edit_Changed(ByRef $hcombo, ByRef $combo_b)
    _GUICtrlComboBox_AutoComplete($hcombo)
EndFunc   ;==>_Edit_Changed


Func WM_COMMAND($hWnd, $iMsg, $iwParam) ;$hWnd, $iMsg,
    #forceref $hWnd, $iMsg
    Local $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word ;?
    Local $iCode = BitShift($iwParam, 16) ; Hi Word ;?
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo, $combo_b)
            EndSwitch

      Case $EN_CHANGE
        $AEmoney = GUICtrlRead($AEamounts)

        If Not StringRegExp($AEmoney, '^[\d-]?\d*(?:\.\d*)?$') Then
               GUICtrlSetData($AEamounts, StringTrimRight($AEmoney, 1))

;>>>>> the previous regex forbids to write a $ sign in the input so this part is confusing :
        ;  If GUICtrlRead($AEamounts) = "$$" Then
        ;     GUICtrlSetData($AEamounts, "$$$")
        ;  EndIf
     Else
         GUICtrlSetData($AEamounts, StringRegExpReplace($AEmoney, '^(-?)\.', '${1}0.'))
      EndIf

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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