Jump to content

How can you CUSTOMDRAW ListView header by State? (CDIS_HOT, etc.)


Go to solution Solved by Nine,

Recommended Posts

Posted
2 hours ago, Nine said:

I was running in x86.  Changing it to x64, made it freeze almost instantly.

I decided to test with x86 now by using "#AutoIt3Wrapper_UseX64=N" and confirmed via Task Manager that it was running under 32-bit AutoIt binary. I was just able to reproduce the crash on x86 as well using the same methods.

I don't quite understand why _WinAPI_SetWindowTheme() would be causing this.

Posted

I believe the issue comes from subclassing the header.  I tried with your suggestion to use _WinAPI_SetWindowLong with $GWL_WNDPROC on header and it gives the same erroneous behavior as I noted before. Since I do not have access to actual internal code, I can't help much for that matter.  At this point, I do not have an elegant solution to provide.

ps.  I observe the same partial freezing on whatever subclass method I use over header...

Posted (edited)
17 hours ago, Nine said:

Looks to me it is an AutoIt bug, but I cannot be sure.  We would need to try the same in another language see if it is what I suspect.

I found a sysheader32 subclass in the win32-darkmodelib that is in c++. Very reputable project and the same developer who does the majority of darkmode related work on Notepad++. I don't understand c++ well, but I did compile it in x64 and the Demo GUI runs the header subclass without any issue.

Link to header subclass code: Link

Code (looks similar to yours):

/**
 * @brief Window subclass procedure for owner drawn header control.
 *
 * @param[in]   hWnd        Window handle being subclassed.
 * @param[in]   uMsg        Message identifier.
 * @param[in]   wParam      Message-specific data.
 * @param[in]   lParam      Message-specific data.
 * @param[in]   uIdSubclass Subclass identifier.
 * @param[in]   dwRefData   HeaderData instance.
 * @return LRESULT Result of message processing.
 *
 * @see dmlib::setHeaderCtrlSubclass()
 * @see dmlib::removeHeaderCtrlSubclass()
 */
LRESULT CALLBACK dmlib_subclass::HeaderSubclass(
    HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam,
    UINT_PTR uIdSubclass,
    DWORD_PTR dwRefData
)
{
    auto* pHeaderData = reinterpret_cast<HeaderData*>(dwRefData);
    auto& themeData = pHeaderData->m_themeData;
    const auto& hMemDC = pHeaderData->m_bufferData.getHMemDC();

    switch (uMsg)
    {
        case WM_NCDESTROY:
        {
            ::RemoveWindowSubclass(hWnd, HeaderSubclass, uIdSubclass);
            std::unique_ptr<HeaderData> u_ptrData(pHeaderData);
            u_ptrData.reset();
            break;
        }

        case WM_ERASEBKGND:
        {
            if (!dmlib::isEnabled() || !themeData.ensureTheme(hWnd))
            {
                break;
            }

            if (reinterpret_cast<HDC>(wParam) != hMemDC)
            {
                return FALSE;
            }
            return TRUE;
        }

        case WM_PAINT:
        {
            if (!dmlib::isEnabled())
            {
                break;
            }

            PAINTSTRUCT ps{};
            HDC hdc = ::BeginPaint(hWnd, &ps);

            if (!dmlib_paint::isRectValid(ps.rcPaint))
            {
                ::EndPaint(hWnd, &ps);
                return 0;
            }

            dmlib_paint::PaintWithBuffer<HeaderData>(*pHeaderData, hdc, ps,
                [&]() { paintHeader(hWnd, hMemDC, *pHeaderData); },
                hWnd);

            ::EndPaint(hWnd, &ps);
            return 0;
        }

        case WM_DPICHANGED_AFTERPARENT:
        {
            themeData.closeTheme();
            return 0;
        }

        case WM_THEMECHANGED:
        {
            themeData.closeTheme();
            break;
        }

        case WM_LBUTTONDOWN:
        {
            if (!pHeaderData->m_hasBtnStyle)
            {
                break;
            }

            pHeaderData->m_isPressed = true;
            break;
        }

        case WM_LBUTTONUP:
        {
            if (!pHeaderData->m_hasBtnStyle)
            {
                break;
            }

            pHeaderData->m_isPressed = false;
            break;
        }

        case WM_MOUSEMOVE:
        {
            if (!pHeaderData->m_hasBtnStyle || pHeaderData->m_isPressed)
            {
                break;
            }

            TRACKMOUSEEVENT tme{};

            if (!pHeaderData->m_isHot)
            {
                tme.cbSize = sizeof(TRACKMOUSEEVENT);
                tme.dwFlags = TME_LEAVE;
                tme.hwndTrack = hWnd;

                ::TrackMouseEvent(&tme);

                pHeaderData->m_isHot = true;
            }

            pHeaderData->m_pt.x = GET_X_LPARAM(lParam);
            pHeaderData->m_pt.y = GET_Y_LPARAM(lParam);

            ::InvalidateRect(hWnd, nullptr, FALSE);
            break;
        }

        case WM_MOUSELEAVE:
        {
            if (!pHeaderData->m_hasBtnStyle)
            {
                break;
            }

            const LRESULT retVal = ::DefSubclassProc(hWnd, uMsg, wParam, lParam);

            pHeaderData->m_isHot = false;
            pHeaderData->m_pt.x = LONG_MIN;
            pHeaderData->m_pt.y = LONG_MIN;

            ::InvalidateRect(hWnd, nullptr, TRUE);

            return retVal;
        }

        default:
        {
            break;
        }
    }
    return ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

 

14 hours ago, Nine said:

ps.  I observe the same partial freezing on whatever subclass method I use over header...

Indeed, I have noticed the same as well. I tried various subclassing methods and even tried splitting into two functions, one for the ListView subclass and one for the Header subclass to see if that would help at all. But all failed.

I find it interesting how the bug (freeze) comes at completely random times. It can work well and proper for 30-60 seconds or more sometimes and then it decides it is done and does the freeze.

If it is an AutoIt bug, it would be nice if it could be fixed. Although I would imagine that would not be easy to determine where the bug is and especially since we have no access to the internal code.

I want to thank you again for your time and patience with everything, anytime you help someone. It is appreciated very much. :)

On a side note, I am also thinking that we likely cannot take this any further. I feel like we are right at the finish line with something nice, but the finish line keeps moving back on us. I also noticed some other unforeseen issues. For example, enabling LVS_EX_HEADERDRAGDROP and dragging ListView columns works for a little bit. But if the scrollbar is visible, it get sketchy and has some flickering issue but also eventually freezes the GUI as well. So I think that it is time to move on from this idea, unfortunately. It has certainly been fun and a learning experience as always.

Edited by WildByDesign
Posted
5 minutes ago, WildByDesign said:

If it is an AutoIt bug, it would be nice if it could be fixed. Although I would imagine that would not be easy to determine where the bug is and especially since we have no access to the internal code.

We need some GUI lover ... @jpm could you take a look here ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

not freeze

#AutoIt3Wrapper_UseX64=y

; From Nine
#include <GuiConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>

Example()

Func Example()
  Local $hGUI = GUICreate("Header issue", 500, 300)

  Local $idListView = GUICtrlCreateListView("Items List|SubItems1|SubItems2", 10, 10, 480, 280, -1, $LVS_EX_DOUBLEBUFFER)
  Local $hListView = GUICtrlGetHandle($idListView)
  Local $hHeader = GUICtrlSendMsg($idListView, $LVM_GETHEADER, 0, 0)

  Local $hSubClass = DllCallbackRegister(WM_NOTIFY, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr")
  _WinAPI_SetWindowSubclass($hHeader, DllCallbackGetPtr($hSubClass), 1000)

  For $i = 1 To 5
    GUICtrlCreateListViewItem("item" & $i & "|item" & $i & "|item" & $i , $idListview)
  Next

  GUISetState()

  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE

  _WinAPI_RemoveWindowSubclass($hHeader, DllCallbackGetPtr($hSubClass), 1000)
  DllCallbackFree($hSubClass)
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam, $iID, $pData)
  Return __WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>WM_NOTIFY



Func __WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
    Return DllCall('comctl32.dll', 'lresult', 'DefSubclassProc', 'hwnd', $hWnd, 'uint', $iMsg, 'wparam', $wParam, _
            'lparam', $lParam)[0]
EndFunc   ;==>_WinAPI_DefSubclassProc

 

Same problem with _WinAPI_CallWindowProc:

#AutoIt3Wrapper_UseX64=y

; From Nine
#include <GuiConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>

Global $g_hProcOld

Example()

Func Example()
  Local $hGUI = GUICreate("Header issue", 500, 300)

  Local $idListView = GUICtrlCreateListView("Items List|SubItems1|SubItems2", 10, 10, 480, 280, -1, $LVS_EX_DOUBLEBUFFER)
  Local $hListView = GUICtrlGetHandle($idListView)
  Local $hHeader = GUICtrlSendMsg($idListView, $LVM_GETHEADER, 0, 0)

  Local $hSubClass = DllCallbackRegister(WM_NOTIFY, "lresult", "hwnd;uint;wparam;lparam")
 $g_hProcOld = _WinAPI_SetWindowLong($hHeader, $GWL_WNDPROC, DllCallbackGetPtr($hSubClass))

  For $i = 1 To 5
    GUICtrlCreateListViewItem("item" & $i & "|item" & $i & "|item" & $i , $idListview)
  Next

  GUISetState()

  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE

  _WinAPI_SetWindowLong($hHeader, $GWL_WNDPROC, $g_hProcOld)
  DllCallbackFree($hSubClass)
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
;  Return _WinAPI_CallWindowProc($g_hProcOld, $hWnd, $iMsg, $wParam, $lParam)   ;~~ code freeze
  Return __WinAPI_CallWindowProc($g_hProcOld, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>WM_NOTIFY


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

 

Edited by jugador
Posted (edited)
42 minutes ago, jugador said:

not freeze

This is interesting. Thank you. :)

So from my understanding, this just skips the error check on the call to DefSubclassProc (and skips error check on CallWindowProc on the other code) to prevent the freeze?

EDIT: I added that fix to the easily reproducible script from this post which would normally freeze within seconds. No more freeze.

EDIT2: I spoke too soon, 5 seconds after my first edit it froze.

Edited by WildByDesign
Posted (edited)

@WildByDesign

not sure but I think it crashed due to _GUICtrlHeader_GetItemText not for _WinAPI_SetWindowSubclass

change to check if it crash (within case $CDDS_ITEMPREPAINT):

Local $sText = 'Testing'
_WinAPI_InflateRect($tRect, -5, -2)
_WinAPI_DrawText($tCustDraw.hDC, $sText, $tRect, BitOR($DT_LEFT, $DT_NOCLIP))

 

Edited by jugador
Posted (edited)
59 minutes ago, jugador said:

I think it crashed due to _GUICtrlHeader_GetItemText

I think you are right. I changed it as you suggest and cannot cause the freeze at all anymore. Thank you. :)

  1. How did you figure out that _GUICtrlHeader_GetItemText() was the cause of the crash?
  2. Also, is there an alternative way for me to get the header text without the crash?

EDIT: This also solved the crash with during header drag and drop (LVS_EX_HEADERDRAGDROP). :)

EDIT2: Just to be clear, your fix with DefSubclassProc was also required to fix my issue. So in my case, _GUICtrlHeader_GetItemText and DefSubclassProc were both causing the GUI to freeze as two separate issues.

Edited by WildByDesign
Posted (edited)

Answer 2: yes WM_NOTIFY

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

WildByDesign  

This whole problem reminds me of the case I had recently here

and I already noticed that _GUICtrlHeader_GetItemText also uses the __GUICtrl_SendMsg function

so as a tip I would say to try @Nine 's fix, maybe it will solve the problem  :unsure:

The fixing concerns the __GUICtrl_SendMsg function, in the file  "C:\Program Files (x86)\AutoIt3\Include\GuiCtrlInternals.au3"

Func __GUICtrl_SendMsg($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement)
    If $iElement > 0 Then
        DllStructSetData($tItem, $iElement, DllStructGetPtr($tBuffer))
        If $iElement = $iElementMax Then DllStructSetData($tItem, $iElement + 1, DllStructGetSize($tBuffer))
    EndIf

    Local $iRet
    If IsHWnd($hWnd) Then
        If ($hWnd = $__g_hGUICtrl_LastWnd) Or (DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", 0)[2] = @AutoItPID) Then ; _WinAPI_InProcess
            $__g_hGUICtrl_LastWnd = $hWnd
            $iRet = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "struct*", $tItem)[0]
        Else
            Local $iItem = Ceiling(DllStructGetSize($tItem) / 16) * 16 ; to allocate buffer on a 16 byte boundary
            Local $tMemMap, $pText
            Local $iBuffer = 0
            If ($iElement > 0) Or ($iElementMax = 0) Then $iBuffer = DllStructGetSize($tBuffer)
            Local $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap)
            If $iBuffer Then
                $pText = $pMemory + $iItem
                If $iElementMax Then
                    DllStructSetData($tItem, $iElement, $pText)
                Else
                    $iIndex = $pText
                EndIf
                _MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
            EndIf
            _MemWrite($tMemMap, $tItem, $pMemory, $iItem)
            $iRet = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "ptr", $pMemory)[0]
            If $iBuffer And $bRetBuffer Then
                _MemRead($tMemMap, $pText, $tBuffer, $iBuffer)
            EndIf
            ; !!! @Nine: https://www.autoitscript.com/forum/topic/213108-_guictrltab_getitemtext-the-target-crashes-on-dissimilar-architecture/#findComment-1551027
            ; If $bRetItem Then _MemRead($tMemMap, $pMemory, $tItem, $iItem) ; *** original line
            If $bRetItem Then _MemRead($tMemMap, $pMemory, $tItem, DllStructGetSize($tItem)) ; *** @Nine fixing

            _MemFree($tMemMap)
        EndIf
    Else
        $iRet = GUICtrlSendMsg($hWnd, $iMsg, $iIndex, DllStructGetPtr($tItem))
    EndIf

    Return $iRet
EndFunc   ;==>__GUICtrl_SendMsg

 

I know that I know nothing

Posted
17 minutes ago, ioa747 said:

This whole problem reminds me of the case I had recently here

and I already noticed that _GUICtrlHeader_GetItemText also uses the __GUICtrl_SendMsg function

That is interesting. I remember reading along with that thread when you had first posted it.

There seems to be a bunch of x64 related bugs recently. But it is great to see the bugs getting tickets and fixes.

I have a feeling that a lot of AutoIt users still have the default of running scripts as x86 because, if I recall correctly, the installer does x86 by default. If that is the case, it could have been preventing some discovery of x64 related bugs over the years.

17 minutes ago, ioa747 said:

so as a tip I would say to try @Nine 's fix, maybe it will solve the problem  :unsure:

The fixing concerns the __GUICtrl_SendMsg function, in the file  "C:\Program Files (x86)\AutoIt3\Include\GuiCtrlInternals.au3"

I made the change to the __GUICtrl_SendMsg function but unfortunately _GUICtrlHeader_GetItemText still causes the GUI the freeze for me. Maybe has something to do with how sensitive the header subclass can be with regard to overall performance of functions. I could have the header item text stored in array and I have a feeling that it would solve the problem which is good, but that would take away some of the automated approach that I prefer to use.

Posted
28 minutes ago, mLipok said:

Answer 2: yes WM_NOTIFY

Thank you. I will have to try this suggestion. I do have a WM_NOTIFY function (in GUIDarkTheme UDF), so it will be easy for me to try for testing.

 

Posted (edited)

@ioa747  Thanks for reminding me.  I forgot to make the change permanent (now it's done).  I must be getting old :D

After that I am unable to make the script to freeze (both x86 and x64).  Been trying for 20 mins.

ps.  there is still an issue with the subclass method we are using.  If you comment out both $HDN_BEGINTRACKW and $HDN_ENDTRACKW, it will crash instantly when resizing a column.

pps. after looking at the code, it cannot be that bug since the function is not returning the value ($bRetItem is false).  So I was just lucky, it seems...

ppps. yes just lucky, it just froze on me :(

Edited by Nine
Posted
5 hours ago, WildByDesign said:

EDIT2: Just to be clear, your fix with DefSubclassProc was also required to fix my issue. So in my case, _GUICtrlHeader_GetItemText and DefSubclassProc were both causing the GUI to freeze as two separate issues.

yes

5 hours ago, WildByDesign said:
  1. Also, is there an alternative way for me to get the header text without the crash?

no  idea..

Posted

Found another bug in _GUICtrlHeader_GetItemText (and a lot of other functions)

as described in MSND

Quote

cchTextMax

Type: int

The length of the item string, in TCHARs

It is not calculated in term of bytes.  Not sure that it has a real impact in normal situation, but still a misunderstanding of MSDN.

 

Posted (edited)
48 minutes ago, Nine said:

It is not calculated in term of bytes

Please describe difference between bytes length and TCHARs length.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

_GUICtrlHeader_GetItemText is causing problems because of SendMessage.
To fix this, only read the ListView header if the handle ($hFrom) changes.

You can do this:

Local Static $sString = '', $aHeaderList, $fhFrom = 0, $fFlag = False

 

If $fhFrom <> $hFrom Then
    $fhFrom = $hFrom
    $fFlag = True
Endif

If $fFlag = True Then
    $fFlag = False
    Local $sCount = _GUICtrlHeader_GetItemCount($tCustDraw.hWndFrom)

    For $i = 0 To $sCount - 1
        $sString &= _GUICtrlHeader_GetItemText($tCustDraw.hWndFrom, $i) & '|'
    Next
    ConsoleWrite("Drawing Header Column: " & $sString & @CRLF)
    $aHeaderList = StringRegExp($sString, "[^|]+", 3)
Endif

 

_WinAPI_DrawText($tCustDraw.hDC, $aHeaderList[$tCustDraw.dwItemSpec], $tRect, BitOR($DT_LEFT, $DT_NOCLIP))

 

Edited by jugador

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
×
×
  • Create New...