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

📄 lion-tutorial33.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  you have at most three choices: </font></p><ol>  <li><font face="Tahoma" size="-1">Apply to all text in the control (<font color="#006666"><b>SCF_ALL</b></font>)</font></li>  <li><font face="Tahoma" size="-1">Apply to the text currently in selection (<font color="#006666"><b>SCF_SELECTION</b></font>)</font></li>  <li><font face="Tahoma" size="-1">Apply to the whole word currently in selection     (<font color="#006666"><b>SCF_WORD</b></font> or <font color="#006666"><b>SCF_SELECTION</b></font>)</font></li></ol><p><font face="Tahoma" size="-1">The first and the second choices are straightforward.   The last choice requires a little explanation. If the current selection only   covers one or more of the characters in the word but not the whole word, specifying   the flag <font color="#006666"><b>SCF_WORD</b></font>+<font color="#006666"><b>SCF_SELECTION</b></font>   applies the text formatting to the whole word. Even if there is no current selection,   ie, only the caret is positioned in the word, the third choice also applies   the text formatting to the whole word.</font></p><p><font face="Tahoma" size="-1">To use <font color="#006666"><b>EM_SETCHARFORMAT</b></font>,   you need to fill several members of <font color="#006666"><b>CHARFORMAT</b></font>   (or <font color="#006666"><b>CHARFORMAT2</b></font>) structure. For example,   if we want to set the text color, we will fill the <font color="#006666"><b>CHARFORMAT</b></font>   structure as follows:</font></p><pre><font face="Tahoma"><b><font color="#000066">.data?	cf CHARFORMAT &lt;&gt;.....code	mov cf.cbSize,sizeof cf	mov cf.dwMask,CFM_COLOR	mov cf.crTextColor,0FF0000h	invoke SendMessage,hwndRichEdit,EM_SETCHARFORMAT,SCF_ALL,addr cf</font></b></font></pre><p><font face="Tahoma" size="-1">The above code snippet sets the text color of   the richedit control to pure blue. Note that if there is no text in the richedit   control when <font color="#006666"><b>EM_SETCHARFORMAT</b></font> is issued,   the text entered into the richedit control following the message will use the   text formatting specified by the<font color="#006666"><b> EM_SETCHARFORMAT</b></font>   message.<br>  </font></p><h3><font face="Times New Roman, Times, serif" color="#000099">Setting the text/saving   the text</font></h3><p><font face="Tahoma" size="-1">For those of you who are used to edit control,   you'll surely be familiar with <font color="#006666"><b>WM_GETTEXT</b></font>/<font color="#006666"><b>WM_SETTEXT</b></font>   as the means to set the text/get the text to/from the control. This method still   works with richedit control but may not be efficient if the file is large. Edit   control limits the text that can be entered into it to 64K but richedit control   can accept text much larger than that. It would be very cumbersome to allocate   a very large block of memory (such as 10 MB or so) to receive the text from   <font color="#006666"><b>WM_GETTEXT</b></font>. Richedit control offers a new   approach to this method, ie. text streaming.</font></p><p><font face="Tahoma" size="-1">To put it simply, you provide the address of   a callback function to the richedit control. And richedit control will call   that callback, passing the address of the buffer to it, when it's ready. The   callback will fill the buffer with the data it wants to send to the control   or read the data from the buffer and then waits for the next call until the   operation is finished. This paradigm is used for both streaming in (setting   the text) and streaming out (getting the text out of the control). You'll see   that this method is more efficient: the buffer is provided by the richedit control   itself so the data are divided into chunks. The operations involve two messages:<font color="#006666"><b>   EM_STREAMIN</b></font> and <font color="#006666"><b>EM_STREAMOUT</b></font></font></p><p><font face="Tahoma" size="-1">Both <font color="#006666"><b>EM_STREAMIN </b></font>and   <font color="#006666"> <b>EM_STREAMOUT</b></font> use the same syntax:</font></p><p><font face="Tahoma" size="-1"> <font color="#0000FF"><b>wParam</b></font> ==   formatting options.</font></p><table cellpadding="3" align="center" border="1">  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">SF_RTF</font></b></td>    <td><font face="MS Sans Serif" size="-1">The data is in the rich-text format       (RTF) </font></td>  </tr>  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">SF_TEXT</font></b></td>    <td><font face="MS Sans Serif" size="-1">The data is in the plain text format</font></td>  </tr>  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">SFF_PLAINRTF</font></b></td>    <td><font face="MS Sans Serif" size="-1">Only the keywords common to all languages       are streamed in.</font></td>  </tr>  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">SFF_SELECTION</font></b></td>    <td><font face="MS Sans Serif" size="-1">If specified, the target of the operation       is the text currently in selection. If you stream the text in, the text       replaces the current selection. If you stream the text out, only the text       currently in selection is streamed out. If this flag is not specified, the       operation affects the whole text in the control.</font></td>  </tr>  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">SF_UNICODE</font></b></td>    <td><font face="MS Sans Serif" size="-1">(Available on RichEdit 2.0 or later)       Specify the unicode text.</font></td>  </tr></table><p><font face="Tahoma" size="-1"> <font color="#0000FF"><b>lParam</b></font> ==   point to an <font color="#006666"><b>EDITSTREAM</b></font> structure which has   the following definition:</font><font face="Tahoma" size="-1"></font></p><pre><font face="Tahoma"> <font color="#006666"><b>EDITSTREAM STRUCT 	dwCookie DWORD    ? 	dwError DWORD ? 	pfnCallback DWORD ? EDITSTREAM ENDS</b></font></font><font face="Tahoma" size="-1"></font></pre><table cellpadding="3" align="center" border="1">  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">dwCookie</font></b></td>    <td><font face="MS Sans Serif" size="-1">application-defined value that will       be passed to the callback function speficied in <font color="#000066"><b>pfnCallback</b></font>       member below. We normally pass some important value to the callback function       such as the file handle to use in the stream-in/out procedure.</font></td>  </tr>  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">dwError</font></b></td>    <td><font face="MS Sans Serif" size="-1">Indicates the results of the stream-in       (read) or stream-out (write) operation. A value of zero indicates no error.       A nonzero value can be the return value of the EditStreamCallback function       or a code indicating that the control encountered an error. </font></td>  </tr>  <tr bgcolor="#FFFFCC">     <td><b><font face="MS Sans Serif" size="-1">pfnCallback</font></b></td>    <td><font face="MS Sans Serif" size="-1">Pointer to an EditStreamCallback       function, which is an application-defined function that the control calls       to transfer data. The control calls the callback function repeatedly, transferring       a portion of the data with each call</font></td>  </tr></table><p><font face="Tahoma" size="-1">The editstream callback function has the following   definition:</font></p><pre><font face="Tahoma">	<b><font color="#990099">EditStreamCallback</font> proto <font color="#CC00CC">dwCookie</font>:DWORD,<br>				 <font color="#CC00CC">pBuffer</font>:DWORD,				 <font color="#CC00CC">NumBytes</font>:DWORD,				 <font color="#CC00CC">pBytesTransferred</font>:DWORD</b></font></pre><p><font face="Tahoma" size="-1">You have to create a function with the above   prototype in your program. And then pass its address to <font color="#006666"><b>EM_STREAMIN</b></font>   or <font color="#006666"><b>EM_STREAMOUT</b></font> via <font color="#006666"><b>EDITSTREAM</b></font>   structure.</font></p><p><font face="Tahoma" size="-1">For stream-in operation (settting the text in   the richedit control)</font><font face="Tahoma">:</font></p><pre><font face="Tahoma">	<font color="#660066"><b><font color="#990099">dwCookie</font></b></font>: the application-defined value you pass to <font color="#006666"><b>EM_STREAMIN</b></font> via <font color="#006666"><b>EDITSTREAM</b></font> structure. We almost always 		pass the file handle of the file we want to set its content to the control here.</font><font face="Tahoma">	<font color="#990099"><b>pBuffer</b></font>: points to the buffer provided by the richedit control that will receive the text from your callback function.	<font color="#990099"><b>NumBytes</b></font>: the maximum number of bytes you can write the the buffer (pBuffer) in this call. You <font color="#000099"><b>MUST</b></font> always obey this limit, ie, you can send		less data than the value in NumBytes but must not send more data than this value. You can think of this value as the size		of the buffer in pBuffer.   <b><font color="#990099">pBytesTransferred</font></b>: points to a dword that you must set the value indicating the number of bytes you actually transferred to the buffer.		This value is usually identical to the value in <font color="#990099"><b>NumBytes</b></font>. The exception is when the data is to send is less than		the size of the buffer provided such as when the end of file is reached.</font></pre><p><font face="Tahoma"><font size="-1"> For stream-out operation (getting the   text out of the richedit control):</font></font><font face="Tahoma"><font size="-1"></font></font><font face="Tahoma"><font size="-1"></font></font></p><pre><font face="Tahoma">	<font color="#FFFFFF"><b><font color="#990099">dwCookie</font></b></font>: Same as the stream-in operation. We usually pass the file handle we want to write the data to in this parameter. 	<font color="#990099"><b>pBuffer</b></font>: points to the buffer provided by the richedit control that is filled with the data from the richedit control. 		To obtain its size, you must examine the value of <font color="#990099"><b>NumBytes</b></font>. <font color="#990099"><b>	NumBytes</b></font>: the size of the data in the buffer pointed to by pBuffer. 	<font color="#990099"><b>pBytesTransferred</b></font>: points to a dword that you must set the value indicating the number of bytes you actually read from the buffer.</font><font face="Tahoma"><font size="-1"></font></font></pre><p><font face="Tahoma" size="-1">The callback function returns 0 to indicate success   and richedit control will continue calling the callback function if there is   still data left to read/write. If some error occurs during the process and you   want to stop the operation, returns a non-zero value and the richedit control   will discard the data pointed to by pBuffer. The error/success value will be   filled in the <font color="#006666"><b>dwError</b></font> field of <font color="#990000"><b>EDITSTREAM</b></font>   so you can examine the error/success status of the stream operation after <font color="#006666"><b>SendMessage</b></font>   returns. </font><font face="Tahoma"><font size="-1"></font></font></p><h3><font face="Times New Roman, Times, serif" color="#0000CC">Example:</font></h3><p><font face="Tahoma" size="-1">The example below is a simple editor which you   can open an asm source code file, edit and save it. It uses RichEdit control   version 2.0 or above.</font></p><pre align="left"><b><font face="Tahoma">.386.model flat,stdcalloption casemap:noneinclude \masm32\include\windows.incinclude \masm32\include\user32.incinclude \masm32\include\comdlg32.incinclude \masm32\include\gdi32.incinclude \masm32\include\kernel32.incincludelib \masm32\lib\gdi32.libincludelib \masm32\lib\comdlg32.libincludelib \masm32\lib\user32.libincludelib \masm32\lib\kernel32.libWinMain proto :DWORD,:DWORD,:DWORD,:DWORD.constIDR_MAINMENU                   equ 101IDM_OPEN                      equ  40001IDM_SAVE                       equ 40002IDM_CLOSE                      equ 40003IDM_SAVEAS                     equ 40004IDM_EXIT                       equ 40005IDM_COPY                      equ  40006IDM_CUT                       equ  40007IDM_PASTE                      equ 40008IDM_DELETE                     equ 40009IDM_SELECTALL                  equ 40010IDM_OPTION 			equ 40011IDM_UNDO			equ 40012IDM_REDO			equ 40013IDD_OPTIONDLG                  equ 101IDC_BACKCOLORBOX               equ 1000IDC_TEXTCOLORBOX               equ 1001RichEditID 			equ 300.dataClassName db "<font color="#0000FF">IczEditClass</font>",0AppName  db "<font color="#0000FF">IczEdit version 1.0</font>",0RichEditDLL db "<font color="#0000FF">riched20.dll</font>",0RichEditClass db "<font color="#0000FF">RichEdit20A</font>",0NoRichEdit db "<font color="#0000FF">Cannot find riched20.dll</font>",0ASMFilterString 		db "<font color="#0000FF">ASM Source code (*.asm)</font>",0,"*<font color="#0000FF">.asm</font>",0				db "<font color="#0000FF">All Files (*.*)</font>",0,"<font color="#0000FF">*.*</font>",0,0OpenFileFail db "<font color="#0000FF">Cannot open the file</font>",0WannaSave db "<font color="#0000FF">The data in the control is modified. Want to save it?</font>",0FileOpened dd FALSEBackgroundColor dd 0FFFFFFh		<font color="#006666">; default to white</font>TextColor dd 0		<font color="#006666">; default to black</font>.data?hInstance dd ?hRichEdit dd ?hwndRichEdit dd ?FileName db 256 dup(?)AlternateFileName db 256 dup(?)CustomColors dd 16 dup(?).codestart:	invoke GetModuleHandle, NULL	mov    hInstance,eax<font color="#FF0033">	invoke LoadLibrary,addr RichEditDLL</font>	.if eax!=0		mov hRichEdit,eax		invoke WinMain, hInstance,0,0, SW_SHOWDEFAULT		invoke FreeLibrary,hRichEdit	.else		invoke MessageBox,0,addr NoRichEdit,addr AppName,MB_OK or MB_ICONERROR	.endif	invoke ExitProcess,eax	WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD	LOCAL wc:WNDCLASSEX	LOCAL msg:MSG	LOCAL hwnd:DWORD	mov   wc.cbSize,SIZEOF WNDCLASSEX	mov   wc.style, CS_HREDRAW or CS_VREDRAW	mov   wc.lpfnWndProc, OFFSET WndProc	mov   wc.cbClsExtra,NULL	mov   wc.cbWndExtra,NULL	push  hInst	pop   wc.hInstance	mov   wc.hbrBackground,COLOR_WINDOW+1	mov   wc.lpszMenuName,IDR_MAINMENU	mov   wc.lpszClassName,OFFSET ClassName	invoke LoadIcon,NULL,IDI_APPLICATION	mov   wc.hIcon,eax	mov   wc.hIconSm,eax	invoke LoadCursor,NULL,IDC_ARROW	mov   wc.hCursor,eax	invoke RegisterClassEx, addr wc	INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\           hInst,NULL	mov   hwnd,eax	invoke ShowWindow, hwnd,SW_SHOWNORMAL	invoke UpdateWindow, hwnd	.while TRUE		invoke GetMessage, ADDR msg,0,0,0		.break .if (!eax)		invoke TranslateMessage, ADDR msg		invoke DispatchMessage, ADDR msg	.endw	mov   eax,msg.wParam	retWinMain endp<font color="#003399">StreamInProc</font> proc hFile:DWORD,pBuffer:DWORD, NumBytes:DWORD, pBytesRead:DWORD	invoke ReadFile,hFile,pBuffer,NumBytes,pBytesRead,0	xor eax,1	ret<font color="#003399">StreamInProc</font> endp

⌨️ 快捷键说明

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