Jump to content

GuiCtrlCreateListview() exStyle: help needs help?


c.haslam
 Share

Recommended Posts

Help says for exStyle: "Defines the extended style of the control. See Extended Style Table or ListView Extended Style Table."

This would make sense if the values of constants in these two tables were unique, but they are not. The attachment shows the constants listed in the tables, side-by-side.

In that there are cases where the same value applies to a WS_EX and to a LVS_EX constant, which constant does AutoIt take it to be? I think that this needs to be clarified.

If one were writing in C++, LVS_EX constants are sent with SETEXTENDEDLISTVIEWSTYLE. So does AutoIt send some constants using SETEXTENDEDLISTVIEWSTYLE ?

The table in the Help omits some LVS_EX constants, e.g. LVS_EX_INFOTIP, value 0x400. $WS_EX_CONTEXTHELP also has this value. So is $WS_EX_CONTEXTHELP available, but not LVS_EX_INFOTIP?

See for the case where BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_CHECKBOXES) works partially using GuiSendMsg(-1,SETEXTENDEDLISTVIEWSTYLE .. and work completely when these styles are the exStyle parameter to GuiCtrlCreateListview().

wsex_lvsex constants.txt

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

When you set the extended style on a control, the control will use the value if it pertains to one of its style settings. Even though the values may be the same as another control's setting it doesn't mean anything to the control it's being applied to. It will only apply the LV setting to a LV, just because to (for example) a TreeView a value of 1 may mean something it doesn't matter what that is to a LV.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You mean it should be "and"? Is that it?

No

I am aware that WS_EX constants are intended for use with any control, and for a form. I also know that some WS_EX constants may not do anything when applied to a particular control.

In this thread, I am only concerned with Listviews, so the styles that apply are LVS_, LVS_EX, WS_ and WS_EX. Here I am only dealing with LVS_EX and WS_EX

For simple controls (e.g. Button), there are less than 32 styles, so all styles particular to Button can be specified in the style parameter. But for ListView, there are more than 32 styles, so Microsoft came up with LVS_EX constants.

UDF _GUICtrlListView_Create() has two style parameters: one for LVS_, and one for LVS_EX. Presumably WS_EX styles can be set somewhere else. But GUICtrlListView_Create(), per the help, has one parameter for _LVS and one parameter for LVS_EX and (or or) WS_EX combined! What if I want my listview to have both WINDOWEDGE and FLATSB? One is a WS_EX and the other is a LVS_EX, which Windows see as 0x100.

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

You can't have the WindowEdge and FlatSB because one applies to a window the other applies to a control.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Does GuiCtrlCreateListView() create a window as well as a control?

The help for GuiCtrlCreateListView() says that it takes WS_EX (windows) constants.

GuiCreateEdit(), a non-COMMCTRL control, takes WS_EX constants.

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

So I still wonder how GuiCtrlCreateView(), with its (per the help) combined WS_EX and LVS_EX parameter, can sort out which bits in the value belong to the control, and which to the window.

I have written some GUI front-end stuff for Koda which will make it easier to choose styles. In writing front-ends for all 22 controls in Koda, I found that i definitely needed to send some of the control EX stuff to XP using GuiCtrlSend(-1,*_SET*EXTENDEDSTYLES, ...), e.g. TVM_SETTREEVIEWEXTENDEDSTYLES. It came as a surprise when this partly failed for ListView: done this way, the script could not uncheck checkboxes which had been manually checked. I may need to revisit my front_end code.

I am trying to work out what, if any, changes need to be made to the help for GuiCtrlCreateListView, e.g. should there be a special table of exStyles? But perhaps combining WS_EX and LVS_EX styles in one parameter is a design bug. If it is, is it AutoIt's or Microsoft's?

I note that the Help for GUICtrlCreateTreeView() suggests only WS_EX styles for exStyles, i.e. it does not suggest TVS_EX_ styles. I wonder why.

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

I'm guessing you meant LVS_EX there instead of TVS_EX. And in my help file, version 3.3.8.1, does include a link to the ListView extended styles.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Your guess is not correct. In the last paragraph, I meant GuiCtrlCreateTreeView(). I have made the correction.

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

You wrote

And in my help file, version 3.3.8.1, does include a link to the ListView extended styles.

I'm not at all sure that it should, but perhaps you have examined the AutoIt source code; I have not.

In writing a GUi front-end for Koda (which lazycat is yet to implement), I tried both ways: including LVS_EX constants in the exStyle parameter, and sending them via LVM_SETEXTENDEDLISTVIEWSTYLE.

The attached PDF is my blog from writing that front-end script. You will see that:

I was surprised the other day when I had this case:
  • populate a report-style listview that has checkboxes
  • user checks the checkbox in Row 1
  • code runs
  • script tries to uncheck the checkbox by calling GUICtrlSetState( $ListViewItem1, $GUI_UNCHECKED)
  • the checkbox says checked.
This was with

Local $lvMsgs = GUICtrlCreateListView("Date|Time|Message", 24, 176, 577, 513, -1, BitOR($WS_EX_CLIENTEDGE, 0))
Local $n = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES)
GUICtrlSendMsg(-1,$LVM_SETEXTENDEDLISTVIEWSTYLE,$n,$n)

Someone on the forum offered

Local $lvMsgs = GUICtrlCreateListView("Date|Time|Message", 24, 176, 577, 513, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES))

It worked.

Until then I had been convinced that the way is LVM_SETEXTENDEDLISTVIEWSTYLE.

There are about 29 LVS_EX constants. If the exStyle parameter is used for LVS_EX and WS_EX, and if all the LVS_EX constants can be specified, only 2 WS_EX constants can be specified. There are 6 WS_EX border-style constants that seem to be applicable to ListView.

I guess that a question is: does the AutoIt code use the exStyle parameter of CreateWindowExW() for LVS_EX constants, or does it SendMessageW them?

Forgot the attachment. Now attached.

ListView notes for Koda styles script.pdf

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

It appears that there are no extended style settings for a TreeView unless you're using Vista+, the help file should be updated to include those as well, although they aren't in the TreeViewConstants.au3 file either so that would have to be updated as well.

I'm not sure if you realize that there's a GUICtrlSetStyle function which can do what you're doing with the SendMsg function.

I can't see any reason why it wouldn't uncheck the LV item using that code. Here's an example of it working by checking and unchecking the first item in the LV. Click the check button, it sets a check mark, click ok on the MsgBox and it will uncheck it

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListview.au3>
Example()

Func Example()
    Local $listview, $button, $item1, $item2, $item3, $msg

    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    $listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    GUICtrlSetStyle(-1, -1, $LVS_EX_CHECKBOXES) ; add extended style of check boxes to the listview
    $button = GUICtrlCreateButton("Check", 75, 170, 70, 20)
    $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
    $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
    GUICtrlCreateInput("", 20, 200, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
    GUISetState()
    GUICtrlSetData($item2, "ITEM1")
    GUICtrlSetData($item3, "||COL33")

    Do
        $msg = GUIGetMsg()

        Select
            Case $msg = $button
                MsgBox(0, "Checked Item 1", GUICtrlSetState($item2, $GUI_CHECKED))
                GUICtrlSetState($item2, $GUI_UNCHECKED)
            Case $msg = $listview
                MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

This is just a modified version of the ListView example script.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Your example works, but in your script the script checks and unchecks, while in mine the user checks and the script unchecks (and fails to do so).

I wonder what GuiCtrlSetStyle() does under the hood. I note that the Help for this function only shows WS_EX styles.

In doing this stuff for Koda, I fought hard and long over how many "style buckets" Windows has: is it 2 or 3? Definitely 2 for non-COMCTL controls, but may be 3 for COMCTL controls.

I worked my way through each of the controls on MSDN. It was only when I reached ListView that I met anything like

Use the LVM_SETEXTENDEDLISTVIEWSTYLE message or one of the ListView_SetExtendedListViewStyle or ListView_SetExtendedListViewStyleEx macros to employ these extended list-view control styles.

After due deliberation (and experiments), I decided that LVS_EX etc belong in a third bucket.

Attached is a screen-shot of my ListView front-end script. If you are interested, I can send you all of the scripts, and my "blog", so you can see what happens with all of the styles. I would rather do this by PM because I don't want unverified info to get out into the AutoIt community: that would add to the present confusion.

You are correct about TVS_EX styles requiring Vista+.

post-8330-0-33585800-1354635859_thumb.jp

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Your example works, but in your script the script checks and unchecks, while in mine the user checks and the script unchecks (and fails to do so).

Then you're doing something wrong, because the code I posted will check and/or uncheck the box regardless of how it was previously checked/unchecked. You can easily demonstrate that by commenting out the line with the message box, checking the first row manually, and clicking the "Check" button, it will uncheck the first box.

I wonder what GuiCtrlSetStyle() does under the hood. I note that the Help for this function only shows WS_EX styles.

It applies the style, and extended style, settings you specify to the control you specify, I'm not sure how it does it, but it works for me so I don't question it.

There are a lot of places that the style settings list is incomplete in the help file, but if you open the xxConstants.au3 files for the control you're dealing with, they're almost always all listed in there

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

It applies the style, and extended style, settings you specify to the control you specify, I'm not sure how it does it, but it works for me so I don't question it.

SetWindowLong.

If you want to verify whether LVS_EX_ styles really are separate then compare the result of GUICtrlSetStyle to doing the equivalent with _WinAPI_SetWindowLong.

Link to comment
Share on other sites

For what it's worth, my code compares the styles that the user requested with the styles that XP reports he actually got. I experimented until .I got code that worked. The pdf file, now attached, shows my results: for ListView, almost everything worked using GuiSendMsg(-1,$LVM_SETEXTENDEDLISTSTYLE.

The way I verified that sending LVS_CHECKBOXES worked was to manually check and uncheck the checkboxes. Verifying this way, I missed the case where the script checks and the user un-checks.

For what it's worth, here is a snippet of my verification code.

Local $winOutStyles,$winOutCtrlExStyles,$winOutExStyles,$view
If ShowStatus($winOutStyles,$winOutCtrlExStyles,$winOutExStyles,$view) Then
Local $winLacks,$winAdded,$winCtrlExLacks,$winCtrlExAdded,$winExLacks,$winExAdded
CompareNormStyles($winInStyles,$winOutStyles,$winLacks,$winAdded)
CompareExStyles($gCtrlExStyles,$winOutCtrlExStyles,$winCtrlExLacks,$winCtrlExAdded)
CompareExStyles($winInExStyles,$winOutExStyles,$winExLacks,$winExAdded)
ShowAll3Styles($winLacks,$winCtrlExLacks,$WinExLacks,$lstStylesWinLacks,False)
ShowAll3Styles($winAdded,$winCtrlExAdded,$winExAdded,$lstStylesWinAdded,False)


EndIf

Func ShowStatus(ByRef $winOutStyles,ByRef $winOutCtrlExStyles,ByRef $winOutExStyles,ByRef $view)
Local $n = 0,$hForm,$lvTest
$hForm = GUICreate("title",200,200,-200,-200)
If $hForm=0 Or @error<>0 Then
MsgBox(4096,"Error","GuiCreate() in ShowStatus failed")
EndIf
Local $bWorks = CreateTestControl(10,10,180,180,False,$lvTest)
If $bWorks Then
Local $hndl = GUICtrlGetHandle($lvTest)
$view = GuiCtrlSendMsg($lvTest,$LVM_GETVIEW,0,0)
$winOutStyles = _C_GetWindowLong($hndl,$GWL_STYLE)
$winOutCtrlExStyles = GUICtrlSendMsg($lvTest,$LVM_GETEXTENDEDLISTVIEWSTYLE,0,0)
$winOutExStyles = _C_GetWindowLong($hndl,$GWL_EXSTYLE)
GUIDelete($hndl)
GUICtrlSetState($btnOK,$GUI_ENABLE)
Else
$winOutStyles = 0
$winOutCtrlExStyles = 0
$winOutExStyles = 0
GUICtrlSetState($btnOK,$GUI_DISABLE)
EndIf
for $i = 1 to UBound($presetStylesAr,1)-1
If $presetStylesAr[$i][$kPssView]=$gView and $presetStylesAr[$i][$kPssNormStyles]=$gNormStyles _
And $presetStylesAr[$i][$kPssCtrlExStyles]=$gCtrlExStyles And $presetStylesAr[$i][$kPssWsExStyles]=$gWinExStyles Then
$n = $i
ExitLoop
EndIf
Next
Switch True
Case $n>0
GUICtrlSetData($lblStatus,"Preset " & $n)
GUICtrlSetColor($lblStatus,0x007f00) ; green
case $bWorks
GUICtrlSetData($lblStatus,"Custom")
GUICtrlSetColor($lblStatus,0x0000ff) ; blue
Case Else
GUICtrlSetData($lblStatus,"Failed")
GUICtrlSetColor($lblStatus,0xff0000) ; red
EndSwitch
Return $bWorks
EndFunc

Func CompareExStyles($in,$out,ByRef $lacks,ByRef $added)
If $out=$in Then
$lacks = 0
$added = 0
Return True
Else
Local $b = BitXOR($in,$out)
$added = BitAND($b,$out)
$lacks = BitAND($b,$in)
Return False
EndIf
EndFunc

; Copied from WinAPI.au3
Func _C_GetWindowLong($hWnd, $iIndex)
Local $sFuncName = "GetWindowLongW"
If @AutoItX64 Then $sFuncName = "GetWindowLongPtrW"
Local $aResult = DllCall("user32.dll", "long_ptr", $sFuncName, "hwnd", $hWnd, "int", $iIndex)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[0]
EndFunc ;==>_C_GetWindowLong

If you will tell me how to get the forum to indent lines properly, I will happily reload the above.

I wonder how the 29 LVS_EX constants and relevant WS_EX constants will fit into the 31 bits of exStyle must handle.

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Chris,

Pain in the ass, isn't it. Click on the button in the upper left hand corner. I also type in the code delimiters (

and
).

Interesting discussion about styles, I'm trying to get facile with listview now and am finding it hard to track down the myriad of constants being used. I think that I'll do what BrewmanNH suggested and go right to the constants definitions.

kylomas

edit: stupid - I typed the code delimiters and got a code box, suprise, suprise!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

kylomas,

I am attaching the script that I wrote for a Koda front-end, to translate from human language to Windows constants, which you may find helpful in figuring out how the constants work. After the script has set the styles for a control, it reads them back from Windows. If it finds a difference (beyond forced styles), it shows Bad in the right hand column (rather than Preset or Custom). New in this version is the Copy Code button. It copies the code used in populating the Test group to the Clipboard. I wrote this in a way that you can play with how you set $styles and $exStyles.

You may never see Bad. See the accompanying notes in the pdf.

If you hover over almost any choice in the dialog, hover help will show you the constant related to this choice.

This script is one of some 22 scripts, there being one for each control, and one for Form. Because similarities, I tried to standardize them. So you may meet bits of code that do nothing in this context, but are used for other controls.

I am running XP. So on my PC styles requiring Vista+ are disabled. They have been desk-checked, but not runtime-checked.

Revised file attached.

ListView styles script.zip

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

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...