MyEarth Posted October 30, 2016 Share Posted October 30, 2016 (edited) Hello, There is an example in the Snippet can avoid sizing of a column of a listview. Work but doesn't avoid resize if used double click on the divider. Searching on the web i have found only solution like subclassing, too complex i want to avoid that. There is also something like this post: Quote hate to bump such an old thread, but either something was fixed over the years, or the previous poster was mistaken, but this additional WM_ block will prevent double-click resizing of columns... at least on XPnot sure of the constants (if there's a A/W versions...) but this is something i wanted so i hope someone else does... WM_NOTIFY(wParam, lParam, msg, hwnd) { Critical Static HDN_BEGINTRACKA = -306, HDN_BEGINTRACKW = -326, HDN_DIVIDERDBLCLICK = -320 Code := -(~NumGet(lParam+0, 8))-1 Return, Code = HDN_DIVIDERDBLCLICK || Code = HDN_BEGINTRACKA || Code = HDN_BEGINTRACKW ? True : "" } I have try to implement that code ( original code work ) but not work in autoit, at least like i have implemented expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <HeaderConstants.au3> $hGUI = GUICreate("ListView Fix Column Width", 400, 300) $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268) GUISetState() ; Prevent resizing of a specific column (0-based) Global $iFix_Col = 1 GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") Switch $iCode Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW, $HDN_DIVIDERDBLCLICK ; 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 Suggestion how to accomplish this or alternative solution to subclassing? UPDATE: In this way work, you cant resize $iFix_Col with double click Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") Switch $lParam Case 0x008CDD80 ; WHAT IS THIS? ; 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 Return $GUI_RUNDEFMSG EndFunc How i can get that 0x008CDD80 in a normal way? I have get it with ConsoleWrite and that binary is for double click on this system. Edited October 30, 2016 by MyEarth Link to comment Share on other sites More sharing options...
Danyfirex Posted October 30, 2016 Share Posted October 30, 2016 (edited) Hello. expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <HeaderConstants.au3> $hGUI = GUICreate("ListView Fix Column Width", 400, 300) $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268) GUISetState() ; Prevent resizing of a specific column (0-based) Global $iFix_Col = 1 GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") Switch $iCode Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW,$HDN_ITEMCHANGINGW ; 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 Saludos Edited October 30, 2016 by Danyfirex pixelsearch 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
MyEarth Posted October 30, 2016 Author Share Posted October 30, 2016 (edited) Work, without doubt. But you have replaced HDN_DIVIDERDBLCLICK with -320 but our HDN_DIVIDERDBLCLICK is -305 ( $HDN_FIRST - 5 ) Why $HDN_BEGINTRACK, $HDN_BEGINTRACKW are the same value instead HDN_DIVIDERDBLCLICK not? Maybe isn't HDN_DIVIDERDBLCLICK but another variable? If yes what? I'll ask you because want to avoid any problems on other system when i'll try and i'm also curious. UPDATE: Yes is a totally different variable: Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW, $HDN_ITEMCHANGING, $HDN_ITEMCHANGINGW Thanks for point me in the right direction and also to that authotkeyguy. No wait is a problem to use $HDN_ITEMCHANGING, stop to update the column... Edited October 30, 2016 by MyEarth Link to comment Share on other sites More sharing options...
Danyfirex Posted October 30, 2016 Share Posted October 30, 2016 HDN_DIVIDERDBLCLICK Notifies a header control's parent window that the user "double-clicked" You can't prevent resize. Instead use HDN_ITEMCHANGING ( -320 ) that allow prevent the changes. Return value Returns FALSE to allow the changes, or TRUE to prevent them. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
MyEarth Posted October 30, 2016 Author Share Posted October 30, 2016 Yes i was right: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <HeaderConstants.au3> $hGUI = GUICreate("ListView Fix Column Width", 400, 300) $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268) GUISetState() ; Prevent resizing of a specific column (0-based) Global $iFix_Col = 1 GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") _GUICtrlListView_SetColumnWidth($hListView, 1, 10) ; this not work if $HDN_ITEMCHANGING, $HDN_ITEMCHANGINGW is enabled ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") Switch $iCode Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW;, $HDN_ITEMCHANGING, $HDN_ITEMCHANGINGW ; 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 I need some workaroud or another way. Link to comment Share on other sites More sharing options...
Danyfirex Posted October 30, 2016 Share Posted October 30, 2016 (edited) Probably you can do something like this. expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <HeaderConstants.au3> Global $g__Prevent = True ;internal use Prevent or no Prevent with _GUICtrlListView_SetColumnWidthEx $hGUI = GUICreate("ListView Fix Column Width", 400, 300) $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268) GUISetState() ; Prevent resizing of a specific column (0-based) Global $iFix_Col = 1 GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") _GUICtrlListView_SetColumnWidthEx($hListView, 1, 10) ;now work Sleep(1000) _GUICtrlListView_SetColumnWidthEx($hListView, 1, 100) ;now work ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") Switch $iCode Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW, $HDN_ITEMCHANGING, $HDN_ITEMCHANGINGW ; Now get column being resized Local $iCol = DllStructGetData($tNMHEADER, "Item") If $iCol = $iFix_Col And $g__Prevent Then ; Prevent resizing Return True Else ; Allow resizing Return False EndIf EndSwitch EndFunc ;==>_WM_NOTIFY Func _GUICtrlListView_SetColumnWidthEx($hWnd, $iCol, $iWidth) Local $iRet = 0 $g__Prevent = False If IsHWnd($hWnd) Then $iRet = _SendMessage($hWnd, $LVM_SETCOLUMNWIDTH, $iCol, $iWidth) Else $iRet = GUICtrlSendMsg($hWnd, $LVM_SETCOLUMNWIDTH, $iCol, $iWidth) EndIf $g__Prevent = True Return $iRet EndFunc ;==>_GUICtrlListView_SetColumnWidthEx Saludos Edited October 30, 2016 by Danyfirex Rename variable Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 30, 2016 Moderators Share Posted October 30, 2016 (edited) MyEarth, I would do it this way: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <HeaderConstants.au3> $hGUI = GUICreate("ListView Fix Column Width", 500, 500) $cLV = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 10, 10, 420, 300) For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($cLV, $i, 100) Next GUISetState() ; Prevent resizing of a specific column (0-based) Global $aFix_Col[][] = [[1, 100]] GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") ; Get column Local $iCol = DllStructGetData($tNMHEADER, "Item") Switch $iCode Case $HDN_DIVIDERDBLCLICK, $HDN_DIVIDERDBLCLICKW ; Divider double click For $i = 0 To UBound($aFix_Col) - 1 If $iCol = $aFix_Col[$i][0] Then _GUICtrlListView_SetColumnWidth($cLV, $iCol, $aFix_Col[$i][1]) ExitLoop EndIf Next Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW ; Divider drag For $i = 0 To UBound($aFix_Col) - 1 If $iCol = $aFix_Col[$i][0] Then Return True ExitLoop EndIf Next Return False EndSwitch EndFunc You do need to know the fixed column width you require, but then is that not why you want it fixed? M23 Edit: And thanks for showing me that the header could be resized by a double-click on the divider - I have just been modifying my GUIListViewEx UDF to prevent this using the same trick as above. Edited October 30, 2016 by Melba23 pixelsearch 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now