#AutoIt3Wrapper_UseX64=n
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include "Thread.au3"
_Main()
Func _Main()
Local $hGUI = GUICreate("test", 400, 300)
GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM")
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUICtrlCreateListView("", 5, 5, 390, 290, $LVS_REPORT + $LVS_OWNERDRAWFIXED)
Local $hListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES + $LVS_EX_DOUBLEBUFFER + $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetBkColor($hListView, 0xC0DBC1)
_GUICtrlListView_SetTextBkColor($hListView, 0xC0DBC1)
_GUICtrlListView_AddColumn($hListView, "Col 1", 100, 2)
_GUICtrlListView_AddColumn($hListView, "Col 2", 100, 2)
_GUICtrlListView_AddColumn($hListView, "Col 3", 100, 2)
_GUICtrlListView_AddItem($hListView, "AnvilHole123")
_GUICtrlListView_AddItem($hListView, "Hello world")
_GUICtrlListView_AddItem($hListView, "Hello" & @CRLF & "world")
_GUICtrlListView_AddSubItem($hListView, 0, "123" & @CRLF & "456", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "123456", 1)
_GUICtrlListView_AddSubItem($hListView, 2, "123" & @CRLF & "456", 2)
SetHook()
GUISetState(@SW_SHOW, $hGUI)
While GUIGetMsg() <> -3
WEnd
GUIDelete($hGUI)
EndFunc ;==>_Main
Func SetHook()
Local $pProcedure = _RTGetProcAddress("User32.dll", "DrawTextExW")
Local $pRedirect = _RTVirtualAlloc(4096)
_RTVirtualProtect($pProcedure, 8)
If @AutoItX64 Then
; TODO: set x64 hook...
Else
Local $tSetJump = DllStructCreate("align 1;UBYTE jmp_long;DWORD offset;WORD jmp_short", $pProcedure - 5)
Local $tRedirect = DllStructCreate("align 1;UBYTE code[5];UBYTE jmp_long;DWORD offset", $pRedirect)
DllStructSetData($tSetJump, "jmp_long", 0xE9)
DllStructSetData($tSetJump, "offset", $pRedirect - $pProcedure)
DllStructSetData($tSetJump, "jmp_short", 0xF9EB)
DllStructSetData($tRedirect, "code", Binary("0x83642414DF")) ; and dword ptr [esp+14], not DT_SINGLELINE
DllStructSetData($tRedirect, "jmp_long", 0xE9)
DllStructSetData($tRedirect, "offset", $pProcedure + 2 - ($pRedirect + 10))
EndIf
EndFunc ;==>SetHook
Func WM_MEASUREITEM($hWnd, $iMsg, $wParam, $lParam)
Local Const $ODT_LISTVIEW = 102
Local Const $tagMEASUREITEMSTRUCT = "UINT CtlType;UINT CtlID;UINT itemID;UINT itemWidth;UINT itemHeight;ULONG_PTR itemData"
Local $tMeasureItem = DllStructCreate($tagMEASUREITEMSTRUCT, $lParam)
If DllStructGetData($tMeasureItem, "CtlType") == $ODT_LISTVIEW Then
DllStructSetData($tMeasureItem, "itemHeight", 40)
Return 1
EndIf
EndFunc ;==>WM_MEASUREITEM
Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
Local Const $ODT_LISTVIEW = 102
Local $tDrawItem = DllStructCreate("UINT CtlType;UINT CtlID", $lParam)
If DllStructGetData($tDrawItem , "CtlType") == $ODT_LISTVIEW Then
Local $hListView = _WinAPI_GetDlgItem($hWnd, DllStructGetData($tDrawItem, "CtlID"))
Local $iStyle = _WinAPI_GetWindowLong($hListView, $GWL_STYLE)
$iStyle = BitAND($iStyle, BitNOT($LVS_OWNERDRAWFIXED))
_WinAPI_SetWindowLong($hListView, $GWL_STYLE, $iStyle)
_WinAPI_InvalidateRect($hListView)
EndIf
Return 1
EndFunc ;==>WM_DRAWITEM