Jump to content

how can i create listview like in the following example?


Guest
 Share

Recommended Posts

hello,

i want to create this kind of listview:

2hd06mr.jpg

i didn't found the example i'm looking for so i did this in photoshop.. sory if i did a bad job.

i need to create exactly this example and i also need a "add" button for adding new things to the list and "delete" button for deleting the selected line in the list.

thanks for helpers

Edited by Guest
Link to comment
Share on other sites

  • Moderators

gil900,

How about sticking to one thread at a time. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If you create a list view using the $LVS_EX_CHECKBOXES extended style you can get the checkboxes. While it won't be exactly like the one you posted, it should be close enough to get the job done.

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

If you create a list view using the $LVS_EX_CHECKBOXES extended style you can get the checkboxes. While it won't be exactly like the one you posted, it should be close enough to get the job done.

Does the checkboxs will be in the same place as in my example?

If so, can you give me an example code?

if not then i know what you talking about. I did a search on this forum before I opened this thread and i saw that example..

I strongly prefer that the checkboxs will be in the same place as in my example..

I would love if someone will build code/udf that makes it and give an example.

thanks.

Link to comment
Share on other sites

You can use images in subitems ($LVS_EX_SUBITEMIMAGES). It should be possible to create two small images that looks like a checked and unchecked checkbox and change the image when an item is clicked.

Link to comment
Share on other sites

This is an example. Copied from the help file. You will find the checkbox images and code in the zip.

LVwithcheckboxincol2_zps360a7f1c.jpg

 

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Global $hListView, $LVchecked[4]

MainFunction()

Func MainFunction()
    Local $hGui, $hImage, $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    $hGui = GUICreate("ListView with Checkbox in Column 2", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    $hListView = ControlGetHandle( $hGui, "", $hListView )
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_AddBitmap($hImage, "CheckboxUnChecked.bmp")
    _GUIImageList_AddBitmap($hImage, "CheckboxChecked.bmp")
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 0", 0)
    _GUICtrlListView_AddColumn($hListView, "Column 1", 200)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 0, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "False", 2, 0)
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 1, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "True", 2, 1)
    $LVchecked[1] = 1
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 2, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 2, "False", 2, 0)
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 3, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 3, "True", 2, 1)
    $LVchecked[3] = 1

    ; Disable column resize
    ControlDisable($hGui, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUISetState()

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR, $hWndFrom, $iCode, $aHitTest, $item
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CLICK
                    $aHitTest = _GUICtrlListView_SubItemHitTest($hListView)
                    If $aHitTest[1] = 2 And $aHitTest[3] Then ; Col 2 and image
                        $item = $aHitTest[0]
                        $LVchecked[$item] = 1 - $LVchecked[$item]
                        _GUICtrlListView_SetItemImage($hListView, $item, $LVchecked[$item], 2)
                        If $LVchecked[$item] Then
                            _GUICtrlListView_SetItemText($hListView, $item, "True", 2)
                        Else
                            _GUICtrlListView_SetItemText($hListView, $item, "False", 2)
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

LV.7z

Edited by LarsJ
Link to comment
Share on other sites

I believe what your picture is showing is a gridview, and not a listview control. You have more options using a gridview than you do with a listview. I'm pretty sure you can't have a checkbox in the second column short of using an ownerdrawn listview, but that's a lot harder to work with. I have no experience using an owner drawn listview so I can't give examples but you might be able to find some on here.

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

gil900, If it's only the BMP-files that are the problem it should be possible to represent these files as text strings directly in code. This should be possible to do with GDIPlus commands. It should also be possible to create bitmaps from the text strings and add these bitmaps to the image list.

Link to comment
Share on other sites

@gil900 - Could you use the Autoit Window Info tool on the control in the OP, so we can see what it is?

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

gil900, Here the bitmaps are included directly in code:

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPIEx.au3>
#include <GDIPlus.au3>
#include <Memory.au3>

Global $hListView, $aLVchecked[4]

MainFunction()

Func MainFunction()
    Local $hGui, $hImageList, $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    $hGui = GUICreate("ListView with Checkbox in Column 2", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    $hListView = ControlGetHandle( $hGui, "", $hListView )
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)

    ; Load images
    $hImageList = _GUIImageList_Create()
    FillImageList( $hImageList )
    _GUICtrlListView_SetImageList($hListView, $hImageList, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 0", 0)
    _GUICtrlListView_AddColumn($hListView, "Column 1", 200)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 0, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "False", 2, 0)
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 1, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "True", 2, 1)
    $aLVchecked[1] = 1
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 2, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 2, "False", 2, 0)
    _GUICtrlListView_AddItem($hListView, "")
    _GUICtrlListView_AddSubItem($hListView, 3, "Checkbox in column 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 3, "True", 2, 1)
    $aLVchecked[3] = 1

    ; Disable column resize
    ControlDisable($hGui, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUISetState()

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR, $hWndFrom, $iCode, $aHitTest, $item
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CLICK
                    $aHitTest = _GUICtrlListView_SubItemHitTest($hListView)
                    If $aHitTest[1] = 2 And $aHitTest[3] Then ; Col 2 and image
                        $item = $aHitTest[0]
                        $aLVchecked[$item] = 1 - $aLVchecked[$item]
                        _GUICtrlListView_SetItemImage($hListView, $item, $aLVchecked[$item], 2)
                        If $aLVchecked[$item] Then
                            _GUICtrlListView_SetItemText($hListView, $item, "True", 2)
                        Else
                            _GUICtrlListView_SetItemText($hListView, $item, "False", 2)
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func FillImageList( $hImageList )
    Local $aCheckboxUnChecked[822] = [ _
    66,77,54,3,0,0,0,0,0,0,54,0,0,0,40,0,0,0,16,0,0,0,16,0,0,0,1,0,24,0,0,0,0,0,0,0,0,0,196,14,0,0,196,14,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81, _
    28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,239,241,241,241,243,243,244,245,245, _
    246,247,247,248,249,249,250,251,251,252,253,253,254,254,254,255,255,255,255,255,255,255,255,255,8364,81,28,255,255,255,255,255,255,255,255,255, _
    8364,81,28,236,239,239,239,241,241,241,243,243,244,245,245,246,247,247,248,249,249,250,251,251,252,253,253,254,254,254,255,255,255,255,255,255, _
    8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,233,236,236,236,239,239,239,241,241,241,243,243,244,245,245,246,247,247,248,249,249, _
    250,251,251,252,253,253,254,254,254,255,255,255,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,229,232,232,233,236,236,236,239,239, _
    239,241,241,241,243,243,244,245,245,246,247,247,248,249,249,250,251,251,252,253,253,254,254,254,8364,81,28,255,255,255,255,255,255,255,255,255, _
    8364,81,28,226,229,229,229,232,232,233,236,236,236,239,239,239,241,241,241,243,243,244,245,245,246,247,247,248,249,249,250,251,251,252,253,253, _
    8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,222,226,226,226,229,229,229,232,232,233,236,236,236,239,239,239,241,241,241,243,243, _
    244,245,245,246,247,247,248,249,249,250,251,251,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,219,224,224,222,226,226,226,229,229, _
    229,232,232,233,236,236,236,239,239,239,241,241,241,243,243,244,245,245,246,247,247,248,249,249,8364,81,28,255,255,255,255,255,255,255,255,255, _
    8364,81,28,217,222,222,219,224,224,222,226,226,226,229,229,229,232,232,233,236,236,236,239,239,239,241,241,241,243,243,244,245,245,246,247,247, _
    8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,215,220,220,217,222,222,219,224,224,222,226,226,226,229,229,229,232,232,233,236,236, _
    236,239,239,239,241,241,241,243,243,244,245,245,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,215,220,220,215,220,220,217,222,222, _
    219,224,224,222,226,226,226,229,229,229,232,232,233,236,236,236,239,239,239,241,241,241,243,243,8364,81,28,255,255,255,255,255,255,255,255,255, _
    8364,81,28,215,220,220,215,220,220,215,220,220,217,222,222,219,224,224,222,226,226,226,229,229,229,232,232,233,236,236,236,239,239,239,241,241, _
    8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81, _
    28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, _
    255,255,255 ]

    Local $aCheckboxChecked[822] = [ _
    66,77,54,3,0,0,0,0,0,0,54,0,0,0,40,0,0,0,16,0,0,0,16,0,0,0,1,0,24,0,0,0,0,0,0,0,0,0,196,14,0,0,196,14,0,0,0,0,0,0,0,0,0,0,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364, _
    81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,241,243,243,243,245, _
    245,246,247,247,248,249,249,249,250,250,251,252,252,253,253,253,254,254,254,255,255,255,255,255,255,255,255,255,8364,81,28,255,255,255,255, _
    255,255,255,255,255,8364,81,28,239,241,241,241,243,243,243,245,245,246,247,247,248,249,249,249,250,250,251,252,252,253,253,253,254,254,254, _
    255,255,255,255,255,255,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,236,239,239,239,241,241,241,243,243,243,245,245,33,161,33, _
    248,249,249,249,250,250,251,252,252,253,253,253,254,254,254,255,255,255,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,233,236,236, _
    236,239,239,239,241,241,33,161,33,33,161,33,33,161,33,248,249,249,249,250,250,251,252,252,253,253,253,254,254,254,8364,81,28,255,255,255,255, _
    255,255,255,255,255,8364,81,28,230,234,234,233,236,236,33,161,33,33,161,33,33,161,33,33,161,33,33,161,33,248,249,249,249,250,250,251,252,252, _
    253,253,253,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,227,231,231,230,234,234,33,161,33,33,161,33,239,241,241,33,161,33,33,161, _
    33,33,161,33,248,249,249,249,250,250,251,252,252,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,225,229,229,227,231,231,33,161,33, _
    233,236,236,236,239,239,239,241,241,33,161,33,33,161,33,33,161,33,248,249,249,249,250,250,8364,81,28,255,255,255,255,255,255,255,255,255,8364, _
    81,28,223,227,227,225,229,229,227,231,231,230,234,234,233,236,236,236,239,239,239,241,241,33,161,33,33,161,33,246,247,247,248,249,249,8364,81, _
    28,255,255,255,255,255,255,255,255,255,8364,81,28,221,226,226,223,227,227,225,229,229,227,231,231,230,234,234,233,236,236,236,239,239,239,241, _
    241,33,161,33,243,245,245,246,247,247,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28,221,226,226,221,226,226,223,227,227,225,229,229, _
    227,231,231,230,234,234,233,236,236,236,239,239,239,241,241,241,243,243,243,245,245,8364,81,28,255,255,255,255,255,255,255,255,255,8364,81,28, _
    221,226,226,221,226,226,221,226,226,223,227,227,225,229,229,227,231,231,230,234,234,233,236,236,236,239,239,239,241,241,241,243,243,8364,81,28, _
    255,255,255,255,255,255,255,255,255,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81,28,8364,81, _
    28,8364,81,28,8364,81,28,8364,81,28,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, _
    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 ]

    _GDIPlus_Startup()

    Local $binImage = StringToBinary( StringFromASCIIArray( $aCheckboxUnChecked ) )

    ; Create stream object from image
    Local $tSize = StringLen( $binImage ) + 1
    Local $imgData = DllStructCreate( "byte[" & $tSize & "]" )
    DllStructSetData( $imgData, 1, $binImage )
    Local $iLength = DllStructGetSize( $imgData )
    Local $hMemory = _MemGlobalAlloc( $iLength, $GMEM_MOVEABLE )
    Local $pDest = _MemGlobalLock( $hMemory )
    Local $pSource = DllStructGetPtr( $imgData )
    _MemMoveMemory( $pSource, $pDest, $iLength )
    Local $pStream = _WinAPI_CreateStreamOnHGlobal( $pDest )

    ; Create bitmap from stream object
    Local $hImage = _GDIPlus_BitmapCreateFromStream( $pStream )
    Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap( $hImage )

    _GUIImageList_Add( $hImageList, $hBitmap )

    ; Cleanup
    _WinAPI_ReleaseStream( $pStream )
    _GDIPlus_ImageDispose( $hImage )
    _WinAPI_DeleteObject( $hBitmap )

    Local $binImage = StringToBinary( StringFromASCIIArray( $aCheckboxChecked ) )

    ; Create stream object from image
    Local $tSize = StringLen( $binImage ) + 1
    Local $imgData = DllStructCreate( "byte[" & $tSize & "]" )
    DllStructSetData( $imgData, 1, $binImage )
    Local $iLength = DllStructGetSize( $imgData )
    Local $hMemory = _MemGlobalAlloc( $iLength, $GMEM_MOVEABLE )
    Local $pDest = _MemGlobalLock( $hMemory )
    Local $pSource = DllStructGetPtr( $imgData )
    _MemMoveMemory( $pSource, $pDest, $iLength )
    Local $pStream = _WinAPI_CreateStreamOnHGlobal( $pDest )

    ; Create bitmap from stream object
    Local $hImage = _GDIPlus_BitmapCreateFromStream( $pStream )
    Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap( $hImage )

    _GUIImageList_Add( $hImageList, $hBitmap )

    ; Cleanup
    _WinAPI_ReleaseStream( $pStream )
    _GDIPlus_ImageDispose( $hImage )
    _WinAPI_DeleteObject( $hBitmap )

    _GDIPlus_Shutdown()
EndFunc

Func _GDIPlus_BitmapCreateFromStream( $pStream )
    Local $Ret = DllCall( $ghGDIPDll, 'uint', 'GdipCreateBitmapFromStream', 'ptr', $pStream, 'ptr*', 0 )
    If (@error) OR ($Ret[0]) Then
        Return SetError(@error, @extended, 0)
    EndIf
    Return $Ret[2]
EndFunc
Link to comment
Share on other sites

Don't want to use Bitmaps, the only option left is Owner Drawn ListView then, I simplified it by using Webdings(font containing many symbols), you can do it with GDI+ even. I have even changed the color of the selection. Modify as you need

Here is the example

#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <GUIConstants.au3>
#include <Misc.au3>

Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODS_SELECTED = 0x0001

Global $GUI_main = GUICreate("Phoenix XL | 09.23.2013", 300, 300)
Global $hGUI_tab_listview[2][10]
Global $hNewFont = -1

GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ;place before listview creation - message sent once for each ownerdrawn control created
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Global $iCheckboxItem = 1 ;first subitem is the checkitem
Global $aCheckBoxStates[11]

$hGUI_tab_listview[0][0] = GUICtrlCreateListView("", 15, 20, 250, 260, _
        BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_OWNERDRAWFIXED)) ; + $LVS_EX_CHECKBOXES + $LVS_SINGLESEL
Global $hListView = GUICtrlGetHandle(-1)

_GUICtrlListView_AddColumn(-1, "Name")
_GUICtrlListView_SetColumnWidth(-1, 0, 155)
_GUICtrlListView_AddColumn(-1, "Count")
_GUICtrlListView_SetColumnWidth(-1, 1, 72)

For $i = 0 To 10 ; populate the listview for testing purposes
    _GUICtrlListView_AddItem(-1, "test " & $i)
    _GUICtrlListView_AddSubItem(-1, $i, $i, 1)
Next

GUISetState(@SW_SHOW)

Do
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hNewFont)

For $i = 0 To 10
    ConsoleWrite("Item:  " & $i & @TAB & "CheckBox Toggled? " & _Iif($aCheckBoxStates[$i], "True", "False") & @CRLF)
Next

Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
    If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    GUIRegisterMsg($WM_MEASUREITEM, "") ;call this after last ownerdrawn listview created
    Return 1
EndFunc   ;==>WM_MEASUREITEM

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)

    Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected
    $tagDRAWITEMSTRUCT = DllStructCreate( _
            "uint cType;" & _
            "uint cID;" & _
            "uint itmID;" & _
            "uint itmAction;" & _
            "uint itmState;" & _
            "hwnd hItm;" & _
            "handle hDC;" & _
            "long itmRect[4];" & _
            "ulong_ptr itmData" _
            , $lParam)
    If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG

    $cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
    $bSelected = BitAND($itmState, $ODS_SELECTED)
    Switch $cID ; will look for ControlID, not window handle.
        Case $hGUI_tab_listview[0][0]
            Switch $itmAction
                Case $ODA_DRAWENTIRE

                    ; don't forget, this is BGR, not RGB
                    If $itmState = $bSelected Then ; item is not selected
                        $iBrushColor = 0xFFFFFF
                    Else ; item is selected
                        $iBrushColor = 0xC0CDEF
                    EndIf

                    Local $aBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $iBrushColor)
                    Local $aBrushOld = _WinAPI_SelectObject($hDC, $aBrush[0])
                    Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)
                    DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 1, 1) ; rectangle coordinates for coloring
                    ; +1 is the left margin
                    _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush[0])
                    _WinAPI_SelectObject($hDC, $aBrushOld)
                    _WinAPI_DeleteObject($aBrush[0])

                    ; for all columns of the row:
                    Local $iIndent_Checkbox = 18, $iSubItmText, $aSubItmRect, $iSubItmRect, $hOldFont
                    $local_alignment = $DT_LEFT

                    For $i = 0 To _GUICtrlListView_GetColumnCount($hGUI_tab_listview[0][0]) - 1

                        ; 1. get subitem text:
                        $iSubItmText = _GUICtrlListView_GetItemText($hGUI_tab_listview[0][0], $itmID, $i)

                        ; 2. get subitem coordinates for drawing its respective text
                        $aSubItmRect = _GUICtrlListView_GetSubItemRect($hGUI_tab_listview[0][0], $itmID, $i)
                        ; the function above accepts not only subitems (one-based index), but also main item (index=0)

                        ; 3. pass the coordinates to a DLL struct
                        $iSubItmRect = DllStructCreate("long[4]")
                        DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + 2, 1) ; +2 is left margin (X)

                        If $i = $iCheckboxItem Then DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + 2 + $iIndent_Checkbox, 1) ;indentation for the checkbox

                        DllStructSetData($iSubItmRect, 1, $aSubItmRect[1], 2) ;
                        DllStructSetData($iSubItmRect, 1, $aSubItmRect[2], 3)
                        DllStructSetData($iSubItmRect, 1, $aSubItmRect[3], 4)
                        _WinAPI_DrawText($hDC, $iSubItmText, $iSubItmRect, $local_alignment)

                        If $i = $iCheckboxItem Then ;subitem

                            If $hNewFont = -1 Then
                                Local $LOGFONT, $tFont, $pFont

                                $hNewFont = _WinAPI_CreateFont(10, 10) ;create a temp font
                                $hOldFont = _WinAPI_SelectObject($hDC, $hNewFont) ;get the current selected font
                                $LOGFONT = _
                                        'LONG lfHeight;' & _
                                        'LONG lfWidth;' & _
                                        'LONG lfEscapement;' & _
                                        'LONG lfOrientation;' & _
                                        'LONG lfWeight;' & _
                                        'BYTE lfItalic;' & _
                                        'BYTE lfUnderline;' & _
                                        'BYTE lfStrikeOut;' & _
                                        'BYTE lfCharSet;' & _
                                        'BYTE lfOutPrecision;' & _
                                        'BYTE lfClipPrecision;' & _
                                        'BYTE lfQuality;' & _
                                        'BYTE lfPitchAndFamily;' & _
                                        'WCHAR lfFaceName [32];'
                                $tFont = DllStructCreate($LOGFONT)

                                $pFont = DllStructGetPtr($tFont)
                                _WinAPI_GetObject($hOldFont, DllStructGetSize($tFont), $pFont) ;get the logfont of the selected font
                                _WinAPI_DeleteObject($hNewFont) ;delete the temporary font

                                DllStructSetData($tFont, "lfFaceName", "Wingdings")
                                DllStructSetData($tFont, "lfHeight", DllStructGetData($tFont, "lfHeight") - 3)

                                $hNewFont = _WinAPI_CreateFontIndirect($tFont) ;create the new font having the same properties as the old font had
                            EndIf

                            _WinAPI_SelectObject($hDC, $hNewFont) ;select the new font

                            DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + 2, 1) ; +2 is left margin (X)
                            DllStructSetData($iSubItmRect, 1, $aSubItmRect[1], 2) ;
                            DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + 2 + $iIndent_Checkbox, 3)
                            DllStructSetData($iSubItmRect, 1, $aSubItmRect[3], 4)

                            ;check = 254, blank = 168
                            _WinAPI_DrawText($hDC, ChrW(_Iif($aCheckBoxStates[$itmID], 254, 168)), $iSubItmRect, $local_alignment) ;wingdings 168 character is an empty box

                            _WinAPI_SelectObject($hDC, $hOldFont)
                        EndIf

                    Next


            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

Func WM_DESTROY($hWnd, $iMsg, $iwParam, $ilParam)
    ;for releasing the static objects from the memory.
    _SendMessage($hWnd, $WM_DRAWITEM, -1, -1)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DESTROY


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR, $hWndFrom, $iCode, $aHitTest, $item
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CLICK
                    $aHitTest = _GUICtrlListView_SubItemHitTest($hListView)
                    If $aHitTest[0] >= 0 And $aHitTest[1] = $iCheckboxItem Then ; if checkbox item is clicked
                        $aCheckBoxStates[$aHitTest[0]] = Not $aCheckBoxStates[$aHitTest[0]]
                        _GUICtrlListView_RedrawItems($hListView, $aHitTest[0], $aHitTest[0])
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY 

Keypoints of Basic Framework

  • WM_DRAWITEM and WM_MEASUREITEM are used for custom drawing
  • The Text is drawn with the default font.
  • The Font is changed to Webdings and the respective symbol resembling a check box is drawn.
  • WM_NOTIFY is used to detect user clicks on the items for toggling the states of the checkboxes.

 

Let me know what you think about it

Thumbs up if it helped

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Thank you very much for the help!
You really helping me.

LarsJ, there is a problem with your GUI (which gave in post #15 ). Look:
2yvqxzb.jpg

The checkboxes do not looking right.

PhoenixXL, you also have a problem in your GUI. your checkboxes also not look good.
w86lbo.jpg


if you will fix it then i will prefer your example because you do not use pictures and your example demonstrates the process better so it will be more easy to work with your example and you also change the names of the columns and this is very important.

Edited by Guest
Link to comment
Share on other sites

gil900, I have testet the code in post 15 on XP 32 bit and Win 7 64 bit under AutoIt 3.3.8.1. In both cases the images looks as the images in post 9. In which environment are you running the script?

Link to comment
Share on other sites

gil900, I have testet the code in post 15 on XP 32 bit and Win 7 64 bit under AutoIt 3.3.8.1. In both cases the images looks as the images in post 9. In which environment are you running the script?

i am using windows 7 64bit. the script runing under autoIt 3.3.8.1 .

i compiled the script to 32bit ..

Link to comment
Share on other sites

Surely there is some issue on your computer, please check the theme settings on your computer

For Me - Environment(Language:0409  Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X86)

With LarsJ script this is the output I get

post-67952-0-62435900-1380115273_thumb.p

With my script this is the output I get exactly the same as your image displayed(again download the script)

post-67952-0-95911900-1380115294_thumb.p

...and you also change the names of the columns and this is very important.

 

You should do it, its rather easy if you try. When you stop to try none will help you..!

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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