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

📄 lion-tutorial12.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 3 页
字号:
  and CS_HREDRAW styles. We use this opportunity to resize our edit control to 
  the same size as the client area of the parent window. First we have to know 
  the current width and height of the client area of the parent window. We get 
  this info from lParam. The high word of lParam contains the height and the low 
  word of lParam the width of the client area. We then use the information to 
  resize the edit control by calling MoveWindow function which, in addition to 
  changing the position of the window, can alter the size too. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .if ax==IDM_OPEN</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  mov&nbsp; ofn.Flags, OFN_FILEMUSTEXIST or \</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  OFN_PATHMUSTEXIST or OFN_LONGNAMES or\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  OFN_EXPLORER or OFN_HIDEREADONLY</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke GetOpenFileName, ADDR ofn</b> 
<p>When the user selects File/Open menu item, we fill in the Flags member of ofn 
  structure and call GetOpenFileName function to display the open file dialog 
  box. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  .if eax==TRUE</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke CreateFile,ADDR buffer,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  GENERIC_READ or GENERIC_WRITE ,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  FILE_SHARE_READ or FILE_SHARE_WRITE,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  NULL</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  mov hFile,eax</b> 
<p>After the user selects a file to open, we call CreateFile to open the file. 
  We specifies that the function should try to open the file for read and write. 
  After the file is opened, the function returns the handle to the opened file 
  which we store in a global variable for future use. This function has the following 
  syntax: 
<p><b>CreateFile proto lpFileName:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dwDesiredAccess:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dwShareMode:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  lpSecurityAttributes:DWORD,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dwCreationDistribution:DWORD\,</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dwFlagsAndAttributes:DWORD\,</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  hTemplateFile:DWORD</b> 
<p><b>dwDesiredAccess</b> specifies which operation you want to perform on the 
  file. 
<ul>
  <li> <b>0&nbsp;</b> Open the file to query its attributes. You have to rights 
    to read or write the data.</li>
  <li> <b>GENERIC_READ</b>&nbsp;&nbsp; Open the file for reading.</li>
  <li> <b>GENERIC_WRITE</b>&nbsp; Open the file for writing.</li>
</ul>
<b>dwShareMode</b> specifies which operation you want to allow other processes 
to perform on the file that 's being opened. 
<ul>
  <li> <b>0</b>&nbsp; Don't share the file with other processes.</li>
  <li> <b>FILE_SHARE_READ</b>&nbsp; allow other processes to read the data from 
    the file being opened</li>
  <li> <b>FILE_SHARE_WRITE</b>&nbsp; allow other processes to write data to the 
    file being opened.</li>
</ul>
<b>lpSecurityAttributes</b> has no significance under Windows 95. <br>
<b>dwCreationDistribution</b> specifies the action CreateFile will perform when 
the file specified in lpFileName exists or when it doesn't exist. 
<ul>
  <li> <b>CREATE_NEW</b> Creates a new file. The function fails if the specified 
    file already exists.</li>
  <li> <b>CREATE_ALWAYS</b> Creates a new file. The function overwrites the file 
    if it exists.</li>
  <li> <b>OPEN_EXISTING</b> Opens the file. The function fails if the file does 
    not exist.</li>
  <li> <b>OPEN_ALWAYS</b> Opens the file, if it exists. If the file does not exist, 
    the function creates the file as if dwCreationDistribution were CREATE_NEW.</li>
  <li> <b>TRUNCATE_EXISTING</b> Opens the file. Once opened, the file is truncated 
    so that its size is zero bytes. The calling process must open the file with 
    at least GENERIC_WRITE access. The function fails if the file does not exist.</li>
</ul>
dwFlagsAndAttributes specifies the file attributes 
<ul>
  <li> <b>FILE_ATTRIBUTE_ARCHIVE</b> The file is an archive file. Applications 
    use this attribute to mark files for backup or removal.</li>
  <li> <b>FILE_ATTRIBUTE_COMPRESSED</b> The file or directory is compressed. For 
    a file, this means that all of the data in the file is compressed. For a directory, 
    this means that compression is the default for newly created files and subdirectories.</li>
  <li> <b>FILE_ATTRIBUTE_NORMAL</b> The file has no other attributes set. This 
    attribute is valid only if used alone.</li>
  <li> <b>FILE_ATTRIBUTE_HIDDEN</b> The file is hidden. It is not to be included 
    in an ordinary directory listing.</li>
  <li> <b>FILE_ATTRIBUTE_READONLY</b> The file is read only. Applications can 
    read the file but cannot write to it or delete it.</li>
  <li> <b>FILE_ATTRIBUTE_SYSTEM </b>The file is part of or is used exclusively 
    by the operating system.</li>
</ul>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE</b> <br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
mov&nbsp; hMemory,eax</b> <br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
invoke GlobalLock,hMemory</b> <br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
mov&nbsp; pMemory,eax</b> 
<p>When the file is opened, we allocate a block of memory for use by ReadFile 
  and WriteFile functions. We specify GMEM_MOVEABLE flag&nbsp; to let Windows 
  move the memory block around to consolidate memory. GMEM_ZEROINIT flag tells 
  GlobalAlloc to fill the newly allocated memory block with zeroes. <br>
  When GlobalAlloc returns successfully, eax contains the handle to the allocated 
  memory block. We pass this handle to GlobalLock function which returns a pointer 
  to the memory block. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke ReadFile,hFile,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SendMessage,hwndEdit,WM_SETTEXT,NULL,pMemory</b> 
<p>When the memory block is ready for use, we call ReadFile function to read data 
  from the file. When a file is first opened or created, the file pointer is at 
  offset 0. So in this case, we start reading from the first byte in the file 
  onwards. The first parameter of ReadFile is the handle of the file to read, 
  the second is the pointer to the memory block to hold the data, next is the 
  number of bytes to read from the file, the fourth param is the address of the 
  variable of DWORD size that will be filled with the number of bytes actually 
  read from the file. <br>
  After we fill the memory block with the data, we put the data into the edit 
  control by sending WM_SETTEXT message to the edit control with lParam containing 
  the pointer to the memory block. After this call, the edit control shows the 
  data in its client area. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke CloseHandle,hFile</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke GlobalUnlock,pMemory</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke GlobalFree,hMemory</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  .endif</b> 
<p>At this point, we have no need to keep the file open any longer since our purpose 
  is to write the modified data from the edit control to another file, not the 
  original file. So we close the file by calling CloseHandle with the file handle 
  as its parameter. Next we unlock the memory block and free it. Actually you 
  don't have to free the memory at this point, you can reuse the memory block 
  during the save operation later. But for demonstration purpose , I choose to 
  free it here. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SetFocus,hwndEdit</b> 
<p>When the open file dialog box is displayed on the screen, the input focus shifts 
  to it. So after the open file dialog is closed, we must move the input focus 
  back to the edit control. <br>
  This end the read operation on the file. At this point, the user can edit the 
  content of the edit control.And when he wants to save the data to another file, 
  he must select File/Save as menuitem which displays a save as dialog box. The 
  creation of the save as dialog box is not much different from the open file 
  dialog box. In fact, they differ in only the name of the functions, GetOpenFileName 
  and GetSaveFileName. You can reuse most members of the ofn structure too except 
  the Flags member. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  mov ofn.Flags,OFN_LONGNAMES or\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  OFN_EXPLORER or OFN_HIDEREADONLY</b> 
<p>In our case, we want to create a new file, so OFN_FILEMUSTEXIST and OFN_PATHMUSTEXIST 
  must be left out else the dialog box will not let us create a file that doesn't 
  already exist. <br>
  The dwCreationDistribution parameter of the CreateFile function must be changed 
  to <b>CREATE_NEW</b> since we want to create a new file. <br>
  The remaining code is identical to those in the open file section except the 
  following: 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SendMessage,hwndEdit,WM_GETTEXT,MEMSIZE-1,pMemory</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke WriteFile,hFile,pMemory,eax,ADDR SizeReadWrite,NULL</b> 
<p>We send WM_GETTEXT message to the edit control to copy the data from it to 
  the memory block we provide, the return value in eax is the length of the data 
  inside the buffer. After the data is in the memory block, we write them to the 
  new file.<strong> </strong>
<hr size="1">
<div align="center"> This article come from Iczelion's asm page, Welcom to <a href="http://asm.yeah.net">http://asm.yeah.net</a></div>

</body>
</html>

⌨️ 快捷键说明

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