Jump to content

Recommended Posts

Hey guys,

I ran into a problem when I wanted to delete items of a listview using the delete key. My approach is to register my own WndProc for the listview and then filter the $WM_GETDLGCODE msg and then call the original WndProc.

That works like a charm. The problem is that when the listview gets redrawn it somehow ends up in an infinite loop. The listview is suddenly emtpy and I can't interact with any controls of the GUI at all. Here's the code:

 

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <WinAPI.au3>

$h_GUI = GUICreate("Test", 200, 200, 350, 350)
$h_LV = GUICtrlCreateListView("Col 1|Col 2|Col 3", 0, 0, 200, 200)
_GUICtrlListView_AddItem($h_LV, "")
_GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 0)
_GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 1)
_GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 2)
_GUICtrlListView_AddItem($h_LV, "")
_GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 0)
_GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 1)
_GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 2)
_GUICtrlListView_AddItem($h_LV, "")
_GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 0)
_GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 1)
_GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 2)
_GUICtrlListView_AddItem($h_LV, "")
_GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 0)
_GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 1)
_GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 2)

$h_LV_NewWndProc = DllCallbackRegister("WndProc_LV", "int", "hwnd;uint;wparam;lparam")
$g_LV_OldWndProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($h_LV), $GWL_WNDPROC, DllCallbackGetPtr($h_LV_NewWndProc))

GUISetState(@SW_SHOW)

Func WndProc_LV($hWnd, $uMsg, $wParam, $lParam)

   Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam)

EndFunc   ;==>WndProc_GUI


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

DllCallbackFree($h_LV_NewWndProc)

As you can see I'm doing nothing in the WndProc of the listview. I'm simply calling the original WndProc. This still "freezes" when I mess with the width of the columns or in the original project when I add more items that they don't fit in the listview and I have to scroll. If I don't do that it's working fine.

Edited by Broihon
added tag
Link to comment
Share on other sites

This is a known problem.

Replace

Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam)

with

Return DllCall("user32.dll", "lresult", "CallWindowProc", "ptr", $g_LV_OldWndProc, "hwnd", $hWnd, "uint", $uMsg, "wparam", $wParam, "lparam", $lParam)[0]

 

You should use

_WinAPI_SetWindowSubclass()

and related functions for subclassing.

Link to comment
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
 Share

×
×
  • Create New...