Jump to content

WM_NOTIFY Help and Tutorial?


Skysnake
 Share

Recommended Posts

Hi

Best example I could find is here

::/html/libfunctions/_GUICtrlTreeView_ClickItem.htm

The way I understand this, the standard Windows messages, such as Left/Right Click etc are covered by AutoIt macros, but the real power is locked up inside this WM_NOTIFY .  I have tried, but I am not even sure I understand what I am looking at.

I need help understanding this.  What I am looking for is Help file or Tutorial explaining how this works?  

Perhaps if there is a script showing both the working of an AutoIt macro and the WM_NOTIFY  in action, it would help.

Right now I am so lost, I do not even know what are the right questions to ask.  One issue I have is on ListViews, how to combine the "Click" of a line with a standard Switch loop?  Like users clicks a line, then get the loop to detect the click and ;do something ...

Any ideas?

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

  • Moderators

Skysnake,

Try this tutorial and see if it clears some of the fog.

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

Okay, much better now.

Where can I find an explanation of at least the most common?  Enter / Left Click, Right click / Double Click?

 ::/html/appendix/WinMsgCodes.htm 

The command names are listed, but what do they do?

 

In this example ::/html/libfunctions/_GUICtrlComboBox_AutoComplete.htm

the DoubleClick in the example does not work for me. The edit does not respond to a Double Click and neither do the list items.

Skysnake

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

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

Global $g_idCombo
Global $g_fcbmSelected

Example()

Func Example()
    ; Create GUI
    Local $hGUI = GUICreate("ComboBox Auto Complete", 400, 296)
    $g_idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296) ; control
    $hWndCombo = GUICtrlGetHandle($g_idCombo)
;~  $g_hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 396, 296) ; handle

    Local $cmbValue = ''

    Local $mylabel = GUICtrlCreateLabel("...", 10, 50, 100, 25)


    GUISetState(@SW_SHOW)

    ; Add files
    _GUICtrlComboBox_BeginUpdate($g_idCombo)
    _GUICtrlComboBox_AddDir($g_idCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate($g_idCombo)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

;~  ; Loop until the user exits.
;~  Do
;~  Until GUIGetMsg() = $GUI_EVENT_CLOSE
;~  GUIDelete()


    While 1
        Switch GUIGetMsg()
            Case $g_idCombo, $g_fcbmSelected
                $cmbValue = GUICtrlRead($g_idCombo)
                GUICtrlSetData($mylabel, $cmbValue)
                $g_fcbmSelected = False
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Exit
            Case Else
                ContinueLoop
        EndSwitch

    WEnd

EndFunc   ;==>Example

Func _Edit_Changed()
    _GUICtrlComboBox_AutoComplete($g_idCombo)
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($g_idCombo) Then $hWndCombo = GUICtrlGetHandle($g_idCombo)
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $g_idCombo, $hWndCombo
            Switch $iCode
                Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed
                    _DebugPrint("$CBN_CLOSEUP" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
;~                   next line seems to do nothing
;~              Case $CBN_DBLCLK ; Sent when the user double-clicks a string in the list box of a combo box
;~                  _DebugPrint("$CBN_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode)
;~                  ; no return value
                Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible
                    _DebugPrint("$CBN_DROPDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
                    _DebugPrint("$CBN_EDITCHANGE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    _Edit_Changed()
                    ; no return value
                Case $CBN_EDITUPDATE ; Sent when the edit control portion of a combo box is about to display altered text
                    _DebugPrint("$CBN_EDITUPDATE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_ERRSPACE ; Sent when a combo box cannot allocate enough memory to meet a specific request
                    _DebugPrint("$CBN_ERRSPACE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
                    _DebugPrint("$CBN_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _DebugPrint("$CBN_SELCHANGE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_SELENDCANCEL ; Sent when the user selects an item, but then selects another control or closes the dialog box
                    _DebugPrint("$CBN_SELENDCANCEL" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list
                    _DebugPrint("$CBN_SELENDOK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; return a flag to be actioned :)
                    Return $g_fcbmSelected = True
                Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
                    _DebugPrint("$CBN_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

Dear @Melba23, I have done this based on the wiki and the Help file.  For the moment, this is doing what I want.  Any comments and criticisms are welcome.  What can I do better?

The idea is to have (a) that auto-update Combo, and (b) pass on the user's selection to another control.  Is this good? Can it be better?

Thank you for all your patience.

Skysnake 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

  • Moderators

Skysnake,

I would do it like this:

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

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

$cCombo = GUICtrlCreateCombo("", 10, 10, 200, 200)

$cLabel = GUICtrlCreateLabel("", 10, 100, 200, 20)

; Add files
_GUICtrlComboBox_BeginUpdate($cCombo)
_GUICtrlComboBox_AddDir($cCombo, @WindowsDir & "\*.exe")
_GUICtrlComboBox_EndUpdate($cCombo)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCombo ; Use Autoit to do the hard work - this fires when the user makes a selection
            GUICtrlSetData($cLabel, GUICtrlRead($cCombo))
    EndSwitch

WEnd

Func _Edit_Changed()

    ; Autocomplete the edit
    _GUICtrlComboBox_AutoComplete($cCombo)
    ; Change the label to match the autocompleted edit entry
    If GUICtrlRead($cLabel) <> GUICtrlRead($cCombo) Then
        GUICtrlSetData($cLabel, GUICtrlRead($cCombo))
    EndIf

EndFunc   ;==>_Edit_Changed

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

    #forceref $hWnd, $iMsg
    If $lParam = GUICtrlGetHandle($cCombo) And BitShift($wParam, 16) = $CBN_EDITCHANGE Then ; Our combo edit content has changed
        _Edit_Changed() ; Action this function
    EndIf

EndFunc

A bit simpler - but not that dissimilar.

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

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

×
×
  • Create New...