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

📄 lion-tutorial31.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 4 页
字号:
  &nbsp; .if SortType==1 <br>
  &nbsp;&nbsp;&nbsp; mov lvi.iSubItem,1 <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam1,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke String2Dword,addr buffer <br>
  &nbsp;&nbsp;&nbsp; mov edi,eax <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam2,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke String2Dword,addr buffer <br>
  &nbsp;&nbsp;&nbsp; sub edi,eax <br>
  &nbsp;&nbsp;&nbsp; mov eax,edi <br>
  &nbsp; .elseif SortType==2 <br>
  &nbsp;&nbsp;&nbsp; mov lvi.iSubItem,1 <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam1,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke String2Dword,addr buffer <br>
  &nbsp;&nbsp;&nbsp; mov edi,eax <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam2,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke String2Dword,addr buffer <br>
  &nbsp;&nbsp;&nbsp; sub eax,edi <br>
  &nbsp; .elseif SortType==3 <br>
  &nbsp;&nbsp;&nbsp; mov lvi.iSubItem,0 <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam1,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke lstrcpy,addr buffer1,addr buffer <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam2,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke lstrcmpi,addr buffer1,addr buffer <br>
  &nbsp; .else <br>
  &nbsp;&nbsp;&nbsp; mov lvi.iSubItem,0 <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam1,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke lstrcpy,addr buffer1,addr buffer <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEMTEXT,lParam2,addr lvi 
  <br>
  &nbsp;&nbsp;&nbsp; invoke lstrcmpi,addr buffer,addr buffer1 <br>
  &nbsp; .endif <br>
  &nbsp; ret <br>
  CompareFunc endp <br>
  <br>
  UpdatelParam proc uses edi <br>
  &nbsp;&nbsp; LOCAL lvi:LV_ITEM <br>
  <br>
  &nbsp;&nbsp; invoke SendMessage,hList, LVM_GETITEMCOUNT,0,0 <br>
  &nbsp;&nbsp; mov edi,eax <br>
  &nbsp;&nbsp; mov lvi.imask,LVIF_PARAM <br>
  &nbsp;&nbsp; mov lvi.iSubItem,0 <br>
  &nbsp;&nbsp; mov lvi.iItem,0 <br>
  &nbsp;&nbsp; .while edi>0 <br>
  &nbsp;&nbsp;&nbsp;&nbsp; push lvi.iItem <br>
  &nbsp;&nbsp;&nbsp;&nbsp; pop lvi.lParam <br>
  &nbsp;&nbsp;&nbsp;&nbsp; invoke SendMessage,hList, LVM_SETITEM,0,addr lvi <br>
  &nbsp;&nbsp;&nbsp;&nbsp; inc lvi.iItem <br>
  &nbsp;&nbsp;&nbsp;&nbsp; dec edi <br>
  &nbsp;&nbsp; .endw <br>
  &nbsp;&nbsp; ret <br>
  UpdatelParam endp <br>
  <br>
  ShowCurrentFocus proc <br>
  &nbsp;&nbsp; LOCAL lvi:LV_ITEM <br>
  &nbsp;&nbsp; LOCAL buffer[256]:BYTE <br>
  <br>
  &nbsp;&nbsp; invoke SendMessage,hList,LVM_GETNEXTITEM,-1, LVNI_FOCUSED<br>
  &nbsp;&nbsp; mov lvi.iItem,eax <br>
  &nbsp;&nbsp; mov lvi.iSubItem,0 <br>
  &nbsp;&nbsp; mov lvi.imask,LVIF_TEXT <br>
  &nbsp;&nbsp; lea eax,buffer <br>
  &nbsp;&nbsp; mov lvi.pszText,eax <br>
  &nbsp;&nbsp;&nbsp;mov lvi.cchTextMax,256 <br>
  &nbsp;&nbsp; invoke SendMessage,hList,LVM_GETITEM,0,addr lvi <br>
  &nbsp;&nbsp; invoke MessageBox,0, addr buffer,addr AppName,MB_OK <br>
  &nbsp;&nbsp; ret <br>
  ShowCurrentFocus endp <br>
  <br>
  WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM <br>
  &nbsp;&nbsp;.if uMsg==WM_CREATE <br>
  &nbsp;&nbsp;&nbsp; invoke CreateWindowEx, NULL, addr ListViewClassName, NULL, 
  LVS_REPORT+WS_CHILD+WS_VISIBLE, 0,0,0,0,hWnd, NULL, hInstance, NULL <br>
  &nbsp;&nbsp;&nbsp; mov hList, eax <br>
  &nbsp;&nbsp;&nbsp;&nbsp;invoke InsertColumn <br>
  &nbsp;&nbsp;&nbsp; invoke FillFileInfo <br>
  &nbsp;&nbsp;&nbsp; RGB 255,255,255 <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_SETTEXTCOLOR,0,eax <br>
  &nbsp;&nbsp;&nbsp; RGB 0,0,0 <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_SETBKCOLOR,0,eax <br>
  &nbsp;&nbsp;&nbsp; RGB 0,0,0 <br>
  &nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_SETTEXTBKCOLOR,0,eax <br>
  &nbsp;&nbsp;&nbsp; invoke GetMenu,hWnd <br>
  &nbsp;&nbsp;&nbsp; mov hMenu,eax <br>
  &nbsp;&nbsp;&nbsp; invoke CheckMenuRadioItem,hMenu,IDM_ICON,IDM_LIST, IDM_REPORT,MF_CHECKED 
  <br>
  &nbsp; .elseif uMsg==WM_COMMAND <br>
  &nbsp;&nbsp;&nbsp; .if lParam==0 <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke GetWindowLong,hList,GWL_STYLE <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and eax,not LVS_TYPEMASK <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov edx,wParam <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and edx,0FFFFh <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push edx <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or eax,edx <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke SetWindowLong,hList,GWL_STYLE,eax <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pop edx <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke CheckMenuRadioItem,hMenu,IDM_ICON,IDM_LIST, 
  edx,MF_CHECKED <br>
  &nbsp;&nbsp;&nbsp; .endif <br>
  &nbsp; .elseif uMsg==WM_NOTIFY <br>
  &nbsp;&nbsp;&nbsp; push edi <br>
  &nbsp;&nbsp;&nbsp; mov edi,lParam <br>
  &nbsp;&nbsp;&nbsp; assume edi:ptr NMHDR <br>
  &nbsp;&nbsp;&nbsp; mov eax,[edi].hwndFrom <br>
  &nbsp;&nbsp;&nbsp; .if eax==hList <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .if [edi].code==LVN_COLUMNCLICK <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assume edi:ptr NM_LISTVIEW <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .if [edi].iSubItem==1 <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .if SizeSortOrder==0 
  || SizeSortOrder==2 <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_SORTITEMS,1,addr 
  CompareFunc <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke UpdatelParam 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov SizeSortOrder,1 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .else <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_SORTITEMS,2,addr 
  CompareFunc <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke UpdatelParam 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov SizeSortOrder,2 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .endif <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .else <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .if FileNameSortOrder==0 
  || FileNameSortOrder==4 <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_SORTITEMS,3,addr 
  CompareFunc <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke UpdatelParam 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov FileNameSortOrder,3 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .else <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke SendMessage,hList,LVM_SORTITEMS,4,addr 
  CompareFunc <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke UpdatelParam 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov FileNameSortOrder,4 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .endif <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .endif <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assume edi:ptr NMHDR <br>
  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;.elseif [edi].code==NM_DBLCLK <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke ShowCurrentFocus <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .endif <br>
  &nbsp;&nbsp;&nbsp; .endif <br>
  &nbsp;&nbsp;&nbsp; pop edi <br>
  &nbsp; .elseif uMsg==WM_SIZE<br>
  &nbsp;&nbsp;&nbsp; mov eax,lParam <br>
  &nbsp;&nbsp;&nbsp; mov edx,eax <br>
  &nbsp;&nbsp;&nbsp; and eax,0ffffh <br>
  &nbsp;&nbsp;&nbsp; shr edx,16 <br>
  &nbsp;&nbsp;&nbsp; invoke MoveWindow,hList, 0, 0, eax,edx,TRUE <br>
  &nbsp; .elseif uMsg==WM_DESTROY <br>
  &nbsp;&nbsp;&nbsp; invoke PostQuitMessage,NULL <br>
  &nbsp; .else <br>
  &nbsp;&nbsp;&nbsp; invoke DefWindowProc,hWnd,uMsg,wParam,lParam <br>
  &nbsp;&nbsp;&nbsp; ret <br>
  &nbsp; .endif <br>
  &nbsp; xor eax,eax <br>
  &nbsp; ret <br>
  WndProc endp <br>
  end start </p>
<h3>Analysis:</h3>
<p>The first thing the program does when the main window is created is to create 
  a listview control.</p>
<p>&nbsp;&nbsp;.if uMsg==WM_CREATE <br>
  &nbsp;&nbsp;&nbsp; invoke CreateWindowEx, NULL, addr ListViewClassName, NULL, 
  LVS_REPORT+WS_CHILD+WS_VISIBLE, 0,0,0,0,hWnd, NULL, hInstance, NULL <br>
  &nbsp;&nbsp;&nbsp; mov hList, eax </p>
<p>We call <b>CreateWindowEx</b>, passing itthe name of the window class &quot;SysListView32&quot;. 
  The default view is the report view as specified by <b>LVS_REPORT</b> style.</p>
<p> &nbsp;&nbsp;&nbsp;&nbsp;invoke InsertColumn </p>
<p>After the listview control is created, we insert columns into it. </p>
<p>&nbsp;&nbsp;LOCAL lvc:LV_COLUMN <br>
  <br>
  &nbsp; mov lvc.imask,LVCF_TEXT+LVCF_WIDTH <br>
  &nbsp; mov lvc.pszText,offset Heading1 <br>
  &nbsp; mov lvc.lx,150 <br>
  &nbsp; invoke SendMessage,hList, LVM_INSERTCOLUMN, 0, addr lvc</p>
<p>We specify the label and the width of the first column, for storing the names 
  of the files, in <b>LV_COLUMN</b> structure thus we need to set<b> imask</b> 
  with <b>LVCF_TEXT</b> and <b>LVCF_WIDTH</b> flags. We fill <b>pszText</b> with 
  the address of the label and <b>lx</b> with the width of the column, in pixels. 
  When all is done, we send <b>LVM_INSERTCOLUMN</b> message to the listview control, 
  passing the structure to it.</p>
<p> &nbsp; or lvc.imask,LVCF_FMT<br>
  &nbsp; mov lvc.fmt,LVCFMT_RIGHT </p>
<p>When we are done with the insertion of the first column, we insert another 
  column for storing the sizes of the files. Since we need the sizes to right-align 
  in the column, we need to specify a flag in <b>fmt</b> member, <b>LVCFMT_RIGHT</b>. 
  We must also specify <b>LVCF_FMT</b> flag in imask, in addition to <b>LVCF_TEXT</b> 
  and <b>LVCF_WIDTH</b>.</p>
<p>&nbsp; mov lvc.pszText,offset Heading2 <br>
  &nbsp; mov lvc.lx,100<br>
  &nbsp; invoke SendMessage,hList, LVM_INSERTCOLUMN, 1 ,addr lvc </p>
<p>The remaining code is simple. Put the address of the label in <b>pszText</b> 
  and the width in<b> lx</b>. Then send <b>LVM_INSERTCOLUMN</b> message to the 
  listview control, specifying the column number and the address of the structure.</p>
<p>When the columns are inserted, we can fill items in the listview control.</p>
<p> &nbsp;&nbsp;&nbsp; invoke FillFileInfo </p>
<p>FillFileInfo has the following code.</p>
<p>FillFileInfo proc uses edi <br>
  &nbsp; LOCAL finddata:WIN32_FIND_DATA <br>
  &nbsp; LOCAL FHandle:DWORD <br>
  <br>
  &nbsp; invoke FindFirstFile,addr FileNamePattern,addr finddata </p>
<p>We call FindFirstFile to obtain the information of the first file that matches 
  the search criteria. FindFirstFile has the following prototype:</p>
<p><b>FindFirstFile proto pFileName:DWORD, pWin32_Find_Data:DWORD</b></p>
<p><b>pFileName</b> is the address of the filename to search for. This string 
  can contain wildcards. In our example, we use *.*, which amounts to search for 
  all the files in the current folder.<br>
  <b>pWin32_Find_Data</b> is the address of the <b>WIN32_FIND_DATA</b> structure 
  that will be filled with information about the file (if found). </p>
<p>This function returns<b> INVALID_HANDLE_VALUE</b> in eax if no matching file 
  is found. Otherwise it returns a search handle that will be used in subsequent 
  <b>FindNextFile</b> calls.</p>
<p> &nbsp; .if eax!=INVALID_HANDLE_VALUE <br>
  &nbsp;&nbsp;&nbsp; mov FHandle,eax <br>
  &nbsp;&nbsp;&nbsp; xor edi,edi </p>
<p>If a file is found, we store the search handle in a variable and then zero 
  out edi which will be used as the index into the items (row number).</p>
<p> &nbsp;&nbsp;&nbsp;&nbsp;.while eax!=0<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test finddata.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY 
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .if ZERO?</p>
<p>In this tutorial, I don't want to deal with the folders yet so I filter them 
  out by checking <b>dwFileAttributes</b> for files which have <b>FILE_ATTRIBUTE_DIRECTORY</b> 
  flag set. If they are found, I skip to call FindNextFile.</p>
<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke ShowFileInfo,edi, 
  addr finddata <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inc edi <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .endif<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke FindNextFile,FHandle,addr finddata &nbsp;&nbsp; 
  &nbsp;<br>
  &nbsp;&nbsp;&nbsp; .endw <br>
</p>
<p> We insert the name and size of the file into the listview control by calling 
  ShowFileInfo function. Then we increase the current row number in edi. Lastly 
  we proceed to call <b>FindNextFile</b> to search for the next file in the current 
  folder until <b>FindNextFile</b> returns 0 (meaning no more file is found).</p>
<p>&nbsp;&nbsp;&nbsp; invoke FindClose,FHandle <br>
  &nbsp; .endif <br>
  &nbsp; ret <br>
  FillFileInfo endp </p>
<p>When all files in the current folder are enumerated, we must close the search 
  handle.</p>
<p>Now let's look at the <b>ShowFileInfo</b> function. This function accepts two 
  parameters, the index of the item (row number) and the address of <b>WIN32_FIND_DATA</b> 
  structure.</p>
<p>ShowFileInfo proc uses edi row:DWORD, lpFind:DWORD <br>
  &nbsp; LOCAL lvi:LV_ITEM <br>
  &nbsp; LOCAL buffer[20]:BYTE <br>
  &nbsp; mov edi,lpFind <br>
  &nbsp; assume edi:ptr WIN32_FIND_DATA </p>
<p>Store the address of <b>WIN32_FIND_DATA</b> structure in edi.</p>

⌨️ 快捷键说明

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