Jump to content

Recommended Posts

Posted

I've got a situation where I was writing and debugging my program for a long while. I got it to the point where everything was perfect and there were no bugs.

Then I go to compile it to a 64-bit EXE...... aaaaand it's gone!

The event no longer works. (Now I'm not 100% sure if the event is not firing or if an "if" statement or two are failing below it. I can test this a bit more tomorrow if the answer is not obvious and quick. Let's dig deeper...

Here's the code snippet (I am not posting the whole thing):

#include <WinApi.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
#include <Clipboard.au3>
#include <Array.au3>
#include <String.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_HANDLER")

; other code and stuff here
; =========================


Func WM_NOTIFY_HANDLER($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate("int;int;int", $lParam)
    Local $hwFrom = DllStructGetData($tNMHDR, 1)
    Local $code = DllStructGetData($tNMHDR, 3)
    Local $hListView = GUICtrlGetHandle($todoList)

    If $code = $NM_DBLCLK Then ;   THIS PART DOES NOT EXECUTE ON 64-BIT EXE. WHY???
        If $hwFrom = $hListView Then
            Local $index = _GUICtrlListView_GetSelectionMark($hListView)
            If $index <> -1 Then
                Local $oldText = _GUICtrlListView_GetItemText($hListView, $index)
                Local $newText = InputBox("Edit Task", "Double-click edit:", $oldText)
                If Not @error And StringStripWS($newText, 3) <> "" Then
                    _GUICtrlListView_SetItemText($hListView, $index, $newText)
                    _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
                EndIf
            EndIf
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

 

Posted (edited)

Try Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) instead. 

The NMHDR structure is not "int;int;int", but "struct; hwnd hWndFrom;uint_ptr IDFrom;INT Code; endstruct".

Also don't use InputBox in the event, it must return as soon as possible. Try to relocate the complex part to your main loop, e.g. only set a trigger variable to true.

Something like this:

Global $b_Trigger_Event_Listview_NM_DBLCLK = False

Global $hListView = GUICtrlGetHandle($todoList)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_HANDLER")

While Sleep(10)
    If $b_Trigger_Event_Listview_NM_DBLCLK = True Then
        _Edit_Task()
        $b_Trigger_Event_Listview_NM_DBLCLK = False
    EndIf
WEnd


Func WM_NOTIFY_HANDLER($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hwFrom = DllStructGetData($tNMHDR, 1)
    Local $code = DllStructGetData($tNMHDR, 3)

    If $code = $NM_DBLCLK Then ;   THIS PART DOES NOT EXECUTE ON 64-BIT EXE. WHY???
        If $hwFrom = $hListView Then
            $b_Trigger_Event_Listview_NM_DBLCLK = True
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY_HANDLER

Func _Edit_Task()
    Local $index = _GUICtrlListView_GetSelectionMark($hListView)
    If $index <> -1 Then
        Local $oldText = _GUICtrlListView_GetItemText($hListView, $index)
        Local $newText = InputBox("Edit Task", "Double-click edit:", $oldText)
        If Not @error And StringStripWS($newText, 3) <> "" Then
            _GUICtrlListView_SetItemText($hListView, $index, $newText)
            _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
        EndIf
    EndIf
EndFunc   ;==>_Edit_Task

 

Edited by KaFu
Posted
3 hours ago, KaFu said:

... Also don't use InputBox in the event, it must return as soon as possible. ...

... 
    If $code = $NM_DBLCLK Then ;   THIS PART DOES NOT EXECUTE ON 64-BIT EXE. WHY???
        If $hwFrom = $hListView Then
;~             $b_Trigger_Event_Listview_NM_DBLCLK = True
            AdlibRegister(_Edit_Task, 20)
        EndIf
    EndIf
...

I use AdlibRegister(), and that frees the $WM_NOTIFY function.
The main difference is that the code don't have to constantly evaluate in the main loop "are we there yet".

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...