AndyS19

No WM_NOTIFY interrupts

15 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

AndyS19,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Melba23:  I sent you my files via PM.

Share this post


Link to post
Share on other sites

AndyS19,

Got them and replied.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

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

Share this post


Link to post
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

 

Share this post


Link to post
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

  • Similar Content

    • Skysnake
      By Skysnake
      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
    • AutoBert
      By AutoBert
      I have a LV with different coloured Cols:
      ;https://autoit.de/index.php/Thread/84279-Unterschiedliche-Textfarben-innerhalb-einer-ListView/?postID=674195#post674195 #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <array.au3> #include <ListViewConstants.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> $aColBK = IniReadSection(@ScriptDir & "\lv_format.ini", "ColBKColor") _ArrayDelete($aColBK, 0) ;_ArrayDisplay($aColBK) $aRowBK = IniReadSection(@ScriptDir & "\lv_format.ini", "RowBKColor") _ArrayDelete($aRowBK, 0) ;_ArrayDisplay($aColBK) $aColText = IniReadSection(@ScriptDir & "\lv_format.ini", "ColTextColor") _ArrayDelete($aColText, 0) ;_ArrayDisplay($aColBK) $aRowText = IniReadSection(@ScriptDir & "\lv_format.ini", "RowTextColor") _ArrayDelete($aRowText, 0) ;_ArrayDisplay($aRowText) $GUI = GUICreate("Listview Farbig", 1024, 300, 0, 0) ;<==== Breite geändert $cListView = GUICtrlCreateListView("", 2, 2, 1020, 294, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;<==== Breite geändert $hListView = GUICtrlGetHandle($cListView) For $i = 1 To 31 _GUICtrlListView_InsertColumn($hListView, $i - 1, $i, 25) _GUICtrlListView_SetColumnWidth($hListView, $i - 1, 32) ;<==== eingefügt für Spaltenbreite Next For $i = 0 To 21 ; alle Item/SubItem erstellen _GUICtrlListView_AddItem($hListView, "Item: " &$i, $i) For $j = 1 To 30 _GUICtrlListView_AddSubItem($hListView, $i, "Sub: "&$j, $j) Next Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While True $msg = GUIGetMsg() Switch $msg Case -3 ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage, $iItem, $iSubitem, $hDC, $tRect $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Item/SubItem das aktuell gezeichnet werden soll ermitteln $iItem = DllStructGetData($tCustDraw, 'dwItemSpec') $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') Switch $iItem ; Zeilenwahl Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann Case Else $iIndex = _ArraySearch($aRowBK, $iItem, 0, 0, 0, 0, 1, 0) If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also weiß DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR(0xFFFFFF)) Else DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK[$iIndex][1])) ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF) EndIf $iIndex = _ArraySearch($aRowText, $iItem, 0, 0, 0, 0, 1, 0) If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also schwarz DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0x000000)) Else DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aRowText[$iIndex][1])) ;ConsoleWrite('Item '&$iItem&' Text: '&$aRowText[$iIndex][1] & @CRLF) EndIf EndSwitch Switch $iSubitem Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann Case Else $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0) If $iIndex <> -1 Then DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColBK[$iIndex][1])) ;ConsoleWrite('SubItem '&$iSubitem&' BK: '&$aColBK[$iIndex][1] & @CRLF) EndIf $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0) If $iIndex <> -1 Then DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aColText[$iIndex][1])) ;ConsoleWrite('SubItem '&$iSubitem&' Text: '&$aColText[$iIndex][1] & @CRLF) EndIf EndSwitch Return $CDRF_NEWFONT EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Local $sH = Hex($iColor, 6) Return '0x' & StringRight($sH, 2) & StringMid($sH, 3, 2) & StringLeft($sH, 2) EndFunc ;==>RGB2BGR i use lv_format.ini for defining the cols Background- and Textcolour. Now i want to colour the cols in the LV-Header also, but i can't figure it out.
       

    • kcvinu
      By kcvinu
      Hi all,
      I am trying to get the selected item text from a tree view control.
      For that i am using this code. Please take a look. In this code, i am using console write function so that i am able to know that the user clicks in an item. This code works perfectly at the first click. But when i click on an item second time, it will work twice, That means, console write will work twice. Same result is at the third and fourth click also. 
       
      Func TreeView_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $tv1 If Not IsHWnd($tv1) Then $hWndTreeview = GUICtrlGetHandle($tv1) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $TVN_SELCHANGINGW ConsoleWrite("Clicked" & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  
    • DavidStark
      By DavidStark
      Hey guys,
      After much searching and reading I Siao's example script from the below link is the closest to what I need to do.
      I have a ListView that is populated with the names of different configurations.  When a Listview item is selected, a form is populated with that items data.  Right now I have a column that shows which item's data is shown in the form, but it would be much cleaner to just have the current item highlighted.
      My problem is this - The highlighting in Siao's example works great, but inside the Listview when you select in the "empty" space to essentially deselect everything the highlighting disappears.
      How can I keep the last selected item highlighted when clicking in this empty space?
      Also - I do not understand enough about Windows notifications to understand if we could utilize SendMessage to initiate a custom draw....  It seems to me that you could specify an item and then invoke the DLL function to redraw the item that you specified with the colors that you specified.... That's the idea I get when I read the MSDN documentation on it: https://msdn.microsoft.com/en-us/library/windows/desktop/ff919573(v=vs.85).aspx
       
      Siao's Example modified for latest AutoIt:
      #Include <GuiConstantsEx.au3> #Include <GuiListView.au3> #include <WindowsConstants.au3> #cs ;custom draw constants Global Const $CDDS_ITEM = 0x10000 Global Const $CDDS_MAPPART = 0x5 Global Const $CDDS_POSTERASE = 0x4 Global Const $CDDS_POSTPAINT = 0x2 Global Const $CDDS_PREERASE = 0x3 Global Const $CDDS_PREPAINT = 0x1 Global Const $CDDS_SUBITEM = 0x20000 Global Const $CDDS_ITEMPOSTERASE = BitOR($CDDS_ITEM, $CDDS_POSTERASE) Global Const $CDDS_ITEMPOSTPAINT = BitOR($CDDS_ITEM, $CDDS_POSTPAINT) Global Const $CDDS_ITEMPREERASE = BitOR($CDDS_ITEM, $CDDS_PREERASE) Global Const $CDDS_ITEMPREPAINT = BitOR($CDDS_ITEM, $CDDS_PREPAINT) Global Const $CDIS_CHECKED = 0x8 Global Const $CDIS_DEFAULT = 0x20 Global Const $CDIS_DISABLED = 0x4 Global Const $CDIS_FOCUS = 0x10 Global Const $CDIS_GRAYED = 0x2 Global Const $CDIS_HOT = 0x40 Global Const $CDIS_INDETERMINATE = 0x100 Global Const $CDIS_MARKED = 0x80 Global Const $CDIS_SELECTED = 0x1 Global Const $CDIS_SHOWKEYBOARDCUES = 0x200 Global Const $CDRF_DODEFAULT = 0x0 Global Const $CDRF_NEWFONT = 0x2 Global Const $CDRF_NOTIFYITEMDRAW = 0x20 Global Const $CDRF_NOTIFYPOSTERASE = 0x40 Global Const $CDRF_NOTIFYPOSTPAINT = 0x10 Global Const $CDRF_NOTIFYSUBITEMDRAW = 0x20 Global Const $CDRF_SKIPDEFAULT = 0x4 #ce ;fonts for custom draw example ;bold Global $aFont1 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _ "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _ "dword", 0, "str", "") ;italic Global $aFont2 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 400, _ "dword", 1, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _ "dword", 0, "str", "") $GUI = GUICreate("Listview Custom Draw", 400, 300) $cListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($cListView) _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100) ; Add items For $i = 1 To 30 _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1) For $j = 1 To 2 _GUICtrlListView_AddSubItem ($hListView, $i-1, "Row" & $i & ": Col " & $j+1, $j) Next Next GUICtrlCreateInput("", 50, 275, 100, 15) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont1[0]) DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont2[0]) Exit Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _ 'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _ 'dword clrText;dword clrTextBk;int SubItem;' & _ 'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3 $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage') Switch $iDrawStage Case $CDDS_PREPAINT Return $CDRF_NOTIFYITEMDRAW Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case $CDDS_ITEMPOSTPAINT Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) $iItem = DllStructGetData($tCustDraw, 'ItemSpec') $iSubitem = DllStructGetData($tCustDraw, 'SubItem') If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then $hDC = _WinAPI_GetDC($hWndFrom) $tRect = DllStructCreate('long;long;long;long') If $iSubitem = 0 Then DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect)) DllStructSetData($tRect, 1, 2) DllCall('user32.dll', 'int', 'FillRect', 'ptr', $hDC, 'ptr', DllStructGetPtr($tRect), 'int', _WinAPI_GetStockObject(4)) EndIf DllStructSetData($tRect, 1, 2) DllStructSetData($tRect, 2, $iSubitem) DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect)) Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem) DLLCall("gdi32.dll","int","SetTextColor", "ptr", $hDC, "int", RGB2BGR(0xffff00)) DLLCall("gdi32.dll","int","SetBkMode", "ptr", $hDC, "int", 1) DllStructSetData($tRect, 1, DllStructGetData($tRect, 1)+2) _WinAPI_DrawText($hDC, $sText, $tRect, 0x8000) ;; $DT_END_ELLIPSIS _WinAPI_ReleaseDC($hWndFrom, $hDC) Return $CDRF_SKIPDEFAULT EndIf Switch $iItem Case 0 To 9 ;for rows 1-10 lets do this $iColor1 = RGB2BGR(0xFBFFD8) $iColor2 = RGB2BGR(-1) $iColor3 = RGB2BGR(0xFF0000) If Mod($iSubitem, 2) Then ;odd columns DllStructSetData($tCustDraw, 'clrTextBk', $iColor1) DllStructSetData($tCustDraw, 'clrText', 0) Else ;even columns DllStructSetData($tCustDraw, 'clrTextBk', $iColor2) DllStructSetData($tCustDraw, 'clrText', $iColor3) EndIf Case 10 To 19 ;for rows 11-20 lets do this $iColor1 = RGB2BGR(0xFBFFD8) $iColor2 = RGB2BGR(0x3DF8FF) $hDC = DllStructGetData($tCustDraw, 'hdc') If Mod($iItem, 2) Then If Mod($iSubitem, 2) Then DllStructSetData($tCustDraw, 'clrTextBk', $iColor1) Else DllStructSetData($tCustDraw, 'clrTextBk', $iColor2) EndIf DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont1[0]) ;select our chosen font into DC Else If Mod($iSubitem, 2) Then DllStructSetData($tCustDraw, 'clrTextBk', $iColor2) Else DllStructSetData($tCustDraw, 'clrTextBk', $iColor1) EndIf DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont2[0]) EndIf Case 20 To 29 ;for rows 21-30 lets do this $iColor1 = RGB2BGR(0xFBFFD8) $iColor2 = RGB2BGR(-1) If Mod($iItem, 2) Then ;odd rows DllStructSetData($tCustDraw, 'clrTextBk', $iColor2) Else DllStructSetData($tCustDraw, 'clrTextBk', $iColor1) EndIf EndSwitch Return $CDRF_NEWFONT Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM) Case Else EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF) EndFunc Source:
       
    • SupaNewb
      By SupaNewb
      Issue: If either date picker controls receive focus, then use arrow keys to change date in edit portion, flags do not set to True until mouse move or mouse click.
      I have used this exact method in the past & it works perfectly. I just can't figure out what I am doing wrong here. The only thing different I can think of is I just updated my Autoit version to ;Autoit v3.3.14.0 & if it matters system I am using is running Win7 Pro x86.
      #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <Date.au3> #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> ;If either date picker controls recieve focus, then use arrow keys to change date ; in edit portion, flags do not set to True until mouse move or mouse click. ;Flags set fine when drop down is closed Global $fdpLogChange = False, $fdpMainChange = False Global $hDailyLogGUI, $g_id_dpDailyLog Global $hMainGui = GUICreate("GardenBuddy", @DesktopWidth / 1.5, @DesktopHeight / 1.4, -1, -1) Global $g_id_dpMain = GUICtrlCreateDate(_NowDate(), 8, 20, 181, 25) Global $mView = GUICtrlCreateMenu("&View") Global $mPlantChart = GUICtrlCreateMenuItem("Plant Chart", $mView, 0) GUICtrlCreateMenuItem("", $mView, 1) Global $mDailyLog = GUICtrlCreateMenuItem("Daily Log", $mView, 2) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $Msg = GUIGetMsg(1) Switch $Msg[1] Case $hMainGui Switch $Msg[0] Case $GUI_EVENT_CLOSE GUIDelete($hMainGui) Exit Case $mDailyLog __CreateDailyLog() Case Else If $fdpMainChange = True Then __DateChangeMain() EndSwitch Case $hDailyLogGUI Switch $Msg[0] Case $GUI_EVENT_CLOSE GUIDelete($hDailyLogGUI) Case Else If $fdpLogChange = True Then __DateChangeDL() EndSwitch EndSwitch WEnd Func __CreateDailyLog() Local $iW = @DesktopWidth / 2, $iH = @DesktopHeight / 2 $hDailyLogGUI = GUICreate("Daily Log", $iW, $iH, -1, -1, $WS_OVERLAPPEDWINDOW) $g_reDailyLog = _GUICtrlRichEdit_Create($hDailyLogGUI, "", 0, 60, $iW, $iH - 110, _ BitOR($WS_VSCROLL, $ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_MULTILINE)) _GUICtrlRichEdit_SetFont($g_reDailyLog, 12) $g_id_dpDailyLog = GUICtrlCreateDate(_NowDate(), 8, 20, 181, 25) GUISetState() EndFunc ;==>__CreateDailyLog Func __DateChangeDL();Would like to be instantly notified if user changes the date through any means. $fdpLogChange = False ConsoleWrite("Log Changed" & @CRLF) EndFunc ;==>__DateChangeDL Func __DateChangeMain() $fdpMainChange = False ConsoleWrite("Main Changed" & @CRLF) EndFunc ;==>__DateChangeMain Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndDateDailyLog, $hWndDateMain $hWndDateDailyLog = GUICtrlGetHandle($g_id_dpDailyLog) $hWndDateMain = GUICtrlGetHandle($g_id_dpMain) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndDateDailyLog, $hWndDateMain Switch $iCode Case $DTN_DATETIMECHANGE If $iIDFrom = $g_id_dpDailyLog Then $fdpLogChange = True If $iIDFrom = $g_id_dpMain Then $fdpMainChange = True Return 0 Case $DTN_CLOSEUP ;no return value Case $DTN_USERSTRING Return 0 Case $DTN_WMKEYDOWN Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY