Sign in to follow this  
Followers 0
zorphnog

[SOLVED] GUIOnEventMode and ListView Params

7 posts in this topic

#1 ·  Posted (edited)

I am having a problem when using GUIOnEventMode and setting ListView Params. What happens is that clicking on a ListView item causes an unrelated OnEvent function to execute. I'm pretty sure this is a bug, but I just wanted to confirm with others or see if anyone else has a workaround for this.

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)

$gui = GUICreate("Unintended Events", 450, 420, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_000")
$lvMain = GUICtrlCreateListView("Title", 10, 10, 350, 400, $LVS_NOCOLUMNHEADER)
$lvMain = GUICtrlGetHandle($lvMain)
GUICtrlSendMsg(-1, 0x101E, 0, 325)
For $i=1 To 13
    GUICtrlCreateButton(StringFormat("_%03d", $i), 368, 6 + ($i - 1) * 32, 75, 25, 0)
    GUICtrlSetOnEvent(-1, StringFormat("_%03d", $i))
Next
For $i=0 To 20
    _GUICtrlListView_AddItem($lvMain, StringFormat("%03d", $i), -1, $i)
Next
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func _000()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 0, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
    Exit
EndFunc

Func _001()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 1, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _002()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 2, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _003()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 3, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _004()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 4, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _005()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 5, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _006()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 6, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _007()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 7, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _008()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 8, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _009()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 9, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _010()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 10, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _011()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 11, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _012()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 12, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

Func _013()
    ConsoleWrite(StringFormat("This is _%03d | %s | %s | %s\r\n", 13, @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
EndFunc

If you click on ListView items _004 through _016, it executes the OnEvent functions of buttons _001 through _013. If I do not set the ListViewItem params, this behavior does not happen. Any thoughts?

Edited by zorphnog

Share this post


Link to post
Share on other sites



Don't mix the UDF _GuiCtrl* functions with the native AutoIt controls. This works with all native AutoIt functions:

#include <GuiConstants.au3>
#include <WindowsConstants.au3>

Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)

$gui = GUICreate("Unintended Events", 450, 420, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$lvMain = GUICtrlCreateListView("Title", 10, 10, 350, 400, $LVS_NOCOLUMNHEADER)
GUICtrlSendMsg(-1, 0x101E, 0, 325)
For $i = 1 To 13
    GUICtrlCreateButton(StringFormat("_%03d", $i), 368, 6 + ($i - 1) * 32, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "_ButtonHit")
Next
For $i = 0 To 20
    GUICtrlCreateListViewItem(StringFormat("%03d", $i), $lvMain)
Next
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func _Quit()
    ConsoleWrite(StringFormat("This is _Quit      | %s | %s | %s\r\n", @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle))
    Exit
EndFunc   ;==>_Quit

Func _ButtonHit()
    ConsoleWrite(StringFormat("This is _ButtonHit | %s | %s | %s | %s\r\n", @GUI_CtrlId, @GUI_CtrlHandle, @GUI_WinHandle, ControlGetText($gui, "", @GUI_CtrlId)))
EndFunc   ;==>_ButtonHit

If you must use _GuiCtrlListView_* functions, then create it with _GuiCtrlListView_Create().

:idea:


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

Share this post


Link to post
Share on other sites

Good catch. Thanks.

Share this post


Link to post
Share on other sites

Don't mix the UDF _GuiCtrl* functions with the native AutoIt controls.

Good advice. Although, I must say that the examples in the help file interchange the two frequently.

I've narrowed it down to the fact that native ListViewItems append their @GUI_CtrlID to the Params of the item. I'm guessing this is for the ability to add events to GUICtrlCreateListViewItems. This is fine as I can get around the issue using _GUICtrlListView_Create. The problem I have now is that I want the click area for items to span the entire column (like items in a ListView created with the native functions). I've tried all kinds of different styles, but I cannot get it to work. This example shows the problem:

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <Winapi.au3>

Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)

$gui = GUICreate("Unintended Events", 730, 420, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$lvOne = _GUICtrlListView_Create($gui, "_GUICtrlListView_Create", 10, 10, 350, 400, $WS_TABSTOP+$WS_GROUP+$LVS_REPORT+$LVS_SHOWSELALWAYS+$LVS_SINGLESEL, $LVS_EX_FULLROWSELECT+$WS_EX_CLIENTEDGE)
_GUICtrlListView_SetColumnWidth($lvOne, 0, 325)
For $i=0 To 15
    _GUICtrlListView_AddItem($lvOne, StringFormat("Item %03d", $i), -1, $i)
Next
$lvTwo = GUICtrlCreateListView("GUICtrlCreateListView", 370, 10, 350, 400)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 325)
For $i=0 To 15
    GUICtrlCreateListViewItem(StringFormat("Item %03d", $i), $lvTwo)
Next
GUISetState(@SW_SHOW)

Dim $aLong[7]
$aLong[0] = _WinAPI_GetWindowLong($lvOne, $GWL_EXSTYLE)
$aLong[1] = _WinAPI_GetWindowLong($lvOne, $GWL_STYLE)
$aLong[2] = _WinAPI_GetWindowLong($lvOne, $GWL_WNDPROC)
$aLong[3] = _WinAPI_GetWindowLong($lvOne, $GWL_HINSTANCE)
$aLong[4] = _WinAPI_GetWindowLong($lvOne, $GWL_HWNDPARENT)
$aLong[5] = _WinAPI_GetWindowLong($lvOne, $GWL_ID)
$aLong[6] = _WinAPI_GetWindowLong($lvOne, $GWL_USERDATA)
ConsoleWrite(StringFormat("  _GUICtrlListView_Create 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X\r\n", $aLong[0], $aLong[1], $aLong[2], $aLong[3], $aLong[4], $aLong[5], $aLong[6]))
_ExpandStyle($aLong[1])
Dim $aLong[7]
$aLong[0] = _WinAPI_GetWindowLong(GUICtrlGetHandle($lvTwo), $GWL_EXSTYLE)
$aLong[1] = _WinAPI_GetWindowLong(GUICtrlGetHandle($lvTwo), $GWL_STYLE)
$aLong[2] = _WinAPI_GetWindowLong(GUICtrlGetHandle($lvTwo), $GWL_WNDPROC)
$aLong[3] = _WinAPI_GetWindowLong(GUICtrlGetHandle($lvTwo), $GWL_HINSTANCE)
$aLong[4] = _WinAPI_GetWindowLong(GUICtrlGetHandle($lvTwo), $GWL_HWNDPARENT)
$aLong[5] = _WinAPI_GetWindowLong(GUICtrlGetHandle($lvTwo), $GWL_ID)
$aLong[6] = _WinAPI_GetWindowLong(GUICtrlGetHandle($lvTwo), $GWL_USERDATA)
ConsoleWrite(StringFormat("\r\n  GUICtrlCreateListView   0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X\r\n", $aLong[0], $aLong[1], $aLong[2], $aLong[3], $aLong[4], $aLong[5], $aLong[6]))
_ExpandStyle($aLong[1])

While 1
    Sleep(10)
WEnd

Func _Quit()
    Exit
EndFunc

Func _ExpandStyle($iStyle)
    Local $sMsg
;~  If BitAND($iStyle, $WS_TILED) = $WS_TILED Then $sMsg = StringFormat("%-25s 0x%08X\r\n", "WS_TILED", $WS_TILED)
    If BitAND($iStyle, $WS_OVERLAPPED) = $WS_OVERLAPPED Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_OVERLAPPED", $WS_OVERLAPPED)
;~  If BitAND($iStyle, $WS_MAXIMIZEBOX) = $WS_MAXIMIZEBOX Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_MAXIMIZEBOX", $WS_MAXIMIZEBOX)
;~  If BitAND($iStyle, $WS_MINIMIZEBOX) = $WS_MINIMIZEBOX Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_MINIMIZEBOX", $WS_MINIMIZEBOX)
    If BitAND($iStyle, $WS_TABSTOP) = $WS_TABSTOP Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_TABSTOP", $WS_TABSTOP)
    If BitAND($iStyle, $WS_GROUP) = $WS_GROUP Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_GROUP", $WS_GROUP)
    If BitAND($iStyle, $WS_SIZEBOX) = $WS_SIZEBOX Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_SIZEBOX", $WS_SIZEBOX)
    If BitAND($iStyle, $WS_THICKFRAME) = $WS_THICKFRAME Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_THICKFRAME", $WS_THICKFRAME)
;~  If BitAND($iStyle, $WS_SYSMENU) = $WS_SYSMENU Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_SYSMENU", $WS_SYSMENU)
    If BitAND($iStyle, $WS_HSCROLL) = $WS_HSCROLL Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_HSCROLL", $WS_HSCROLL)
    If BitAND($iStyle, $WS_VSCROLL)  = $WS_VSCROLL Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_VSCROLL", $WS_VSCROLL)
    If BitAND($iStyle, $WS_DLGFRAME) = $WS_DLGFRAME Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_DLGFRAME", $WS_DLGFRAME)
    If BitAND($iStyle, $WS_BORDER) = $WS_BORDER Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_BORDER", $WS_BORDER)
    If BitAND($iStyle, $WS_CAPTION) = $WS_CAPTION Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_CAPTION", $WS_CAPTION)
;~  If BitAND($iStyle, $WS_OVERLAPPEDWINDOW) = $WS_OVERLAPPEDWINDOW Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_OVERLAPPEDWINDOW", $WS_OVERLAPPEDWINDOW)
;~  If BitAND($iStyle, $WS_TILEDWINDOW) = $WS_TILEDWINDOW Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_TILEDWINDOW", $WS_TILEDWINDOW)
;~  If BitAND($iStyle, $WS_MAXIMIZE) = $WS_MAXIMIZE Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_MAXIMIZE", $WS_MAXIMIZE)
    If BitAND($iStyle, $WS_CLIPCHILDREN) = $WS_CLIPCHILDREN Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_CLIPCHILDREN", $WS_CLIPCHILDREN)
    If BitAND($iStyle, $WS_CLIPSIBLINGS) = $WS_CLIPSIBLINGS Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_CLIPSIBLINGS", $WS_CLIPSIBLINGS)
    If BitAND($iStyle, $WS_DISABLED) = $WS_DISABLED Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_DISABLED", $WS_DISABLED)
    If BitAND($iStyle, $WS_VISIBLE) = $WS_VISIBLE Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_VISIBLE", $WS_VISIBLE)
;~  If BitAND($iStyle, $WS_MINIMIZE) = $WS_MINIMIZE Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_MINIMIZE", $WS_MINIMIZE)
    If BitAND($iStyle, $WS_CHILD) = $WS_CHILD Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_CHILD", $WS_CHILD)
    If BitAND($iStyle, $WS_POPUP) = $WS_POPUP Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_POPUP", $WS_POPUP)
;~  If BitAND($iStyle, $WS_POPUPWINDOW) = $WS_POPUPWINDOW Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "WS_POPUPWINDOW", $WS_POPUPWINDOW)
    If BitAND($iStyle, $LVS_ALIGNLEFT) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_ALIGNLEFT", $LVS_ALIGNLEFT)
    If BitAND($iStyle, $LVS_ALIGNMASK) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_ALIGNMASK", $LVS_ALIGNMASK)
    If BitAND($iStyle, $LVS_ALIGNTOP) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_ALIGNTOP", $LVS_ALIGNTOP)
    If BitAND($iStyle, $LVS_AUTOARRANGE) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_AUTOARRANGE", $LVS_AUTOARRANGE)
;~  If BitAND($iStyle, $LVS_DEFAULT) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_DEFAULT", $LVS_DEFAULT)
    If BitAND($iStyle, $LVS_EDITLABELS) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_EDITLABELS", $LVS_EDITLABELS)
    If BitAND($iStyle, $LVS_ICON) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_ICON", $LVS_ICON)
    If BitAND($iStyle, $LVS_LIST) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_LIST", $LVS_LIST)
    If BitAND($iStyle, $LVS_NOCOLUMNHEADER) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_NOCOLUMNHEADER", $LVS_NOCOLUMNHEADER)
    If BitAND($iStyle, $LVS_NOLABELWRAP) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_NOLABELWRAP", $LVS_NOLABELWRAP)
    If BitAND($iStyle, $LVS_NOSCROLL) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_NOSCROLL", $LVS_NOSCROLL)
    If BitAND($iStyle, $LVS_NOSORTHEADER) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_NOSORTHEADER", $LVS_NOSORTHEADER)
    If BitAND($iStyle, $LVS_OWNERDATA) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_OWNERDATA", $LVS_OWNERDATA)
    If BitAND($iStyle, $LVS_OWNERDRAWFIXED) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_OWNERDRAWFIXED", $LVS_OWNERDRAWFIXED)
    If BitAND($iStyle, $LVS_REPORT) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_REPORT", $LVS_REPORT)
    If BitAND($iStyle, $LVS_SHAREIMAGELISTS) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_SHAREIMAGELISTS", $LVS_SHAREIMAGELISTS)
    If BitAND($iStyle, $LVS_SHOWSELALWAYS) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_SHOWSELALWAYS", $LVS_SHOWSELALWAYS)
    If BitAND($iStyle, $LVS_SINGLESEL) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_SINGLESEL", $LVS_SINGLESEL)
    If BitAND($iStyle, $LVS_SMALLICON) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_SMALLICON", $LVS_SMALLICON)
    If BitAND($iStyle, $LVS_SORTASCENDING) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_SORTASCENDING", $LVS_SORTASCENDING)
    If BitAND($iStyle, $LVS_SORTDESCENDING) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_SORTDESCENDING", $LVS_SORTDESCENDING)
    If BitAND($iStyle, $LVS_TYPEMASK) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_TYPEMASK", $LVS_TYPEMASK)
    If BitAND($iStyle, $LVS_TYPESTYLEMASK) <> 0 Then $sMsg &= StringFormat("%-25s 0x%08X\r\n", "LVS_TYPESTYLEMASK", $LVS_TYPESTYLEMASK)
    ConsoleWrite($sMsg)
EndFunc

If use the UDF ListView you have to click on the text to select the item, but using the native ListView you can select an item by clicking anywhere in the column. Anyone know how to set this behavior in the UDF ListView?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The style doesn't seem to "stick" if used in the create statement, but it appears to have an effect after the fact:

$lvOne = _GUICtrlListView_Create($gui, "_GUICtrlListView_Create", 10, 10, 350, 400)
_GUICtrlListView_SetExtendedListViewStyle ($lvOne, $LVS_EX_FULLROWSELECT)

typo

Edited by Spiff59

Share this post


Link to post
Share on other sites

The style doesn't seem to "stick" if used in the create statement, but it appears to have an effect after the fact:

Well that is indeed strange. I was thinking that it was set looking at the flag values from GetWindowLong, but I guess it wasn't truly set. Oh well. Thanks for the info, that seems to work!

Share this post


Link to post
Share on other sites

Good advice. Although, I must say that the examples in the help file interchange the two frequently.

Yes, and that's considered a pervasive bug in documentation at this point. They are slowly being changed as busy people get around to them.

Here's one of many examples: BugTrack #1580: Bug in example script for _GUICtrlRebar_Create()

:idea:


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

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
Sign in to follow this  
Followers 0