The MASM Forum

General => The Campus => Topic started by: vogelsang on July 01, 2014, 03:42:09 AM

Title: checkbox in listview header
Post by: vogelsang on July 01, 2014, 03:42:09 AM
Hello all

I'm trying to add a checkbox to listview header which will select/unselect all checkboxes in the rows. I've wrote some code. But checkbox doesn't appear in the header.

WndProc code:

WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL hdi :HDITEM

mov eax, uMsg
wp_wm_create:
cmp eax, WM_CREATE
jne wp_wm_destroy

push NULL
push hInstance
push NULL
push hWnd
push 500
push 400
push 10
push 10
push LVS_REPORT + WS_CHILD + WS_VISIBLE + WS_BORDER + LVS_SHOWSELALWAYS
push OFFSET szLVText
push OFFSET szLVClassName
push 0
call CreateWindowEx ;create listview control
mov hLV, eax

push LVS_EX_FULLROWSELECT + LVS_EX_CHECKBOXES + LVS_EX_GRIDLINES
push 0
push LVM_SETEXTENDEDLISTVIEWSTYLE
push eax
call SendMessage ;add full row select, gridlines and checkboxes to listview items

call InsertColumns ;add columns to listview

call InsertItems ;add rows to listview

push 0
push 0
push LVM_GETHEADER
push hLV
call SendMessage ;get handle of listview header
mov hLVHeader, eax
     
push GWL_STYLE
push eax
call GetWindowLong ;get header window styles
or eax, HDS_CHECKBOXES ;add to it checkbox style
     
push eax
push GWL_STYLE
push hLVHeader
call SetWindowLong ;set header window new styles(add checkboxes)
   
push
push SIZEOF HDITEM
lea eax, hdi
push eax
call memfill ;zero out HDITEM struct
     
mov hdi._mask, HDI_FORMAT ;get current format of listview header
     
lea eax, hdi
push eax
push 0
push HDM_GETITEM
push hLVHeader
call SendMessage

mov hdi._mask, HDI_FORMAT
or hdi.fmt, HDF_CHECKBOX
     
lea eax, hdi
push eax
push 0
push HDM_SETITEM
push hLVHeader
call SendMessage ;add checkbox to header format

jmp exit_zero_WndProc
wp_wm_destroy:
cmp eax, WM_DESTROY
jne wp_wm_none

push 0
call PostQuitMessage

jmp exit_zero_WndProc
wp_wm_none:
push lParam
push wParam
push uMsg
push hWnd
call DefWindowProc

jmp exit_nonzero_WndProc
exit_zero_WndProc:
xor eax, eax
exit_nonzero_WndProc:
ret

WndProc ENDP


I'll add whole code if needed.
Could someone point me what is wrong?
Title: Re: checkbox in listview header
Post by: dedndave on July 01, 2014, 05:00:25 AM
http://stackoverflow.com/questions/8730212/how-to-show-a-check-box-in-tlistview-header-column (http://stackoverflow.com/questions/8730212/how-to-show-a-check-box-in-tlistview-header-column)

it's in C++ or whatever
but, you can see they used extended style LVS_EX_CHECKBOXES or LVS_EX_FULLROWSELECT
and - that common controls 6.0 or later is required
so - you need a manifest and InitCommonControls (probably Ex) if using XP
Title: Re: checkbox in listview header
Post by: vogelsang on July 01, 2014, 06:14:51 AM
Quote
it's in C++ or whatever
It's Delphi - probably objective Pascal. I don't know it.
Quote
but, you can see they used extended style LVS_EX_CHECKBOXES or LVS_EX_FULLROWSELECT
I've also added those extended styles to my listview.
I'm using Win7. So checkbox in listview header should work.
Quote
so - you need a manifest and InitCommonControls (probably Ex) if using XP
You mean manifest file? I don't how to write it.

I've searched a lot about this issue before i've posted here and i've found some interessting sites.
c++ MFC:

http://www.codeproject.com/Articles/157033/How-to-Add-a-Checkbox-to-a-List-View-Column-Header
(http://www.codeproject.com/Articles/157033/How-to-Add-a-Checkbox-to-a-List-View-Column-Header)

http://www.codeproject.com/Articles/13586/Using-Check-Box-in-List-Control
(http://www.codeproject.com/Articles/13586/Using-Check-Box-in-List-Control)
But can't compile it on my VS. And I have pure c/c++ basic skills.
Title: Re: checkbox in listview header
Post by: dedndave on July 01, 2014, 09:48:56 AM
it's pretty easy to add a manifest for common controls 6.0

here is the text in the manifest file
it is XML - i usually name the file like ProjectName.xml
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df"/>
    </dependentAssembly>
  </dependency>
</assembly>


then, you add that to the resource file
the manifest for EXE's uses 2 constants
some older versions of resource.h did not have these constants defined
the newer versions do
so, i add them like this
#include "\masm32\include\resource.h"

#ifndef  CREATEPROCESS_MANIFEST_RESOURCE_ID
#define  CREATEPROCESS_MANIFEST_RESOURCE_ID  1
#endif

#ifndef  RT_MANIFEST
#define  RT_MANIFEST                         24
#endif


then, to add the manifest....
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "ProjectName.xml"

some members don't want to go through all that
they just use
1 24 "ProjectName.xml"
essentially the same thing

now, in your program...
        .DATA

icc INITCOMMONCONTROLSEX <sizeof INITCOMMONCONTROLSEX,0>

        .CODE

Start:  INVOKE  InitCommonControlsEx,offset icc


notice that the 0 in the structure may be replaced by whatever flagset you desire

http://msdn.microsoft.com/en-us/library/windows/desktop/bb775507%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/bb775507%28v=vs.85%29.aspx)

ICC_ANIMATE_CLASS
Load animate control class.

ICC_BAR_CLASSES
Load toolbar, status bar, trackbar, and tooltip control classes.

ICC_COOL_CLASSES
Load rebar control class.

ICC_DATE_CLASSES
Load date and time picker control class.

ICC_HOTKEY_CLASS
Load hot key control class.

ICC_INTERNET_CLASSES
Load IP address class.

ICC_LINK_CLASS
Load a hyperlink control class.

ICC_LISTVIEW_CLASSES
Load list-view and header control classes.

ICC_NATIVEFNTCTL_CLASS
Load a native font control class.

ICC_PAGESCROLLER_CLASS
Load pager control class.

ICC_PROGRESS_CLASS
Load progress bar control class.

ICC_STANDARD_CLASSES
Load one of the intrinsic User32 control classes. The user controls include button, edit, static, listbox, combobox, and scroll bar.

ICC_TAB_CLASSES
Load tab and tooltip control classes.

ICC_TREEVIEW_CLASSES
Load tree-view and tooltip control classes.

ICC_UPDOWN_CLASS
Load up-down control class.

ICC_USEREX_CLASSES
Load ComboBoxEx class.

ICC_WIN95_CLASSES
Load animate control, header, hot key, list-view, progress bar, status bar, tab, tooltip, toolbar, trackbar, tree-view, and up-down control classes.


looks like you'd want at least ICC_LISTVIEW_CLASSES
or you might use ICC_WIN95_CLASSES, which incudes that flag
Title: Re: checkbox in listview header
Post by: vogelsang on July 01, 2014, 11:10:39 PM
Great thanks dedndave. Checkbox is now on the header. But it doesn't mark item checkboxes. I'll try to figure out how to do it. Anyway once again great thanks :greenclp:.