Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to get the ListViews Group View working


  • Please log in to reply
11 replies to this topic
Shield
  • Members
  • 4 posts
  • Last active: Dec 21 2009 10:25 AM
  • Joined: 20 Dec 2009

Posted Image

I think the title says it all, so stop talking, let's start coding. :wink:

This is how far I got before I got stuck:

; Create GUI incl. ListView (3 columns)
Gui Add, ListView, w400 r10 Checked HwndMyListViewHandle vMyListView,Filename|Extension|Size
LV_ModifyCol(1,200)
LV_ModifyCol(2,"70")
LV_ModifyCol(3,"70 Integer")
Gui Add, Button, x300 +Default gLeave, Leave
Gui Show,,Group View Test


; Adding files
Loop %temp%\*,0
{ SplitPath A_LoopFileName,,,,NameWithoutExt
LV_Add(""" " . DefaultCheck . " """,NameWithoutExt,A_LoopFileExt,A_LoopFileSize)
}

;Sleep 500 ; <- allows visual control before...

;--------------------
; Creating two Groups
;====================

; Messages needed
LVM_INSERTGROUP = 0x1091
LVM_SETITEM = 0x1006
LVM_ENABLEGROUPVIEW = 0x109d

; LVGROUP structure
LVGROUP_CbSize = 0
LVGROUP_Mask = 4
LVGROUP_PszHeader = 8
LVGROUP_CchHeader = 12
LVGROUP_PszFooter = 16
LVGROUP_CchFooter = 20
LVGROUP_IGroupId = 24
LVGROUP_StateMask = 28
LVGROUP_State = 32
LVGROUP_UAlign = 36
LVGROUP_PszSubtitle = 40
LVGROUP_CchSubtitle = 44
LVGROUP_PszTask = 48
LVGROUP_CchTask = 52
LVGROUP_PszDescriptionTop = 56
LVGROUP_CchDescriptionTop = 60
LVGROUP_PszDescriptionBottom= 64
LVGROUP_CchDescriptionBottom= 68
LVGROUP_ITitleImage = 72
LVGROUP_IExtendedImage = 76
LVGROUP_IFirstItem = 80
LVGROUP_CItems = 84
LVGROUP_PszSubsetTitle = 88
LVGROUP_CchSubsetTitle = 92

; Unicoded Header
VarSetCapacity(UnicodeHeader,100)


; Create Group #1
HeadertextGroup1=Group #1
VarSetCapacity(LVGroup1, 96, 0)
NumPut(96, &LVGroup1, LVGROUP_CbSize,"Int")
NumPut(0x11, &LVGroup1, LVGROUP_Mask,"Int") ; Members we want to set: LVGF_HEADER (flag 0x1) + LVGF_GROUPID (flag 0x10)
DllCall("MultiByteToWideChar","UINT",0,"UINT",0,"UINT",&HeadertextGroup1,"INT",-1,"UINT",&UnicodeHeader,"INT",strlen(HeadertextGroup1)+1)
NumPut(&UnicodeHeader, &LVGroup1, LVGROUP_PszHeader,"Int")
NumPut(0, &LVGroup1, LVGROUP_IGroupId,"Int")

SendMessage LVM_INSERTGROUP, -1, &LVGroup1,, ahk_id %MyListViewHandle%

; Create Group #2 (basically the same as above, but with IGroupId +1)
HeadertextGroup2=Group #2
VarSetCapacity(LVGroup2, 96, 0)
NumPut(96, &LVGroup2, LVGROUP_CbSize, "Int")
NumPut(0x11, &LVGroup2,LVGROUP_Mask, "Int")
DllCall("MultiByteToWideChar","UINT",0,"UINT",0,"UINT",&HeadertextGroup2,"INT",-1,"UINT",&UnicodeHeader,"INT",strlen(HeadertextGroup2)+1)
NumPut(&UnicodeHeader, &LVGroup2,LVGROUP_PszHeader, "Int")
NumPut(1, &LVGroup2, LVGROUP_IGroupId, "Int")

SendMessage LVM_INSERTGROUP, -1, &LVGroup2,,ahk_id %MyListViewHandle%


;Adding items to the groups
;==========================
; AutoHotkey has no build-in support for Group View, however, it's possible to assign the already imported items manually to the groups
; by subsequently setting the iGroupId member of the items LVITEM structure:

LVITEM_mask = 0
LVITEM_iItem = 4
LVITEM_iSubItem = 8
LVITEM_state = 16
LVITEM_stateMask = 20
LVITEM_pszText = 24
LVITEM_cchTextMax = 28
LVITEM_iImage = 32
LVITEM_lParam = 36
LVITEM_iIndent = 40
LVITEM_iGroupId = 44
LVITEM_cColumns = 48
LVITEM_puColumns = 52
LVITEM_piColFmt = 56
LVITEM_iGroup = 60


VarSetCapacity(LVItem5, 64, 0)
NumPut(0x100, &LVItem5, 0,"Int") ; Member we want to set: LVIF_GROUPID (flag 0x100)
NumPut(5, &LVItem5, LVITEM_iItem,"Int") ; Assign item #5 to ...
NumPut(0, &LVItem5, LVITEM_iGroupId,"Int") ; ... group #1
SendMessage LVM_SETITEM, -1, &LVItem,, ahk_id %MyListViewHandle% ; Do it

VarSetCapacity(LVItem6, 64, 0)
NumPut(0x100, &LVItem6, 0,"Int")
NumPut(6, &LVItem6, LVITEM_iItem,"Int") ; Same with item #6
NumPut(0, &LVItem6, LVITEM_iGroupId,"Int")
SendMessage LVM_SETITEM, -1, &LVItem6,,ahk_id %MyListViewHandle%


VarSetCapacity(LVItem7, 64, 0)
NumPut(0x100, &LVItem7, 0,"Int")
NumPut(7, &LVItem7, LVITEM_iItem,"Int") ; Item #7 into...
NumPut(1, &LVItem7, LVITEM_iGroupId,"Int") ; ... group #2
SendMessage LVM_SETITEM, -1, &LVItem7,,ahk_id %MyListViewHandle%


; Enable Group View (this hides all items which are not assigned to a group!)
SendMessage LVM_ENABLEGROUPVIEW,1,0,,ahk_id %MyListViewHandle%


Winset Redraw ; not needed on my system, just for being sure

Exit

GuiClose:
GuiEscape:
Leave:
ExitApp

... and that's the unpleasant outcome: The second group does not appear.

Posted Image

In addition to that, the column headers loose the sorting capability.. Posted Image

I'm not very familiar with this whole API-stuff, so I pin all my hopes on your experience to help me get this thing off the hook .

Shield
  • Members
  • 4 posts
  • Last active: Dec 21 2009 10:25 AM
  • Joined: 20 Dec 2009
Solved the header problem -> the text needed to be unicode :?

I updated the post & screenshot above since the main problem remains - the missing second group.

hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007
Does it support WinXP or Win2000?
When I browser MSDN, I found it Minimum supported OS is Vista.

Shield
  • Members
  • 4 posts
  • Last active: Dec 21 2009 10:25 AM
  • Joined: 20 Dec 2009
http://msdn.microsof...900(VS.85).aspx -> Minimum supported client. Windows XP

... and it works fine. :)

However, it is true that the release of Vista came along with a somewhat enhanced group view API (e.g. http://msdn.microsof...4(v=VS.85).aspx)

newbie33
  • Guests
  • Last active:
  • Joined: --

... and it works fine. :)


The Second group does appear???
i have tried ,but failed. Why??

AutoIt Script shows "second group".
But, does not appear on ahk.

rhinox202
  • Members
  • 37 posts
  • Last active: Sep 18 2014 07:19 PM
  • Joined: 23 Apr 2009
Hey Shield,

I am incorporating your Group View into my app and ran into the same problem you have. I did notice a typo for Item5 under the "Adding items to the groups" section but it doesn't correct the problem. The line says

SendMessage LVM_SETITEM, -1, &LVItem,, ahk_id %MyListViewHandle% ; Do it
and it should be

SendMessage LVM_SETITEM, -1, &LVItem5,, ahk_id %MyListViewHandle% ; Do it
I did a little more research too. It seems that the groups are being created, so the problem might be with how the grouping is assigned. I don't know too much about this but I'd like to figure it out. What information have you used to get to this point? Thanks.

Bob

rhinox202
  • Members
  • 37 posts
  • Last active: Sep 18 2014 07:19 PM
  • Joined: 23 Apr 2009
I managed to find the following information, http://www.winapizon...view/groups.php. Not sure if you have seen it before. The code means nothing to me but it seems like it may be beneficial. I'll keep looking.

helper
  • Guests
  • Last active:
  • Joined: --
:D
I found above LVItem Structure Wrong. :idea:

Replace LVITEM_iGroupId = 44 with 40 and Group#2 will be visible.

Maybe, It should be
LVITEM_pszText = 24 --> 20
LVITEM_cchTextMax = 28 --> 24
-
-
-
LVITEM_iGroupId = 44 --> 40
-
-

rhinox202
  • Members
  • 37 posts
  • Last active: Sep 18 2014 07:19 PM
  • Joined: 23 Apr 2009
Thanks a LOT helper! I was able to get everything working in my app. I was curious how you figured out what was wrong. Thanks again.

rhinox202
  • Members
  • 37 posts
  • Last active: Sep 18 2014 07:19 PM
  • Joined: 23 Apr 2009
I recently switched to using AutoHotkey_L (32bit Unicode) and have been modifying my scripts to work with it. So of them do and others don't. This script is one I am having trouble with. For some reason the group name is not being saved entirely. Only the first letter of the HeadertextGroup1 variable is stored. I don't really know anything about Numput but I think that it may be the problem as AutoHotkey_L has known compatibility issues with it. I was hoping for a little help. Thanks.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
You probably have to use 'LVM_SETITEMW' for it to be compatible with unicode AHK.

rhinox202
  • Members
  • 37 posts
  • Last active: Sep 18 2014 07:19 PM
  • Joined: 23 Apr 2009
@[VxE] -- I tried doing what you said by changing my code like the following and it doesn't work. The code does run, so really I should say it doesn't fix the problem.

; OLD
LVM_SETITEM = 0x1006
; NEW
LVM_SETITEM = 0x104C
Rather than change all of my LVM_SETITEM references to LVM_SETITEMW, I opted to just change the variable's value. I got the value for LVM_SETITEMW off of http://code.google.c...dowsMessages.cs. I noticed that you code in AHK Basic, but do you have any other ideas. Thanks too :-)