iczelion tut31[9]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 jimgreen 的 blog

      or eax,edx

and add the desired view style to the existing styles (minus the current view style) of the listview control.

      invoke setwindowlong,hlist,gwl_style,eax

and set the new styles with setwindowlong.

      pop edx
      invoke checkmenuradioitem,hmenu,idm_icon,idm_list, edx,mf_checked    
   .endif

we also need to put the radio button in front of the selected view menu item. thus we call checkmenuradioitem, passing the current view style (double as menu id) to it.

when the user clicks on the column headers in the report view, we want to sort the items in the listview control. we must respond to wm_notify message.

  .elseif umsg==wm_notify
    push edi
    mov edi,lparam
    assume edi:ptr nmhdr
    mov eax,[edi].hwndfrom
    .if eax==hlist

when we receive wm_notify message, lparam contains the pointer to an nmhdr structure. we can check if this message is from the listview control by comparing the hwndfrom member of nmhdr to the handle to the listview control. if they match, we can assume that the notification came from the listview control.

      .if [edi].code==lvn_columnclick
        assume edi:ptr nm_listview

if the notification is from the listview control, we check if the code is lvn_columnclick. if it is, it means the user clicks on a column header. in the case that the code is lvn_columnclick, we can assume that lparam contains the pointer to an nm_listview structure which is a superset of the nmhdr structure. we then need to know on which column header the user clicks. examination of isubitem member reveals this info. the value in isubitem can be treated as the column number, starting from 0.

        .if [edi].isubitem==1
          .if sizesortorder==0 || sizesortorder==2

in the case isubitem is 1, it means the user clicks on the second column, size. we use state variables to keep the current status of the sorting order. 0 means "no sorting yet", 1 means "sort ascending", 2 means "sort descending". if the items/subitems in the column are not sorted before, or sorted descending, we set the sorting order to ascending.

            invoke sendmessage,hlist,lvm_sortitems,1,addr comparefunc

we send lvm_sortitems message to the listview control, passing 1 in wparam and the address of our comparison function in lparam. note that the value in wparam is user-defined, you can use it in any way you like. i use it as the sorting method in this example. we will take a look at the comparison function first.

comparefunc proc uses edi lparam1:dword, lparam2:dword, sorttype:dword
  local buffer[256]:byte
  local buffer1[256]:byte
  local lvi:lv_item

  mov lvi.imask,lvif_text
  lea eax,buffer
  mov lvi.psztext,eax
  mov lvi.cchtextmax,256

in the comparison function, the listview control will pass lparams (in lv_item) of the two items it needs to compare to us in lparam1 and lparam2. you'll recall that we put the index of the item in lparam. thus we can obtain information about the items by querying the listview control using the indexes. the info we need is the labels of the items/subitems being sorted. thus we prepare an lv_item structure for such purpose, specifying lvif_text in imask and the address of the buffer in psztext and the size of the buffer in cchtextmax.

  .if sorttype==1
    mov lvi.isubitem,1
    invoke sendmessage,hlist,lvm_getitemtext,lparam1,addr lvi

if the value in sorttype is 1 or 2, we know that the size column is clicked. 1 means sort the items according to their sizes in ascending order. 2 means the reverse. thus we specify isubitem as 1 ( to specify the size column) and send lvm_getitemtext message to the listview control to obtain the label (size string) of the subitem.

    invoke string2dword,addr buffer
    mov edi,eax

covert the size string into a dword value with string2dword which is the function i wrote. it returns the dword value in eax. we store it in edi for comparison later.

    invoke sendmessage,hlist,lvm_getitemtext,lparam2,addr lvi
    invoke string2dword,addr buffer
    sub edi,eax

本文关键:iczelion asm
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top