Sign in to follow this  
Followers 0
enaiman

Bug? - _ArrayDisplay freezes everytime [RESOLVED]

7 posts in this topic

#1 ·  Posted (edited)

I don't know if this is a bug or not but if I am using WM_NOTIFY to detect a double click on a listView item, any further call for _ArrayDisplay it will make the _ArrayDisplay GUI to freeze.

I have put together an example script:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $hListView
Global $ListContent
Global $TestARR[4] = ["test1", "test2", "test3", "test4"]

GUICreate("ListView", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("line4|5|more_a", $hListView)
GUICtrlCreateListViewItem("line5|4.50 |more_c", $hListView)
GUICtrlCreateListViewItem("line5|4.0 |more_c", $hListView)
GUICtrlCreateListViewItem("line3|23|more_e", $hListView)
GUICtrlCreateListViewItem("line2|0.34560 |more_d", $hListView)
GUICtrlCreateListViewItem("line1|1.0 |more_b", $hListView)
GUICtrlCreateListViewItem("line1|0.1 |more_b", $hListView)
GUICtrlCreateListViewItem("line1|10|more_b", $hListView)
_GUICtrlListView_SetColumnWidth($hListView, 0, 75)
_GUICtrlListView_SetColumnWidth($hListView, 1, 75)
_GUICtrlListView_SetColumnWidth($hListView, 2, 75)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


While 1
    Sleep(200)
WEnd

Func Form1Close()
    Exit
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
;~  Local $tBuffer
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    MsgBox(0, "DoubleClick", "Double Click detected")
                    _ArrayDisplay($TestARR)
            EndSwitch

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

For me the GUI freezes and all I can do is to close the application.

AutoIt 3.3.6.1 and Win7

It is really strange - does anyone have an idea why this is happening? Am I doing something wrong?

Thanks,

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I tidied up the code a little ... It's never a good idea to interrupt the WM Message with a MsgBox() or _ArrayDisplay() (for example.) You can see that I have recorded the Item and SubItem and then set a Global variable to indicate there was a DoubleClick, from there the WM Message is exited and the MsgBox() + _ArrayDisplay() is shown.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $hListView, $iDoubleClick = 0
Global $ListContent
Global $TestARR[4] = ["test1", "test2", "test3", "test4"]

GUICreate("ListView", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("line4|5|more_a", $hListView)
GUICtrlCreateListViewItem("line5|4.50 |more_c", $hListView)
GUICtrlCreateListViewItem("line5|4.0 |more_c", $hListView)
GUICtrlCreateListViewItem("line3|23|more_e", $hListView)
GUICtrlCreateListViewItem("line2|0.34560 |more_d", $hListView)
GUICtrlCreateListViewItem("line1|1.0 |more_b", $hListView)
GUICtrlCreateListViewItem("line1|0.1 |more_b", $hListView)
GUICtrlCreateListViewItem("line1|10|more_b", $hListView)
_GUICtrlListView_SetColumnWidth($hListView, 0, 75)
_GUICtrlListView_SetColumnWidth($hListView, 1, 75)
_GUICtrlListView_SetColumnWidth($hListView, 2, 75)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


While 1
    If $iDoubleClick = 1 Then
        MsgBox(0, "DoubleClick", "Double Click detected")
        _ArrayDisplay($TestARR)
        $iDoubleClick = 0
    EndIf
    Sleep(200)
WEnd

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom,  $iCode, $tNMHDR, $hWndListView,  $iInfo, $iIndex, $iSubItem
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    $iInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    $iIndex = DllStructGetData($iInfo, "Index") ; The 'Row' Number  Selected E.G. Select The 1st Item Will Return 0
    $iSubItem = DllStructGetData($iInfo, "SubItem") ; The 'Column' Number  Selected E.G. Select The 2nd Item Will Return 1

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $iDoubleClick = 1
                    ConsoleWrite("Index = " & $iIndex & " and SubItem = " & $iSubItem & @Crlf)
            EndSwitch

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Edit : Have a look at this >> http://www.autoitscript.com/wiki/GUIRegisterMsg, you can see that Melba23 pointed out this "Warning: blocking of running user functions which execute Windows messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!"

Also my Tip is have a look at GUICtrlSendToDummy() :) This is what I use when I want to run a Function but don't want to run it in a WM Message.

Edit 2: Just saw that Melba23 uses GUICtrlSendToDummy() too (Whats that they say about great minds?)

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

The helpfile tell you something very important for GUIRegisterMsg() =

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

Remember that AutoIt can only do one event at a time, others are put to a queue, so when you use a blocking function things just break down. Like putting a mountain in front of a train.

KABOOM!!

Share this post


Link to post
Share on other sites

@guinness

Thank you very much for clarifying this aspect.

That Melba23 quote really sounded familiar, at some point in the past I definitely read about that but I forgot :P

It is obviously my poor coding's fault here - in my big script I was calling a function when a double-click was detected ... well I can see clearly now from your example how it needs to be done.

Lesson learned :) - I am pretty sure I won't forget it :)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

You're Welcome :)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

@AdmiralAlkex

thanks for your input :) you were right 100% too :)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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