Jump to content

How to mark ListView Column?


Recommended Posts

Hi,

I know that we can select a ListView column like this:

GUICtrlSendMsg($ListView, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($ListView), 0)oÝ÷ Ø­
.ÙbëhªäØî²Ø§¶¡y§^­«%Ûeyªë£    bé&©¦Çhz¶·¶*'¡û(®Ø§+5jºèÁÚ0'õ¶§jºèÂêGz·¢±§îW±jje{­Ê+)à.+-V'°¢¸ v¥r^fw¢·lÁ«)¢Ë^v«zߢ»¦o+(ê'z)ÞyÛhªä¶¢[¦ëÞ¯+bè©­ë,¶¢[¦uêÛºÛh«­¢+Ø¥¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì)±½°
½¹ÍÐÀÌØí1Y5}Q%Q4$ôÀÌØí1Y5}%IMP¬Ô()±½°ÀÌØí¹
ÕÉɹÑ
½±Õµ¸$$ô´Ä)±½°ÀÌØí¹M½ÉÑ¥È$$$ôÄ)±½°ÀÌØí¹M½ÉÑMÐ$$$ôÀ)±½°ÀÌØí¹
½±Õµ¹MÐ$$$ô´Ä((ÀÌØí¡U$ôU%
ÉÑ ÅÕ½ÐíQMPA@ÌÌìÅÕ½Ðì¤(ÀÌØí1¥ÍÑY¥ÜôU%
Ñɱ
ÉÑ1¥ÍÑY¥Ü ÅÕ½Ðí
½±Õµ¸Åñ
½±Õµ¸Éñ
½±Õµ¸ÌÅÕ½Ðì°À°ÔÀ°ÔÀÀ°ÐÀÀ°ÀÌØí]M}YM
I=10°ÀÌØí1YM}a}
!
-   =aL¬ÀÌØí1YM}a}I%1%9L¤)U%
ÑɱI¥ÍÑÉ1¥ÍÑY¥ÝM½ÉÐ ´Ä°ÅÕ½Ðí1¥ÍÑY¥Ý}M½ÉÑ}AɽÅÕ½Ðì¤ìI¥ÍÑÈѡչѥ½¸ÅÕ½Ðí1¥ÍÑY¥Ý}M½ÉÑ}AɽÅÕ½Ðì½ÈѡͽÉÑ¥¹±±¬()U%
Ñɱ
ÉÑ1¥ÍÑY¥Ý%Ñ´ ÅÕ½ÐìÐÐÑðÐÐÑðÐÐÐÅÕ½Ðì°ÀÌØí1¥ÍÑY¥Ü¤)U%
ÑɱMÑ%µ ´Ä°ÅÕ½ÐíÍ¡±°Ìȹ±°ÅÕ½Ðì°ÄÀ¤)U%
Ñɱ
ÉÑ1¥ÍÑY¥Ý%Ñ´ ÅÕ½ÐìÌÌÍðÌÌÍðÌÌÌÅÕ½Ðì°ÀÌØí1¥ÍÑY¥Ü¤)U%
ÑɱMÑ%µ ´Ä°ÅÕ½ÐíÍ¡±°Ìȹ±°ÅÕ½Ðì°Ü¤)U%
Ñɱ
ÉÑ1¥ÍÑY¥Ý%Ñ´ ÅÕ½ÐìÈÈÉðÈÈÉðÈÈÈÅÕ½Ðì°ÀÌØí1¥ÍÑY¥Ü¤)U%
ÑɱMÑ%µ ´Ä°ÅÕ½ÐíÍ¡±°Ìȹ±°ÅÕ½Ðì°Ð¤)U%
Ñɱ
ÉÑ1¥ÍÑY¥Ý%Ñ´ ÅÕ½ÐìÄÄÅðÄÄÅðÄÄÄÅÕ½Ðì°ÀÌØí1¥ÍÑY¥Ü¤)U%
ÑɱMÑ%µ ´Ä°ÅÕ½ÐíÍ¡±°Ìȹ±°ÅÕ½Ðì°à¤()U%MÑMÑÑ¡M]}M!=°ÀÌØí¡U$¤()]¡¥±Ä(%MÝ¥Ñ U%Ñ5Í ¤($%
ÍÀÌØíU%}Y9Q}
1=M($$%á¥Ñ1½½À($%
ÍÀÌØí1¥ÍÑY¥Ü($$$ÀÌØí¹M½ÉÑMÐôÀ($$$ÀÌØí¹
ÕÉɹÑ
½±Õµ¸ôÀÌØí¹
½±Õµ¹MÐ($$$($$$íQ¡¥Ì¹Ñ¼ÉÁ±¸¸¸ÕÐÝ¥Ñ Ý¡ÐüÌÌì($$%U%
ÑɱM¹5Í ÀÌØí1¥ÍÑY¥Ü°ÀÌØí1Y5}MQM1
Q
=1U58°U%
ÑɱÑMÑÑ ÀÌØí1¥ÍÑY¥Ü¤°À¤($$%±±
±° ÅÕ½ÐíÕÍÈÌȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½Ðí%¹Ù±¥ÑIÐÅÕ½Ðì°ÅÕ½Ðí¡Ý¹ÅÕ½Ðì°U%
ÑɱÑ!¹± ÀÌØí1¥ÍÑY¥Ü¤°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°À°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°Ä¤(%¹MÝ¥Ñ )]¹((ì=ÕÈͽÉÑ¥¹±±¬Õ¹Ñ¥½¸)Õ¹1¥ÍÑY¥Ý}M½ÉÑ}Aɽ ÀÌØí¡]¹°ÀÌØí¹%Ñ´Ä°ÀÌØí¹%Ñ´È°ÀÌØí¹
½±Õµ¸¤(%1½°ÀÌØí¹M½ÉаÀÌØí¥Y°Ä°ÀÌØí¥Y°È($($ìMÝ¥Ñ Ñ¡Í½ÉÑ¥¹¥ÉÑ¥½¸(%%ÀÌØí¹
½±Õµ¸ôÀÌØí¹
ÕÉɹÑ
½±Õµ¸Q¡¸($%%9½ÐÀÌØí¹M½ÉÑMÐQ¡¸($$$ÀÌØí¹M½ÉѥȨô´Ä($$$ÀÌØí¹M½ÉÑMÐôÄ($%¹%(%±Í($$ÀÌØí¹M½ÉÑ¥ÈôÄ(%¹%($($ÀÌØí¹
½±Õµ¹MÐôÀÌØí¹
½±Õµ¸($($ÀÌØí¥Y°Äô}U%
Ñɱ1¥ÍÑY¥Ý}ÑMÕ%ѵQáÐ ÀÌØí1¥ÍÑY¥Ü°ÀÌØí¹%Ñ´Ä°ÀÌØí¹
½±Õµ¸¤($ÀÌØí¥Y°Èô}U%
Ñɱ1¥ÍÑY¥Ý}ÑMÕ%ѵQáÐ ÀÌØí1¥ÍÑY¥Ü°ÀÌØí¹%Ñ´È°ÀÌØí¹
½±Õµ¸¤($($ÀÌØí¹IÍÕ±ÐôÀì9¼¡¹½¥Ñ´Ä¹¥Ñ´ÈÁ½Í¥Ñ¥½¹Ì($(%%ÀÌØí¥Y°Ä±ÐìÀÌØí¥Y°ÈQ¡¸($$ÀÌØí¹IÍÕ±Ðô´ÄìAÕХѴȽɥѴÄ(%±Í%ÀÌØí¥Y°ÄÐìÀÌØí¥Y°ÈQ¡¸($$ÀÌØí¹IÍÕ±ÐôÄìAÕХѴȡ¥¹¥Ñ´Ä(%¹%($(%IÑÕɸÀÌØí¹IÍձШÀÌØí¹M½ÉÑ¥È)¹Õ¹((ìIÑÉ¥ÙÑ¡Ñáн±¥ÍÑ٥ܥѴ¥¸ÍÁ¥¥½±Õµ¸)Õ¹}U%
Ñɱ1¥ÍÑY¥Ý}ÑMÕ%ѵQáÐ ÀÌØí¹
Ñɱ%°ÀÌØí¹%ѵ%°ÀÌØí¹
½±Õµ¸¤(%1½°ÀÌØíÍÑ1Ù¤ô±±MÑÉÕÑ
ÉÑ ÅÕ½ÐíÕ¥¹ÐíÁÑÈí¥¹Ðí¥¹ÑlÉtí¥¹ÐÅÕ½Ðì¤(%±±MÑÉÕÑMÑÑ ÀÌØíÍÑ1Ù¤°Ä°ÀÌØí1Y%}AI4¤(%±±MÑÉÕÑMÑÑ ÀÌØíÍÑ1Ù¤°Ì°ÀÌØí¹%ѵ%¤($(%1½°ÀÌØíÍÑ ÕÈô±±MÑÉÕÑ
ÉÑ ÅÕ½Ðí¡ÉlÈØÁtÅÕ½Ðì¤(%1½°ÀÌØí¹%¹àôU%
ÑɱM¹5Í ÀÌØí¹
Ñɱ%°ÀÌØí1Y5}%9%Q4°´Ä°±±MÑÉÕÑÑAÑÈ ÀÌØíÍÑ1Ù¤¤¤ì(%1½°ÀÌØíÍÑ1Ù¤ô±±MÑÉÕÑ
ÉÑ ÅÕ½ÐíÕ¥¹Ðí¥¹Ðí¥¹ÐíÕ¥¹ÐíÕ¥¹ÐíÁÑÈí¥¹Ðí¥¹Ðí¥¹Ðí¥¹ÐÅÕ½Ðì¤($(%±±MÑÉÕÑMÑÑ ÀÌØíÍÑ1Ù¤°Ä°ÀÌØí1Y%}QaP¤(%±±MÑÉÕÑMÑÑ ÀÌØíÍÑ1Ù¤°È°ÀÌØí¹%¹à¤(%±±MÑÉÕÑMÑÑ ÀÌØíÍÑ1Ù¤°Ì°ÀÌØí¹
½±Õµ¸¤(%±±MÑÉÕÑMÑÑ ÀÌØíÍÑ1Ù¤°Ø°±±MÑÉÕÑÑAÑÈ ÀÌØíÍÑ   ÕȤ¤(%±±MÑÉÕÑMÑÑ ÀÌØíÍÑ1Ù¤°Ü°ÈØÀ¤($(%U%
ÑɱM¹5Í ÀÌØí¹
Ñɱ%°ÀÌØí1Y5}Q%Q4°À°±±MÑÉÕÑÑAÑÈ ÀÌØíÍÑ1Ù¤¤¤ì($(%IÑÕɸ±±MÑÉÕÑÑÑ ÀÌØíÍÑ  ÕȰĤ)¹Õ¹

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

MrCreatoR

Hello friend! Example from help file:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Global $hListView

_Example1()

Func _Example1()
    Local $hImage, $aIcons[3] = [0, 3, 6]
    Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
    Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

    GUICreate("ListView Sort", 300, 200)

    $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)

    ; Load images
    $hImage = _GUIImageList_Create(18, 18, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -7)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -12)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -5)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -6)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -9)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -10)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -11)
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    _AddRow($hListView, "ABC|000666|10.05.2004", $aIcons)
    _AddRow($hListView, "DEF|444|11.05.2005", $aIcons, 1)
    _AddRow($hListView, "CDE|555|12.05.2004", $aIcons, 2)
    
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUISetState()

    _GUICtrlListView_RegisterSortCallBack($hListView)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hListView
                ; Kick off the sort callback
                ;_GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($hListView)
    GUIDelete()
EndFunc   ;==>_Example1

Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0)
    Local $aItem = StringSplit($sItem, "|")
    Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 9999)
    _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER)

    For $x = 2 To $aItem[0]
        _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus)
        _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE)
    Next
EndFunc   ;==>_AddRow

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView

    $hWndListView = $hListView
    
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

                    ; Kick off the sort callback
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
            EndSwitch
    EndSwitch
    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
muttley
Link to comment
Share on other sites

Beautiful! Thank you rasim, and to the guy that make it possible (Gary muttley ).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Ok, now i am struggling to make it work on the 3.2.8.1 version (yep, some of us still use that version muttley)...

Here is the transformed example + functions:

#include <GuiListView.au3>
#include <DllCallBack.au3>

; for use with the sort call back functions
Global $iLListViewSortInfoSize = 11
Global $aListViewSortInfo[1][$iLListViewSortInfoSize]

Global Const $LVN_FIRST = -100

Global Const $LVM_SORTITEMS = ($LVM_FIRST + 48)
Global Const $LVN_COLUMNCLICK = ($LVN_FIRST - 8)

Global Const $tagHDITEM = "int Mask;int XY;ptr Text;hwnd hBMP;int TextMax;int Fmt;int Param;int Image;int Order;int Type;ptr pFilter;int State"
Global Const $tagNMHDR = "hwnd hWndFrom;int IDFrom;int Code"
Global Const $tagNMLISTVIEW = "hwnd hWndFrom;int IDFrom;int Code;int Item;int SubItem;int NewState;int OldState;int Changed;" & _
        "int ActionX;int ActionY;int Param"
Global Const $tagLVFINDINFO = "int Flags;ptr Text;int Param;int X;int Y;int Direction"

Global Const $HDM_FIRST = 0x1200
Global Const $HDM_GETITEM = $HDM_FIRST + 3
Global Const $HDM_GETITEMW = $HDM_FIRST + 11
Global Const $HDM_GETITEMCOUNT = $HDM_FIRST + 0
Global Const $HDM_SETITEM = $HDM_FIRST + 4
Global Const $HDM_SETITEMW = $HDM_FIRST + 12
Global Const $HDF_SORTDOWN = 0x00000200
Global Const $HDF_SORTUP = 0x00000400
Global Const $HDI_FORMAT = 0x00000004

Global Const $WM_NOTIFY = 0x004E 

GUICreate("ListView Sort", 300, 200)

$hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, _
    BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES))

GUICtrlCreateListViewItem("444|444|444", $hListView)
GUICtrlSetImage(-1, "shell32.dll", 10)
GUICtrlCreateListViewItem("333|333|333", $hListView)
GUICtrlSetImage(-1, "shell32.dll", 7)
GUICtrlCreateListViewItem("222|222|222", $hListView)
GUICtrlSetImage(-1, "shell32.dll", 4)
GUICtrlCreateListViewItem("111|111|111", $hListView)
GUICtrlSetImage(-1, "shell32.dll", 8)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

_GUICtrlListView_RegisterSortCallBack($hListView)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    
    $hWndListView = $hListView
    
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    
                    ; Kick off the sort callback
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Func _GUICtrlListView_RegisterSortCallBack($hWnd, $fNumbers = True, $fArrows = True)
    Local $iIndex, $hHeader

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    $hHeader = _GUICtrlListViewGetHeader($hWnd)
    
    ReDim $aListViewSortInfo[UBound($aListViewSortInfo) + 1][$iLListViewSortInfoSize]

    $aListViewSortInfo[0][0] = UBound($aListViewSortInfo) - 1
    $iIndex = $aListViewSortInfo[0][0]

    $aListViewSortInfo[$iIndex][1] = $hWnd ; Handle/ID of listview

    $aListViewSortInfo[$iIndex][2] = _DllCallback("_GUICtrlListView_Sort", "uint;uint;hwnd") ; Handle of callback
    $aListViewSortInfo[$iIndex][3] = -1 ; $nColumn
    $aListViewSortInfo[$iIndex][4] = -1 ; nCurCol
    $aListViewSortInfo[$iIndex][5] = 1 ; $nSortDir
    $aListViewSortInfo[$iIndex][6] = -1 ; $nCol
    $aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $aListViewSortInfo[$iIndex][8] = $fNumbers ; Treat as numbers?
    $aListViewSortInfo[$iIndex][9] = $fArrows ; Use arrows in the header of the columns?
    $aListViewSortInfo[$iIndex][10] = $hHeader ; Handle to the Header

    Return $aListViewSortInfo[$iIndex][2] <> 0
EndFunc

Func _GUICtrlListView_SortItems($hWnd, $iCol)
    Local $iResult, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    For $x = 1 To $aListViewSortInfo[0][0]
        If $hWnd = $aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next
    
    ;No need to get a pointer, custom _DllCallback function return pointer already
    $pFunction = $aListViewSortInfo[$iIndex][2] ; get pointer to call back
    $aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $aListViewSortInfo[$iIndex][4] = $aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iResult = _SendMessage($hWnd, $LVM_SORTITEMS, $hWnd, $pFunction, 0, "hwnd", "ptr")
    
    If $iResult <> 0 Then
        If $aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $aListViewSortInfo[$iIndex][10]
            
            For $x = 0 To _SendMessage($hHeader, $HDM_GETITEMCOUNT) - 1
                $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x)
                
                If BitAND($iFormat, $HDF_SORTDOWN) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN))
                ElseIf BitAND($iFormat, $HDF_SORTUP) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP))
                EndIf
            Next
            
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol)
            If $aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iResult <> 0
EndFunc

Func _GUICtrlListView_Sort($nItem1, $nItem2, $hWnd)
    Local $iIndex, $tInfo, $val1, $val2, $nResult
    $tInfo = DllStructCreate($tagLVFINDINFO)
    DllStructSetData($tInfo, "Flags", $LVFI_PARAM)

    For $x = 1 To $aListViewSortInfo[0][0]
        If $hWnd = $aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    ; Switch the sorting direction
    If $aListViewSortInfo[$iIndex][3] = $aListViewSortInfo[$iIndex][4] Then ; $nColumn = nCurCol ?
        If Not $aListViewSortInfo[$iIndex][7] Then ; $bSet
            $aListViewSortInfo[$iIndex][5] *= -1 ; $nSortDir
            $aListViewSortInfo[$iIndex][7] = 1 ; $bSet
        EndIf
    Else
        $aListViewSortInfo[$iIndex][7] = 1 ; $bSet
    EndIf
    
    $aListViewSortInfo[$iIndex][6] = $aListViewSortInfo[$iIndex][3] ; $nCol = $nColumn
    DllStructSetData($tInfo, "Param", $nItem1)
    
    $val1 = _GUICtrlListView_FindItem($hWnd, -1, $tInfo)
    DllStructSetData($tInfo, "Param", $nItem2)
    $val2 = _GUICtrlListView_FindItem($hWnd, -1, $tInfo)
    
    $val1 = _GUICtrlListViewGetItemText($hWnd, $val1, $aListViewSortInfo[$iIndex][3])
    $val2 = _GUICtrlListViewGetItemText($hWnd, $val2, $aListViewSortInfo[$iIndex][3])
    
    If $aListViewSortInfo[$iIndex][8] Then ; Treat As Number
        If (StringIsFloat($val1) Or StringIsInt($val1)) Then $val1 = Number($val1)
        If (StringIsFloat($val2) Or StringIsInt($val2)) Then $val2 = Number($val2)
    EndIf

    $nResult = 0 ; No change of item1 and item2 positions

    If $val1 < $val2 Then
        $nResult = -1 ; Put item2 before item1
    ElseIf $val1 > $val2 Then
        $nResult = 1 ; Put item2 behind item1
    EndIf

    $nResult *= $aListViewSortInfo[$iIndex][5] ; $nSortDir

    Return $nResult
EndFunc

Func _GUICtrlListView_FindItem($hWnd, $iStart, ByRef $tFindInfo, $sText = "")
    Local $iBuffer, $tBuffer, $pBuffer, $iFindInfo, $pFindInfo, $pMemory, $tMemMap, $pText, $iResult

    $iBuffer = StringLen($sText) + 1
    $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]")
    $pBuffer = DllStructGetPtr($tBuffer)
    $pFindInfo = DllStructGetPtr($tFindInfo)
    DllStructSetData($tBuffer, "Text", $sText)
    
    If IsHWnd($hWnd) Then
        DllStructSetData($tFindInfo, "Text", $pBuffer)
        $iResult = _SendMessage($hWnd, $LVM_FINDITEM, $iStart, $pFindInfo, 0, "wparam", "ptr")
    Else
        DllStructSetData($tFindInfo, "Text", $pBuffer)
        $iResult = GUICtrlSendMsg($hWnd, $LVM_FINDITEM, $iStart, $pFindInfo)
    EndIf
    
    Return $iResult
EndFunc

Func _GUICtrlHeader_GetItem($hWnd, $iIndex, ByRef $tItem)
    Local $iItem, $pItem, $pMemory, $tMemMap, $iResult

    $pItem = DllStructGetPtr($tItem)
    
    $iResult = _SendMessage($hWnd, $HDM_GETITEMW, $iIndex, $pItem, 0, "wparam", "ptr")
    
    Return $iResult <> 0
EndFunc

Func _GUICtrlHeader_GetItemFormat($hWnd, $iIndex)
    Local $tItem
    
    $tItem = DllStructCreate($tagHDITEM)
    DllStructSetData($tItem, "Mask", $HDI_FORMAT)
    _GUICtrlHeader_GetItem($hWnd, $iIndex, $tItem)
    Return DllStructGetData($tItem, "Fmt")
EndFunc

Func _GUICtrlHeader_SetItem($hWnd, $iIndex, ByRef $tItem)
    Local $iItem, $pItem, $pMemory, $tMemMap, $iResult

    $pItem = DllStructGetPtr($tItem)
    
    $iResult = _SendMessage($hWnd, $HDM_SETITEMW, $iIndex, $pItem, 0, "wparam", "ptr")
    
    Return $iResult <> 0
EndFunc

Func _GUICtrlHeader_SetItemFormat($hWnd, $iIndex, $iFormat)
    Local $tItem
    
    $tItem = DllStructCreate($tagHDITEM)
    DllStructSetData($tItem, "Mask", $HDI_FORMAT)
    DllStructSetData($tItem, "Fmt", $iFormat)
    
    Return _GUICtrlHeader_SetItem($hWnd, $iIndex, $tItem)
EndFunc

What do i miss here?

Or can anyone show me please how to get only the part with arrow creation to the example in my first post?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

After little searching on the forum, i finally made a workable example for AutoIt v3.2.8.1:

#include <GUIConstants.au3>
#include <ListViewConstants.au3>

Global Const $LVM_GETITEM   = $LVM_FIRST + 5

Global Const $HDF_LEFT  = 0x00000000
Global Const $HDF_RIGHT     = 0x00000001
Global Const $HDF_CENTER    = 0x00000002
Global Const $HDF_BITMAP    = 0x00002000
Global Const $HDF_STRING    = 0x00004000
Global Const $HDF_SORTDOWN  = 0x00000200
Global Const $HDF_SORTUP    = 0x00000400

Global Const $HDI_FORMAT    = 0x00000004

Global Const $HDM_FIRST     = 0x1200
Global Const $HDM_SETITEM   = $HDM_FIRST + 4
Global Const $HDM_SETITEMW  = $HDM_FIRST + 12

Global Const $tagHDITEM     = "int Mask;int XY;ptr Text;hwnd hBMP;int TextMax;int Fmt;int Param;" & _
    "int Image;int Order;int Type;ptr pFilter;int State"

Global $iShowArrows     = 1
Global $iShowSelectedCol    = 0

Global $nCurrentColumn  = -1
Global $nSortDirection      = -1
Global $nSortSet        = 0
Global $nColumnSet      = 0


$hGUI = GUICreate("ListView Sort!")

$ListView = GUICtrlCreateListView("Column 1|Column 2|Column3", 0, 50, 500, 400, $WS_VSCROLL, $LVS_EX_CHECKBOXES + $LVS_EX_GRIDLINES)
GUICtrlRegisterListViewSort(-1, "ListView_Sort_Proc") ; Register the function "ListView_Sort_Proc" for the sorting callback

GUICtrlCreateListViewItem("444|444|444", $ListView)
GUICtrlSetImage(-1, "shell32.dll", 10)
GUICtrlCreateListViewItem("333|333|333", $ListView)
GUICtrlSetImage(-1, "shell32.dll", 7)
GUICtrlCreateListViewItem("222|222|222", $ListView)
GUICtrlSetImage(-1, "shell32.dll", 4)
GUICtrlCreateListViewItem("111|111|111", $ListView)
GUICtrlSetImage(-1, "shell32.dll", 8)

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $ListView
            $nSortSet = 0
            $nCurrentColumn = $nColumnSet
            
            If $iShowSelectedCol Then GUICtrlSendMsg($ListView, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($ListView), 0)
            If $iShowArrows Then SetHeaderColumnArrow_Proc()
            
            DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($ListView), "int", 0, "int", 1)
    EndSwitch
WEnd

; Our sorting callback funtion
Func ListView_Sort_Proc($hWnd, $nItem1, $nItem2, $nColumn)
    Local $nSort, $iVal1, $iVal2
    
    ; Switch the sorting direction
    If $nColumn = $nCurrentColumn Then
        If Not $nSortSet Then
            $nSortDirection *= -1
            $nSortSet = 1
        EndIf
    Else
        Local $hHeader = GUICtrlSendMsg($ListView, $LVM_GETHEADER, 0, 0)
        _GUICtrlHeader_SetItemFormat($hHeader, $nCurrentColumn, BitOR($HDF_LEFT, $HDF_STRING))
        $nSortDirection = 1
    EndIf
    
    $nColumnSet = $nColumn
    
    $iVal1 = _GUICtrlListView_GetSubItemText($ListView, $nItem1, $nColumn)
    $iVal2 = _GUICtrlListView_GetSubItemText($ListView, $nItem2, $nColumn)
    
    $nResult = 0        ; No change of item1 and item2 positions
    
    If $iVal1 < $iVal2 Then
        $nResult = -1   ; Put item2 before item1
    ElseIf $iVal1 > $iVal2 Then
        $nResult = 1    ; Put item2 behind item1
    EndIf
    
    Return $nResult * $nSortDirection
EndFunc

; Retrieve the text of a listview item in a specified column
Func _GUICtrlListView_GetSubItemText($nCtrlID, $nItemID, $nColumn)
    Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int")
    DllStructSetData($stLvfi, 1, $LVFI_PARAM)
    DllStructSetData($stLvfi, 3, $nItemID)
    
    Local $stBuffer = DllStructCreate("char[260]")
    Local $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
    Local $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
    
    DllStructSetData($stLvi, 1, $LVIF_TEXT)
    DllStructSetData($stLvi, 2, $nIndex)
    DllStructSetData($stLvi, 3, $nColumn)
    DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
    DllStructSetData($stLvi, 7, 260)
    
    GUICtrlSendMsg($nCtrlID, $LVM_GETITEM, 0, DllStructGetPtr($stLvi));
    
    Return DllStructGetData($stBuffer, 1)
EndFunc

Func SetHeaderColumnArrow_Proc()
    Local $hHeader = GUICtrlSendMsg($ListView, $LVM_GETHEADER, 0, 0)
    Local $iHeaderItemFormat = BitOR($HDF_LEFT, $HDF_STRING, $HDF_SORTUP)
    
    If $nSortDirection > 0 Then $iHeaderItemFormat = BitOR($HDF_LEFT, $HDF_STRING, $HDF_SORTDOWN)
    
    _GUICtrlHeader_SetItemFormat($hHeader, $nCurrentColumn, $iHeaderItemFormat)
EndFunc

Func _GUICtrlHeader_SetItemFormat($hWnd, $iIndex, $iFormat)
    Local $tItem, $pItem, $iResult

    $tItem = DllStructCreate($tagHDITEM)
    DllStructSetData($tItem, "Mask", $HDI_FORMAT)
    DllStructSetData($tItem, "Fmt", $iFormat)
    
    ;_GUICtrlHeader_SetItem()
    $pItem = DllStructGetPtr($tItem)
    
    If @Unicode Then
        $iResult = DllCall("User32.dll", "long", _
            "SendMessage", "hwnd", $hWnd, "int", $HDM_SETITEMW, "int", $iIndex, "ptr", $pItem)
    Else
        $iResult = DllCall("User32.dll", "long", _
            "SendMessage", "hwnd", $hWnd, "int", $HDM_SETITEM, "int", $iIndex, "ptr", $pItem)
    EndIf
    
    Return $iResult[0] <> 0
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...