Hello. I was trying your penultimate script above and could improve it a bit (no more Adib but $HDN_ENDTRACK changed to $HDN_ITEMCHANGED, added _GUICtrlHeader_Destroy) etc...
The problem with a separate header control is that you'll have to add plenty of code in your script to get (nearly) the same results as a native Listview control (which takes care of its native header items), this means sorting listview columns by clicking their headers, changing header items order by dragging a header item at the left or right of another, double-clicking a header separator etc...)
For example, in my script below, please notice what will happen when you enlarge a header item : an horizontal scrollbar will appear in the listview. Now when you scroll horizontally, the headers items won't align the listview columns, so you'll have to take care of this part too etc...
Of course all these points could be fixed with additional code, it's up to you to decide if you're ready to add all this code to avoid flicker.
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
; DPI
DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -2)
Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration
Global $g_hGUI, $g_hChild
Global $g_hHeader, $g_idListview
Example()
Func Example()
$g_hGUI = GUICreate("Example", 400, 400, -1, -1, $WS_OVERLAPPEDWINDOW, $WS_EX_COMPOSITED)
GUISetBkColor(0x202020)
GUISetState(@SW_SHOW, $g_hGUI)
$g_hChild = GUICreate("ChildWindow", 320, 320, 40, 40, $WS_CHILD, -1, $g_hGUI)
GUISetBkColor(0x606060)
$g_hHeader = _GUICtrlHeader_Create($g_hChild)
_GUICtrlHeader_AddItem($g_hHeader, "Column1", 100)
_GUICtrlHeader_AddItem($g_hHeader, "Column2", 100)
_GUICtrlHeader_AddItem($g_hHeader, "Column3", 100)
$g_idListview = GUICtrlCreateListView("col1|col2|col3 ", 0, 24, 320, 295, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_NOCOLUMNHEADER), BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT))
For $i = 1 To 30
GUICtrlCreateListViewItem("item" & $i & "|item" & $i & "|item" & $i, $g_idListview)
Next
; resize listview columns to match header widths
_resizeLVCols()
GUISetState(@SW_SHOW, $g_hChild)
; get rid of dotted rectangle on listview, when an item got the focus
GUICtrlSendMsg($g_idListview, $WM_CHANGEUISTATE, 65537, 0)
GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_GUICtrlHeader_Destroy($g_hHeader) ; added
GUIDelete($g_hChild)
GUIDelete($g_hGUI)
EndFunc ;==>Example
Func _resizeLVCols()
For $i = 0 To _GUICtrlHeader_GetItemCount($g_hHeader) - 1
_GUICtrlListView_SetColumnWidth($g_idListview, $i, _GUICtrlHeader_GetItemWidth($g_hHeader, $i))
Next
EndFunc ;==>_resizeLVCols
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
Local $iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $g_hHeader
Switch $iCode
Case $HDN_ITEMCHANGED, $HDN_ITEMCHANGEDW
_resizeLVCols()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY