Modify

Opened 11 years ago

Closed 4 years ago

#2668 closed Bug (No Bug)

Subclassing issue on CallWindowProc

Reported by: FireFox Owned by:
Milestone: Component: AutoIt
Version: 3.3.11.3 Severity: None
Keywords: Cc:

Description

Hi,
There's an issue on the CallWindowProc function (_WinAPI_CallWindowProc), which causes the script to stuck somewhat in an infinite loop.

The issue is fixed if the DllCall result is directly returned using this syntax :

Return DllCall(...)[0]

Attached the script reproducer, with the orignal function called at line 82 and the "fixed" function called at line 83 (commented).

Attachments (1)

subclassing.au3 (2.4 KB) - added by FireFox 11 years ago.

Download all attachments as: .zip

Change History (5)

Changed 11 years ago by FireFox

comment:1 Changed 11 years ago by anonymous

I forgot to add that the issue is showed by dragging the 1st column.

comment:2 Changed 4 years ago by anonymous

it looks like it is working by luck

if the result of CallWindowsProc is stored in a variable and then return the error occur

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <HeaderConstants.au3>
#include <WinAPI.au3>

; The 0-based column to be disabled
Global $iFix_Col
;~ Global $hOld_WndProc
; Get new WndProc hamdle and pointer
Global $hNew_WndProc = DllCallbackRegister("_New_LVHdr_Proc", "lresult", "hwnd;uint;wparam;lparam")
Global $pNew_WndProc = DllCallbackGetPtr($hNew_WndProc)
; To save old WndProc handle
Global $hOld_WndProc

_Main()

Func _Main()
	Local Const $hGUI = GUICreate("ListView Fix Column Width", 400, 300)

	Local Const $cListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 10, 10, 380, 220)
	GUICtrlCreateListViewItem("0|1|2|3", $cListView)

	Global $hLVHdr = _GUICtrlListView_GetHeader($cListView)

	$cButton = GUICtrlCreateButton("Test", 10, 250, 80, 30)

	GUISetState()

	; Prevent resizing of column 1
	$iFix_Col = 1

	; Prevent drag resize
	GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

	; SubClass LV Header
	$hOld_WndProc = _WinAPI_SetWindowLong($hLVHdr, $GWL_WNDPROC, $pNew_WndProc)
	ConsoleWrite("Old proc: 0x" & Hex($hOld_WndProc, 8) & @CRLF)

	; Loop until user exits
	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE
				Exit
			Case $cButton
				ConsoleWrite("Pressed" & @CRLF)
		EndSwitch
	WEnd

	GUIDelete($hGUI)
EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

	; Get details of message
	Local $iCode, $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
	; Look for header resize code
	$iCode = DllStructGetData($tNMHEADER, "Code")
	Switch $iCode
		Case $HDN_BEGINTRACKW
			; Now get column being resized
			Local $iCol = DllStructGetData($tNMHEADER, "Item")
			If $iCol = $iFix_Col Then
				; Prevent resizing
				Return True
			Else
				; Allow resizing
				Return False
			EndIf
	EndSwitch

EndFunc   ;==>_WM_NOTIFY

Func _New_LVHdr_Proc($hWnd, $iMsg, $wParam, $lParam)

	Switch $iMsg
		Case $WM_SETCURSOR
			Return True
	EndSwitch
	Local $iRet
	; Now call previous WndProc and complete the chain
;~ 	$iRet = _WinAPI_CallWindowProc($hOld_WndProc, $hWnd, $iMsg, $wParam, $lParam)
	$iRet = CallWindowProc($hOld_WndProc, $hWnd, $iMsg, $wParam, $lParam)
	Return $iRet
EndFunc   ;==>_New_LVHdr_Proc

Func CallWindowProc($lpPrevWndFunc, $hWnd, $Msg, $wParam, $lParam)
	Return DllCall("user32.dll", "lresult", "CallWindowProc", "ptr", $lpPrevWndFunc, "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)[0]
EndFunc   ;==>CallWindowProc

comment:3 Changed 4 years ago by Jpm

the last post from Anonymous was me (jpm)

comment:4 Changed 4 years ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

I assume that nobody will confirm that I was right
so I close it

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.