Sign in to follow this  
Followers 0
LurchMan

WM_NOTIFY In a List View Help[SOLVED]

4 posts in this topic

#1 ·  Posted (edited)

Hey everyone -

I'm having some troubles making heads or tails of how WM_NOTIFY with a list view is suppose to work - I've used the script from the help file to get a little ways with it but I can't get it to work. Basically I have a list view that I want it so if you double click an item it does the same as if you were to used the menu and choose edit. I've got it working from the menu, but when I double click it crashes and I get an error of:

!>17:59:16 AutoIT3.exe ended.rc:-1073741819

I am using SQLite inside the function that gets called, but I've accounted for it its going into that function from either a double click or the menu (At least with my crazy logic it looks like I have lol). I've attached the functions in use for this problem (kinda lengthy). Any questions or if I didn't explain it too good, let me know.

Thank you for any and all help anyone can provide.

--LurchMan

Edit: Uploaded DB File - Youll have to change extension to .db or change code..forgot about that sorry.

error help.au3

contacts.txt

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites



I'm having some troubles making heads or tails of how WM_NOTIFY with a list view is suppose to work - I've used the script from the help file to get a little ways with it but I can't get it to work. Basically I have a list view that I want it so if you double click an item it does the same as if you were to used the menu and choose edit. I've got it working from the menu, but when I double click it crashes and I get an error of:

First of all, what this code is supposed to do (excerpts from your script)?:

Func editClick()
    If $NM_DBLCLK Then
        $recs = _GUICtrlListView_GetHotItem($contactlist)
    Else
;....
        EndIf
EndFunc

$NM_DBLCLICK is a constant value for notification code and therefore your else-block doesn't ever get executed.

Second of all, take a look at "How To: catch ENTER and double clicks on a ListView item". If you don't need the enter key you can omit the subclassing part of the example.


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Strange i found the opposite, the double clicking worked and the menu edit casued an error, the selecting of the rowid inside func editclick wasnt working and editgui window was being recreated without deleteing the old, i've made some changes to make it function how i think you want it. Something to think about, rather then recreating the windows each time how about just hiding the one you dont want seen and updating the control values.

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <sqlite.dll.au3>
#include <file.au3>
#Include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
Global $EditGUI, $viewGUI, $sDBFile = @ScriptDir & "\contacts.db"
Global $contactlist, $hQuery, $aRow
_SQLite_Startup ()
If Not FileExists($sDBFile) Then
    _CreateDB ()
EndIf
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$hDB = _SQLite_Open ($sDBFile)

ViewClick ()

While 1
    Sleep (100)
WEnd

Func ViewClick()
    If WinExists($EditGUI) Then GUIDelete($EditGUI)
    $viewGUI = GUICreate("View Contacts", 637, 443, 253, 151)
    GUISetOnEvent($GUI_EVENT_CLOSE, "mainClose")
    $edit_menu = GUICtrlCreateMenu("Edit")
    $edit = GUICtrlCreateMenuItem("Edit Contact", $edit_menu)
        GUICtrlSetOnEvent(-1, "editClick")

    $contactlist = GUICtrlCreateListView("#|First Name|Last Name|Address|Address 2|Home Ph#|Cell Ph#|Work #", 0, 0, 634, 422)
    GUICtrlSendMsg(-1, 0x101E, 0, 25)
    GUICtrlSendMsg(-1, 0x101E, 1, 100)
    GUICtrlSendMsg(-1, 0x101E, 2, 100)
    GUICtrlSendMsg(-1, 0x101E, 3, 100)
    GUICtrlSendMsg(-1, 0x101E, 4, 100)
    GUICtrlSendMsg(-1, 0x101E, 5, 100)
    GUICtrlSendMsg(-1, 0x101E, 6, 100)
    GUICtrlSendMsg(-1, 0x101E, 7, 100)
    GUISetState(@SW_SHOW)
    _SQLite_Query($hDB, "SELECT ROWID, * FROM Contacts;", $hQuery)

    While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
    GUICtrlCreateListViewItem($aRow[0] & '|' & $aRow[1] & '|' & $aRow[2] & '|' & $aRow[3] & '|' & _
                            $aRow[4] & '|' & $aRow[5] & '|' & $aRow[6] & '|' & $aRow[7], $contactlist)
    WEnd

EndFunc

Func editClick()
    Local $aSelectRowArray
    $aSelectRowArray = _GUICtrlListView_GetItemTextArray(GUICtrlGetHandle($contactlist),-1)
    If not $aSelectRowArray[1] Then
        MsgBox(48, "Select Contact", "Please select a contact to edit.")
            Return
    EndIf

    GUIDelete($viewGUI)
    $EditGUI = GUICreate("Edit Contact", 637, 443, 253, 151)
        GUISetOnEvent($GUI_EVENT_CLOSE, "mainClose")
    $edit_menu = GUICtrlCreateMenu("Edit")
    $edit = GUICtrlCreateMenuItem("Edit Contact", $edit_menu)
        GUICtrlSetOnEvent(-1, "_EditMenuClicked")

    _SQLite_Query($hDB, "SELECT ROWID, * FROM Contacts WHERE (ROWID=" & $aSelectRowArray[1] & ");", $hQuery)
    _SQLite_FetchData ($hQuery, $aRow)

    If Not IsArray($aRow) Then
        MsgBox(48, "Select Contact", "Please select a valid contact to edit.")
        ViewClick ()
        Return
    EndIf
    $fname = GUICtrlCreateInput($aRow[1], 118, 88, 177, 21)
    GUICtrlSetState(-1, $GUI_FOCUS)
    GUICtrlCreateLabel("First Name", 38, 88, 54, 17)
    GUICtrlCreateLabel("Home Phone Number", 318, 136, 106, 17)
    $lname = GUICtrlCreateInput($aRow[2], 118, 136, 177, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Last Name", 38, 136, 55, 17)
    $address1 = GUICtrlCreateInput($aRow[3], 118, 184, 177, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Address", 38, 184, 42, 17)
    GUICtrlCreateLabel("Address 2", 38, 232, 51, 17)
    $address2 = GUICtrlCreateInput($aRow[4], 118, 232, 177, 21, $WS_TABSTOP)
    $cellnum = GUICtrlCreateInput($aRow[6], 438, 88, 169, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Cell Phone Number", 318, 88, 95, 17)
    $homenum = GUICtrlCreateInput($aRow[5], 438, 136, 169, 21, $WS_TABSTOP)
    $worknum = GUICtrlCreateInput($aRow[7], 438, 184, 169, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Work Phone Number", 318, 184, 104, 17)
    $c_view = GUICtrlCreateButton("View Contacts", 391, 312, 90, 25, 0)
    GUICtrlSetOnEvent(-1, "ViewClick")
    GUISetState(@SW_SHOW)
EndFunc

Func _EditMenuClicked()
    MsgBox(0,"","You need a new function here for whatever this menu edit needs to do")
EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $contactlist
    If Not IsHWnd($contactlist) Then $hWndListView = GUICtrlGetHandle($contactlist)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndListView

        if $iCode = $NM_DBLCLK Then
                editClick ()
        EndIf

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _CreateDB ()
    _SQLite_Exec($hDB, "CREATE TABLE Contacts (FirstName, LastName, address, address2, cellnum, homenum, worknum);")
EndFunc

Func mainClose ()
    Exit
EndFunc

adding a quick example of creating the Gui's first then showing and updating controls.

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <sqlite.dll.au3>
#include <file.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
Global $EditGUI, $viewGUI, $sDBFile = @ScriptDir & "\contacts.db"
Global $contactlist, $hQuery, $aRow
Global $fname, $lname, $address1, $address1, $address2, $cellnum, $homenum, $worknum
_SQLite_Startup()
If Not FileExists($sDBFile) Then
    _CreateDB()
EndIf
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$hDB = _SQLite_Open($sDBFile)

_CreateViewGUI()
_CreateEditRowGui()
_ShowViewGUI()

While 1
    Sleep(100)
WEnd

Func _CreateViewGUI()
    $viewGUI = GUICreate("View Contacts", 637, 443, 253, 151)
    GUISetOnEvent($GUI_EVENT_CLOSE, "mainClose")
    $edit_menu = GUICtrlCreateMenu("Edit")
    $edit = GUICtrlCreateMenuItem("Edit Contact", $edit_menu)
    GUICtrlSetOnEvent(-1, "_ShowEditRowGui")
    $contactlist = GUICtrlCreateListView("#|First Name|Last Name|Address|Address 2|Home Ph#|Cell Ph#|Work #", 0, 0, 634, 422)
    GUICtrlSendMsg(-1, 0x101E, 0, 25)
    GUICtrlSendMsg(-1, 0x101E, 1, 100)
    GUICtrlSendMsg(-1, 0x101E, 2, 100)
    GUICtrlSendMsg(-1, 0x101E, 3, 100)
    GUICtrlSendMsg(-1, 0x101E, 4, 100)
    GUICtrlSendMsg(-1, 0x101E, 5, 100)
    GUICtrlSendMsg(-1, 0x101E, 6, 100)
    GUICtrlSendMsg(-1, 0x101E, 7, 100)
EndFunc   ;==>_CreateViewGUI

Func _ShowViewGUI()
    local $aWinPos
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($contactlist))
    _SQLite_Query($hDB, "SELECT ROWID, * FROM Contacts;", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        GUICtrlCreateListViewItem($aRow[0] & '|' & $aRow[1] & '|' & $aRow[2] & '|' & $aRow[3] & '|' & _
                $aRow[4] & '|' & $aRow[5] & '|' & $aRow[6] & '|' & $aRow[7], $contactlist)
    WEnd

    $aWinPos = WinGetPos($EditGUI)
    WinMove($viewGUI, "", $aWinPos[0], $aWinPos[1])
    GUISetState(@SW_HIDE, $EditGUI)
    GUISetState(@SW_SHOW, $viewGUI)
EndFunc   ;==>_ShowViewGUI


Func _CreateEditRowGui()
    $EditGUI = GUICreate("Edit Contact", 637, 443, 253, 151)
    GUISetOnEvent($GUI_EVENT_CLOSE, "mainClose")
    $edit_menu = GUICtrlCreateMenu("Edit")
    $edit = GUICtrlCreateMenuItem("Edit Contact", $edit_menu)
    GUICtrlSetOnEvent(-1, "_EditMenuClicked")
    $fname = GUICtrlCreateInput("", 118, 88, 177, 21)
    GUICtrlCreateLabel("First Name", 38, 88, 54, 17)
    GUICtrlCreateLabel("Home Phone Number", 318, 136, 106, 17)
    $lname = GUICtrlCreateInput("", 118, 136, 177, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Last Name", 38, 136, 55, 17)
    $address1 = GUICtrlCreateInput("", 118, 184, 177, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Address", 38, 184, 42, 17)
    GUICtrlCreateLabel("Address 2", 38, 232, 51, 17)
    $address2 = GUICtrlCreateInput("", 118, 232, 177, 21, $WS_TABSTOP)
    $cellnum = GUICtrlCreateInput("", 438, 88, 169, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Cell Phone Number", 318, 88, 95, 17)
    $homenum = GUICtrlCreateInput("", 438, 136, 169, 21, $WS_TABSTOP)
    $worknum = GUICtrlCreateInput("", 438, 184, 169, 21, $WS_TABSTOP)
    GUICtrlCreateLabel("Work Phone Number", 318, 184, 104, 17)
    $c_view = GUICtrlCreateButton("View Contacts", 391, 312, 90, 25, 0)
    GUICtrlSetOnEvent(-1, "_ShowViewGUI")
EndFunc   ;==>_CreateEditRowGui

Func _ShowEditRowGui()
    Local $aSelectRowArray, $aWinPos
    $aSelectRowArray = _GUICtrlListView_GetItemTextArray(GUICtrlGetHandle($contactlist), -1)
    If Not $aSelectRowArray[1] Then
        MsgBox(48, "Select Contact", "Please select a contact to edit.")
        Return
    EndIf
    _SQLite_Query($hDB, "SELECT ROWID, * FROM Contacts WHERE (ROWID=" & $aSelectRowArray[1] & ");", $hQuery)
    _SQLite_FetchData($hQuery, $aRow)
    If Not IsArray($aRow) Then
        MsgBox(48, "Select Contact", "Please select a valid contact to edit.")
        Return
    EndIf
    GUICtrlSetData($fname, $aRow[1])
    GUICtrlSetData($lname, $aRow[2])
    GUICtrlSetData($address1, $aRow[3])
    GUICtrlSetData($address2, $aRow[4])
    GUICtrlSetData($cellnum, $aRow[6])
    GUICtrlSetData($homenum, $aRow[5])
    GUICtrlSetData($worknum, $aRow[7])
    GUICtrlSetState($fname, $GUI_FOCUS)
    $aWinPos = WinGetPos($viewGUI)
    WinMove($EditGUI, "", $aWinPos[0], $aWinPos[1])
    GUISetState(@SW_HIDE, $viewGUI)
    GUISetState(@SW_SHOW, $EditGUI)
EndFunc   ;==>_ShowEditRowGui

Func _EditMenuClicked()
    MsgBox(0, "", "You need a new function here for whatever this menu edit needs to do")
EndFunc   ;==>_EditMenuClicked


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $contactlist
    If Not IsHWnd($contactlist) Then $hWndListView = GUICtrlGetHandle($contactlist)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView

            If $iCode = $NM_DBLCLK Then
                _ShowEditRowGui()
            EndIf

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _CreateDB()
    _SQLite_Exec($hDB, "CREATE TABLE Contacts (FirstName, LastName, address, address2, cellnum, homenum, worknum);")
EndFunc   ;==>_CreateDB

Func mainClose()
    Exit
EndFunc   ;==>mainClose
Edited by Yoriz

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

Both of you thank you for your time. Between a mixture of your solutions and my own stupidity I found the root of the real problem....I haven't used this computer for awhile and I just realized it was still on AutoIt 3.3.0...I upgraded and made the changes to that If block in editClick () and it works as expected now...sorry for wasting your guys' time thank you for your help though.


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

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