Jump to content

No WM_NOTIFY interrupts


AndyS19
 Share

Recommended Posts

I have a script that writes a message to the console whenever a WM_NOTIFY event is detected. but I don't get the events.

Here is my test script:

Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)
OnAutoItExitRegister("ExitStageLeft")

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

Global $hMainWin

_Main()

Func _Main()

    $hMainWin = GUICreate("test", 300, 300)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState()
    GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft')

    GUISetState()

    While (1)
        Sleep(250)
    WEnd

EndFunc   ;==>_Main

Func ExitStageLeft()
    Exit (1)
EndFunc   ;==>ExitStageLeft

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ConsoleWrite("+++: WM_NOTIFY(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_NOTIFY

 

Link to comment
Share on other sites

  • Moderators

AndyS19,

You need something in the GUI that will fire a WM_NOTIFY event - try this script and move the mouse over the button:

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

Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)

HotKeySet("{ESC}", "_Exit")

Global $hMainWin



_Main()

Func _Main()

    $hMainWin = GUICreate("test", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GUICtrlCreateButton("Press", 10, 10, 80, 30)

    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    While 1
        Sleep(10)
    WEnd



EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ConsoleWrite("+++: WM_NOTIFY(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_NOTIFY

Func _Exit()
    Exit
EndFunc

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

Hmmm... I see what you're saying, but I actually have the problem in another, more complex script.  The script creates a listview and some buttons, and has been working for a while.  I wanted to implement a dynamic context menu for when right clicking in the listview.  I wanted to look at what was selected and create a popup menu according to the data I selected.  So all I did was added a GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") line and a WM_NOTIFY function like you see in my test script.

I could send you my script, although I have many of my own UDFs in it.  Perhaps you could look at it and see if you could spot the problem.

Link to comment
Share on other sites

  • Moderators

AndyS19,

Always helps to look at the actual script in which you have the problem. By all means let me see it (via PM if you do not want to do so in open forum) and I will take a look.

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

Hmmm... I see what you're saying, but I actually have the problem in another, more complex script.  The script creates a listview and some buttons, and has been working for a while.  I wanted to implement a dynamic context menu for when right clicking in the listview.  I wanted to look at what was selected and create a popup menu according to the data I selected.  So all I did was added a GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") line and a WM_NOTIFY function like you see in my test script.

I could send you my script, although I have many of my own UDFs in it.  Perhaps you could look at it and see if you could spot the problem.

Link to comment
Share on other sites

Wait!  In my production script, I see that when I hover the mouse over my buttons, I see WM_NOTIFY interrupts, but not when I hover over or click on the listview item.  I added a listview control to the test script and I see WM_NOTIFY notifications.  I'm missing something here.  Any suggestions?

Link to comment
Share on other sites

  • Moderators

AndyS19,

It seems there is an echo around here......

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

AndyS19,

Got them and replied.

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

I've added code to create a ListView (GUICtrlCreateListView) object and a List (GUICtrlCreateList) object.  The ListView control gets WM_NOTIFY events, but the List control does not.

Here is my new test code:

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

Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)

HotKeySet("{ESC}", "_Exit")

Global $hMainWin, $cnt = 0
_Main()

Func _Main()

    $hMainWin = GUICreate("test", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GUICtrlCreateButton("Press", 10, 260, 80, 30)
    GUICtrlCreateList("listview control",     10, 10,  150, 100)
    GUICtrlCreateListView("listview control", 10, 110, 250, 100)

    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_NOTIFY(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_NOTIFY

Func _Exit()
    Exit
EndFunc

 

Link to comment
Share on other sites

AndyS19,

See this doc for an example of ListBox notification messages.  Note, these messages are sent to the WM_COMMAND routine.

kylomas

Edited by kylomas
correction

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

But these messages are sent when left clicking in the listbox, not when right clicking.  Because I want to display a context menu, I need to trap a right click.

I added code to trap WM_COMMAND events, and got nothing when I right clicked the listbox.

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

Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)

HotKeySet("{ESC}", "_Exit")

Global $hMainWin, $cnt = 0

_Main()

Func _Main()

    $hMainWin = GUICreate("test", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GUICtrlCreateButton("Press", 10, 260, 80, 30)
    GUICtrlCreateList("listview control",     10, 10,  150, 100)
    GUICtrlCreateListView("listview control", 10, 110, 250, 100)

    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_NOTIFY(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_NOTIFY

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_COMMAND(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_NOTIFY

Func _Exit()
    Exit
EndFunc

 

Link to comment
Share on other sites

Try this.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)

HotKeySet("{ESC}", "_Exit")

Global $hMainWin, $cnt = 0

_Main()

Func _Main()

    $hMainWin = GUICreate("test", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GUICtrlCreateButton("Press", 10, 260, 80, 30)
    GUICtrlCreateList("listbox control", 10, 10, 150, 100)
    GUICtrlSetData(-1, "2|3")
    GUICtrlCreateListView("listview control", 10, 110, 250, 100)
    Local $idItem2 = GUICtrlCreateListViewItem("item1", -1)
    Local $idItem3 = GUICtrlCreateListViewItem("item2", -1)


    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_NOTIFY(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>_WM_NOTIFY

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_COMMAND(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_CONTEXTMENU(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_CONTEXTMENU


Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ahh, I see you introduced context menu's in post #5.  Have you looked at _GUICtrlMenu_CreatePopup in the Help file?

Here, I dug up this old example...maybe you can adapt it to your needs...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

Local $sHelp = 'Right click on any entry and choose one of the popup menu items.  Watch the console area for results'

; Define message numbers to be associated with popup menu items.
; These will also be the message id's that the Windows message hander (WM_COMMAND) will use to action a control.
Global Enum $idproc1 = 1000, $idproc2

; Create the gui and listview control.
Local $gui010 = GUICreate('Listview Example', 200, 200)
Local $lv010 = GUICtrlCreateListView('Types', 20, 20, 65, 150)

; Populate the listview control using an array and resize the column width to automatically fit the data length.
Local $aTranTypes[7][1] = [['Auto'], ['Bus'], ['Airplane'], ['Train'], ['Boat'], ['Motorcycle'], ['Helicopter']]
_GUICtrlListView_AddArray($lv010, $aTranTypes)
_GUICtrlListView_SetColumnWidth($lv010, 0, $LVSCW_AUTOSIZE)

Local $help = GUICtrlCreateLabel($sHelp, 100, 20, 100, 150)

; The are dummy controls that will be actioned by the Windows message handler based on the message id associated with the popup menu.
; E.G. $dummy_proc1 will be actioned by application defined window message $idproc1 from message handler WM_COMMAND.
Local $dummy_proc1 = GUICtrlCreateDummy()
Local $dummy_proc2 = GUICtrlCreateDummy()

; Set in the notification message handler (WM_NOTIFY) to get the item number of the listview item clicked on.
Local $iItem = 0

; Popup menu...each item is associated with an applications defined window message ($idproc1 and $idproc2).
local $hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Run Procedure #1", $idproc1)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Run Procedure #2", $idproc2)

GUISetState()

; Register the message handlers
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $dummy_proc1
            ConsoleWrite('You have choosen to run Procedure #1 on ' & _GUICtrlListView_GetItemText($lv010, $iItem) & @CRLF)
        Case $dummy_proc2
            ConsoleWrite('You have choosen to run Procedure #2 on ' & _GUICtrlListView_GetItemText($lv010, $iItem) & @CRLF)
    EndSwitch

WEnd



; Notification message handler.  This is what will detect the right click.
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    ; structure to map $ilParam ($tNMHDR - see Help file)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

    Switch $tNMHDR.IDFrom

        Case $lv010
            Switch $tNMHDR.Code
                Case $NM_RCLICK
                    ; another structure to remap $ilParam...used to get the item that was right clicked
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    If $tInfo.Item > -1 Then
                        $iItem = $tInfo.Item
                        ; positions the popup menu at the right clicked item
                        _GUICtrlMenu_TrackPopupMenu($hMenu, $gui010)
                    endif

            EndSwitch

    EndSwitch



    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

; Window message handler...this is what will action the controls in the message loop
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    ; $iwParam contains the application messages that we defined earlier
    Switch $iwParam

        Case $idproc1
            guictrlsendtodummy($dummy_proc1)
        Case $idproc2
            guictrlsendtodummy($dummy_proc2)
    EndSwitch

EndFunc   ;==>WM_COMMAND

edit: Here is a link that shows how this could be done with a listbox. 

Edited by kylomas
additional info

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Thanks, KingBob.  I changed my script to trap WM_CONTEXTMENU events and it all works!  Thanks for the help.

Andy

My working test script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)


Global $hMainWin, $cnt = 0

_Main()

Func _Main()

    $hMainWin = GUICreate("test", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GUICtrlCreateButton("Press", 10, 260, 80, 30)
    GUICtrlCreateList("listbox control", 10, 10, 150, 100)
    GUICtrlSetData(-1, "2|3")
    GUICtrlCreateListView("listview control", 10, 110, 250, 100)
    Local $idItem2 = GUICtrlCreateListViewItem("item1", -1)
    Local $idItem3 = GUICtrlCreateListViewItem("item2", -1)

    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_NOTIFY(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>_WM_NOTIFY

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_COMMAND(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cnt += 1
    ConsoleWrite("+++:" & $cnt & ": WM_CONTEXTMENU(" & Hex($hWnd) & "|" & Hex($iMsg) & "|" & Hex($iwParam) & "|" & Hex($ilParam) & ") entered" & @CRLF)
EndFunc   ;==>WM_CONTEXTMENU


Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

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...