⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tut31.html

📁 WINDOWS程序员使用指南--汇编基础
💻 HTML
📖 第 1 页 / 共 5 页
字号:
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">imask</font></td>
    <td><font face="MS Sans Serif" size="-1">A collection of flags indicating 
      which members in this structure are valid for this call. In general, this 
      field is similar to <font color="#FFFFCC"><b>imask</b></font> member of 
      <font color="#CCFFCC"><b>LV_COLUMN</b></font> above. Check your win32 api 
      reference for more detail on the available flags.</font></td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">iItem</font></td>
    <td><font face="MS Sans Serif" size="-1">The index of the item this structure 
      refers to. The index is zero-based. You can think of this field as containing 
      the &quot;row&quot; number of a table.</font></td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">iSubItem</font></td>
    <td><font face="MS Sans Serif" size="-1">The index of the subitem associated 
      with the item specified by<font color="#FFFFCC"><b> iItem</b></font> above. 
      You can think of this field as containing the &quot;column&quot; of a table. 
      For example, if you want to insert an item into a newly created listview 
      control, the value in<font color="#FFFFCC"><b> iItem</b></font> would be 
      0 (because this item is the first one), and the value in <font color="#FFFFCC"><b>iSubItem</b></font> 
      would also be 0 (we want to insert the item into the first column). If you 
      want to specify a subitem associated with this item, the <font color="#FFFFCC"><b>iItem</b></font> 
      would be the index of the item you want to associate with (in the above 
      example, it's 0), the <font color="#FFFFCC"><b>iSubItem</b></font> would 
      be 1 or greater, depending on which column you want to insert the subitem 
      into. For example, if your listview control has 4 columns, the first column 
      will contain the items. The remaining 3 columns are for subitems. If you 
      want to insert a subitem into the 4th column, you need to specify the value 
      3 in <font color="#FFFFCC"><b>iSubItem</b></font>. </font></td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">state</font></td>
    <td> 
      <p><font face="MS Sans Serif" size="-1">This member contains flags that 
        reflect the status of the item. The state of an item can change because 
        of the user's actions or it can be modified by our program. The state 
        includes whether the item has the focus/is hilited/is selected for cut 
        operation/is selected. In addition to the state flags, It can also contains 
        one-based index into the overlay image/state image for use by the item. 
        </font></p>
    </td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">stateMask</font></td>
    <td><font face="MS Sans Serif" size="-1">Since the state member above can 
      contain the state flags, overlay image index , and state image index, we 
      need to tell Windows which value we want to set or retrieve. The value in 
      this field is for such use.</font></td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">pszText</font></td>
    <td><font face="MS Sans Serif" size="-1">The address of an ASCIIZ string that 
      will be used as the label of the item in the case we want to set/insert 
      the item. In the case that we use this structure to retrieve the item's 
      property, this member must contain the address of a buffer that will be 
      filled with the label of the item.</font></td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">cchTextMax</font></td>
    <td><font face="MS Sans Serif" size="-1">This field is used only when you 
      use this structure to receive info about an item. In this case, this field 
      contains the size in bytes of the buffer specified in <font color="#FFFFCC"><b>pszText</b></font> 
      above.</font></td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">iImage</font></td>
    <td><font face="MS Sans Serif" size="-1">The index into the imagelist containing 
      the icons for the listview control. This index points to the icon to be 
      used with this item.</font></td>
  </tr>
  <tr bgcolor="#333300"> 
    <td><font face="MS Sans Serif" size="-1">lParam</font></td>
    <td><font face="MS Sans Serif" size="-1">A user-defined value that will be 
      used when you sort items in the listview control. In short, when you tell 
      the listview control to sort the items, the listview control will compare 
      the items in pairs. It will send the <font color="#FFFFCC"><b>lParam</b></font> 
      values of both items to you so you can decide which of the two should be 
      listed first. If you're still hazy about this, don't worry. You'll learn 
      more about sorting later.</font></td>
  </tr>
</table>
<p><font face="MS Sans Serif" size="-1">Let's summarize the steps in inserting 
  an item/subitem into a listview control.</font></p>
<ol>
  <li><font face="MS Sans Serif" size="-1">Create a variable of type <font color="#CCFFCC"><b>LV_ITEM</b></font> 
    structure</font></li>
  <li><font face="MS Sans Serif" size="-1">Fill it with necessary information</font></li>
  <li><font face="MS Sans Serif" size="-1">Send <font color="#CCFFCC"><b>LVM_INSERTITEM</b></font> 
    message to the listview control if you want to insert an item. Or if you want 
    to *insert* a subitem, send <font color="#CCFFCC"><b>LVM_SETITEM</b></font> 
    instead. This is rather confusing if you don't understand the relationship 
    between an item and its subitems. <font color="#FFCC33"><b>Subitems are considered 
    as properties of an item</b></font>. Thus you can insert items but not subitems 
    and you can't have a subitem without an associated item. That's why you need 
    to send <font color="#CCFFCC"><b>LVM_SETITEM</b></font> message to add a subitem 
    instead of <font color="#CCFFCC"><b>LVM_INSERTITEM</b></font>. </font></li>
</ol>
<h3><font face="Arial, Helvetica, sans-serif">ListView Messages/Notifications</font></h3>
<p><font face="MS Sans Serif" size="-1">Now that you know how to create and populate 
  a listview control, the next step is to communicate with it. A listview control 
  communicates with the parent window via messages and notifications. The parent 
  window can control the listview control by sending messages to it. The listview 
  control notifies the parent of important/interesting events via <font color="#CCFFCC"><b>WM_NOTIFY</b></font> 
  message, just like other common controls.</font></p>
<h3><font face="Arial, Helvetica, sans-serif">Sorting items/subitems</font></h3>
<p><font face="MS Sans Serif" size="-1">You can specify the default sorting order 
  of a listview control by specifying <font color="#CCFFCC"><b>LVS_SORTASCENDING</b></font> 
  or <font color="#CCFFCC"><b>LVS_SORTDESCENDING</b></font> styles in <font color="#FFFFCC"><b>CreateWindowEx</b></font>. 
  These two styles order the items using their labels only. If you want to sort 
  the items in other ways, you need to send <font color="#CCFFCC"><b>LVM_SORTITEMS</b></font> 
  message to the listview control.</font></p>
<blockquote>
  <p><font face="MS Sans Serif" size="-1"><b>LVM_SORTITEMS<br>
    wParam = lParamSort<br>
    lParam = pCompareFunction</b></font></p>
</blockquote>
<p><font face="MS Sans Serif" size="-1"><b><font color="#CCFFCC">lParamSort </font></b>is 
  a user-defined value that will be passed to the compare function. You can use 
  this value in any way you want.<br>
  <font color="#CCFFCC"><b>pCompareFunction</b></font> is the address of the user-defined 
  function that will decide the outcome of the comparison of items in the listview 
  control. The function has the following prototype:</font></p>
<p><font face="MS Sans Serif" size="-1"><b><font color="#CCFFCC">CompareFunc proto 
  lParam1:DWORD, lParam2:DWORD, lParamSort:DWORD</font></b></font></p>
<p><font face="MS Sans Serif" size="-1"><b><font color="#FFFFCC">lParam1</font></b> 
  and <font color="#FFFFCC"><b>lParam2</b></font> are the values in <font color="#FFFFCC"><b>lParam</b></font> 
  member of <font color="#CCFFCC"><b>LV_ITEM</b></font> that you specify when 
  you insert the items into the listview control.<br>
  <font color="#FFFFCC"><b>lParamSort</b></font> is the value in wParam you sent 
  with <font color="#CCFFCC"><b>LVM_SORTITEMS</b></font></font></p>
<p><font face="MS Sans Serif" size="-1">When the listview control receives<font color="#CCFFCC"><b> 
  LVM_SORTITEMS</b></font> message, it calls the compare function specified in<font color="#FFFFCC"><b> 
  lParam</b></font> of the message when it needs to ask us for the result of comparison 
  between two items. In short, the comparison function will decide which of the 
  two items sent to it will precede the other. The rule is simple: if the function 
  returns a negative value, the first item (represented by<font color="#FFFFCC"><b> 
  lParam1</b></font>) should precede the other. If the function returns a positive 
  value, the second item (represented by <font color="#FFFFCC"><b>lParam2</b></font>) 
  should precede the first one. If both items are equal, it must return zero. 
  </font></p>
<p><font face="MS Sans Serif" size="-1">What makes this method work is the value 
  in <font color="#FFFFCC"><b>lParam</b></font> of <font color="#CCFFCC"><b>LV_ITEM</b></font> 
  structure. If you need to sort the items (such as when the user clicks on a 
  column header), you need to think of a sorting scheme that makes use of the 
  values in lParam member. In the example, I put the index of the item in this 
  field so I can obtain other information about the item by sending <font color="#CCFFCC"><b>LVM_GETITEM</b></font> 
  message. Note that when the items are rearranged, their indexes also change. 
  So when the sorting is done in my example, I need to update the values in lParam 
  to reflect the new indexes. If you want to sort the items when the user clicks 
  on a column header, you need to process <font color="#CCFFCC"><b>LVN_COLUMNCLICK</b></font> 
  notification message in your window procedure. <font color="#CCFFCC"><b>LVN_COLUMNCLICK</b></font> 
  is passed to your window proc via <font color="#CCFFCC"><b>WM_NOTIFY</b></font> 
  message.</font></p>
<h3><font face="Arial, Helvetica, sans-serif">Example:</font></h3>
<p><font face="MS Sans Serif" size="-1">This example creates a listview control 
  and fills it with the names and sizes of the files in the current folder. The 
  default view is the report one. In the report view, you can click on the column 
  heads and the items will be sorted in ascending/descending order. You can select 
  the view you want via the menu. When you double-click on an item, a message 
  box showing the label of the item is displayed.</font></p>
<p><font face="Fixedsys">.386 <br>
  .model flat,stdcall <br>
  option casemap:none <br>
  include \masm32\include\windows.inc <br>
  include \masm32\include\user32.inc <br>
  include \masm32\include\kernel32.inc <br>
  include \masm32\include\comctl32.inc <br>
  includelib \masm32\lib\comctl32.lib <br>
  includelib \masm32\lib\user32.lib <br>
  includelib \masm32\lib\kernel32.lib <br>
  <br>
  WinMain proto :DWORD,:DWORD,:DWORD,:DWORD <br>
  <br>
  IDM_MAINMENU equ 10000 <br>
  IDM_ICON equ LVS_ICON <br>
  IDM_SMALLICON equ LVS_SMALLICON <br>
  IDM_LIST equ LVS_LIST <br>
  IDM_REPORT equ LVS_REPORT <br>
  <br>
  RGB macro red,green,blue <br>
  &nbsp; xor eax,eax <br>
  &nbsp; mov ah,blue <br>
  &nbsp; shl eax,8 <br>
  &nbsp; mov ah,green <br>
  &nbsp; mov al,red <br>
  endm <br>
  <br>
  .data <br>
  ClassName db "ListViewWinClass",0 <br>
  AppName db "Testing a ListView Control",0 <br>
  ListViewClassName db "SysListView32",0 <br>
  Heading1 db "Filename",0 <br>
  Heading2 db "Size",0 <br>
  FileNamePattern db "*.*",0 <br>
  FileNameSortOrder dd 0 <br>
  SizeSortOrder dd 0 <br>
  template db &quot;%lu&quot;,0</font><font face="Fixedsys"><br>
  <br>
  .data? <br>
  hInstance HINSTANCE ? <br>
  hList dd ? <br>
  hMenu dd ? <br>
  <br>
  .code <br>
  start: <br>
  &nbsp;&nbsp;invoke GetModuleHandle, NULL <br>
  &nbsp; mov hInstance,eax <br>
  &nbsp; invoke WinMain, hInstance,NULL, NULL, SW_SHOWDEFAULT <br>
  &nbsp; invoke ExitProcess,eax <br>
  &nbsp; invoke InitCommonControls <br>
  WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD 
  <br>
  &nbsp;&nbsp;LOCAL wc:WNDCLASSEX <br>
  &nbsp;&nbsp;LOCAL msg:MSG <br>
  &nbsp; LOCAL hwnd:HWND<br>
  <br>
  &nbsp; mov wc.cbSize,SIZEOF WNDCLASSEX <br>
  &nbsp; mov wc.style, NULL <br>
  &nbsp; mov wc.lpfnWndProc, OFFSET WndProc <br>
  &nbsp; mov wc.cbClsExtra,NULL <br>
  &nbsp; mov wc.cbWndExtra,NULL <br>
  &nbsp; push hInstance <br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -