Jump to content

WM_COMMAND


d0n
 Share

Recommended Posts

I copied this out and changed it to work for $input2, but i want it to work with both $Input2, and $Input3

Chaning the text in either edit control will run the same function, how would i modify that?

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($Input2) Then $hWndEdit = GUICtrlGetHandle($Input2)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord ($iwParam)
    $iCode = _WinAPI_HiWord ($iwParam)
    Switch $hWndFrom
        Case $hWndEdit
            Switch $iCode
                Case $EN_CHANGE  ; Sent when the user has taken an action that may have altered text in an edit control
                    MsgBox("","","")
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Link to comment
Share on other sites

  • Moderators

d0n ,

Just add the handle to the Switch Case. :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>

$fFlag = False

$hGUI = GUICreate("Test", 500, 500)

$Input2 = GUICtrlCreateInput("", 10, 10, 400, 30)
$HandleInput2 = GUICtrlGetHandle($Input2)

$Input3 = GUICtrlCreateInput("", 10, 50, 400, 30)
$HandleInput3 = GUICtrlGetHandle($Input3)

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $fFlag = True Then
        $fFlag = False
        MsgBox(0, "", "Edit Changed")
    EndIf

WEnd

Func MY_WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit

    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord ($iwParam)
    $iCode = _WinAPI_HiWord ($iwParam)

    Switch $hWndFrom
        Case $HandleInput2, $HandleInput3
            Switch $iCode
                Case $EN_CHANGE  ; Sent when the user has taken an action that may have altered text in an edit control
                    $fFlag = True
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

A couple of other changes - because the Help file says:

Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!

So,

1. Get the handles when you create the Inputs - why make your message function do it each time?

2. Use a flag to signal that the function has fired and then run the MsgBox from your main code.

Please ask if anything is unclear.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

logic would dictate:

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit1, $hWndEdit2
    If Not IsHWnd($Input2) Then $hWndEdit1 = GUICtrlGetHandle($Input2)
    If Not IsHWnd($Input3) Then $hWndEdit2 = GUICtrlGetHandle($Input3)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord ($iwParam)
    $iCode = _WinAPI_HiWord ($iwParam)
    Switch $hWndFrom
        Case $hWndEdit1, $hWndEdit2
            Switch $iCode
                Case $EN_CHANGE  ; Sent when the user has taken an action that may have altered text in an edit control
                    MsgBox("","","")
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
No?

Edit:

Code outside codebox?

Melba provided a different method with same cause and effect.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Have it test $hWndFrom against the handles for those controls also. Currently it only tests against the handle of $Input2.

;)

edit: All those great minds, thinking alike... :)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well.... here is mine and I did not see any of the others first...

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit, $cActive
    If Not IsHWnd($Input2) Then $hWndEdit = GUICtrlGetHandle($Input2)
    If Not IsHWnd($Input3) Then $hWndEdit2 = GUICtrlGetHandle($Input3)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $hWndEdit, $hWndEdit2
            $cActive = $hWndEdit
            If GUICtrlGetState($Input3) = $GUI_FOCUS Then $cActive = $hWndEdit2
            Switch $iCode
                Case $EN_CHANGE ; Sent when the user has taken an action that may have altered text in an edit control
                    MsgBox("", "", "")
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

8

8)

... over an hour ago i was posting... damn interruptions :)

NEWHeader1.png

Link to comment
Share on other sites

HI, i ran into another question regarding WM_COMMAND

Right now my GUI when entered something into an input will reset a listview accordingly

But because sometimes, i type in 10 (2 digits), it will reset it twice, then screwing with the listview (sometimes it will lose the groups)

it works if i only type in a single digit

I was wondering if it is possible to only run after the user is done typing or something similar?

The problem doesn't happen if i type really slow, or is a single digit

I should also mention that i am using SQLlite for data, not sure if that would be a problem

EDIT: I think i know why, could be because before the function is finished, another one is ran again, therefore messing it up

how would i go about fixing this?

Edited by d0n
Link to comment
Share on other sites

HI, i ran into another question regarding WM_COMMAND

Right now my GUI when entered something into an input will reset a listview accordingly

But because sometimes, i type in 10 (2 digits), it will reset it twice, then screwing with the listview (sometimes it will lose the groups)

it works if i only type in a single digit

I was wondering if it is possible to only run after the user is done typing or something similar?

The problem doesn't happen if i type really slow, or is a single digit

I should also mention that i am using SQLlite for data, not sure if that would be a problem

EDIT: I think i know why, could be because before the function is finished, another one is ran again, therefore messing it up

how would i go about fixing this?

You really need to show us your WM_COMMAND function, but I assume that you have code in your WM_COMMAND handler which alters the listview. If so then you should do what Melba23 showed and only set a flag, then act on that flag in your main idle loop not in the message handler. In your main idle loop reset the flag and call a function to deal with the update. That way should not give the problem you describe. The examples shown where there is a MsgBox statement in the WM_COMMAND function are a bit naughty because that could cause problems IMO.

Alternatively you could use EN_KILLFOCUS so that the list view is only updated when you leave the edit, or you could simply have a button "Apply".

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...