WIN32汇编语言教程:第09章 通用控件 · 9.4 使用Richedit控件(3)
.if stFind.Flags & FR_DOWN
push @stFindText.chrg.cpMax
pop @stFindText.chrg.cpMin
.endif
mov @stFindText.chrg.cpMax,-1
;********************************************************************
; 设置查找选项
;********************************************************************
mov @stFindText.lpstrText,offset szFindText
mov ecx,stFind.Flags
and ecx,FR_MATCHCASE or FR_DOWN or FR_WHOLEWORD
;********************************************************************
; 查找并把光标设置到找到的文本上
;********************************************************************
invoke SendMessage,hWinEdit,EM_FINDTEXTEX,\
ecx,addr @stFindText
.if eax == -1
mov ecx,hWinMain
.if hFindDialog
mov ecx,hFindDialog
.endif
invoke MessageBox,ecx,addr szNotFound,NULL,\
MB_OK or MB_ICONINFORMATION
ret
.endif
invoke SendMessage,hWinEdit,EM_EXSETSEL,\
0,addr @stFindText.chrgText
invoke SendMessage,hWinEdit,EM_SCROLLCARET,NULL,NULL
ret
_FindText endp
;####################################################################
; 根据情况改变菜单项状态
;####################################################################
_SetStatus proc
local @stRange:CHARRANGE
invoke SendMessage,hWinEdit,EM_EXGETSEL,0,addr @stRange
;********************************************************************
mov eax,@stRange.cpMin
.if eax == @stRange.cpMax
invoke EnableMenuItem,hMenu,IDM_COPY,MF_GRAYED
invoke EnableMenuItem,hMenu,IDM_CUT,MF_GRAYED
.else
invoke EnableMenuItem,hMenu,IDM_COPY,MF_ENABLED
invoke EnableMenuItem,hMenu,IDM_CUT,MF_ENABLED
.endif
;********************************************************************
invoke SendMessage,hWinEdit,EM_CANPASTE,0,0
.if eax
invoke EnableMenuItem,hMenu,IDM_PASTE,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_PASTE,MF_GRAYED
.endif
;********************************************************************
invoke SendMessage,hWinEdit,EM_CANREDO,0,0
.if eax
invoke EnableMenuItem,hMenu,IDM_REDO,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_REDO,MF_GRAYED
.endif
;********************************************************************
invoke SendMessage,hWinEdit,EM_CANUNDO,0,0
.if eax
invoke EnableMenuItem,hMenu,IDM_UNDO,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_UNDO,MF_GRAYED
.endif
;********************************************************************
invoke GetWindowTextLength,hWinEdit
.if eax
invoke EnableMenuItem,hMenu,IDM_SELALL,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_SELALL,MF_GRAYED
.endif
;********************************************************************
invoke SendMessage,hWinEdit,EM_GETMODIFY,0,0
.if eax && hFile
invoke EnableMenuItem,hMenu,IDM_SAVE,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_SAVE,MF_GRAYED
.endif
;********************************************************************
.if szFindText
invoke EnableMenuItem,hMenu,IDM_FINDNEXT,MF_ENABLED
invoke EnableMenuItem,hMenu,IDM_FINDPREV,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_FINDNEXT,MF_GRAYED
invoke EnableMenuItem,hMenu,IDM_FINDPREV,MF_GRAYED
.endif
;********************************************************************
ret
_SetStatus endp
;####################################################################
_Init proc
local @stCf:CHARFORMAT
;********************************************************************
; 注册“查找”对话框消息,初始化“查找”对话框的结构
;********************************************************************
push hWinMain
pop stFind.hwndOwner
invoke RegisterWindowMessage,addr FINDMSGSTRING
mov idFindMessage,eax
;********************************************************************
; 建立输出文本窗口
;********************************************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassEdit,\
NULL,WS_CHILD OR WS_VISIBLE OR WS_VSCROLL \
OR WS_HSCROLL OR ES_MULTILINE or ES_NOHIDESEL,\
0,0,0,0,hWinMain,0,hInstance,NULL
mov hWinEdit,eax
invoke SendMessage,hWinEdit,EM_SETTEXTMODE,TM_PLAINTEXT,0
invoke RtlZeroMemory,addr @stCf,sizeof @stCf
mov @stCf.cbSize,sizeof @stCf
mov @stCf.yHeight,9 * 20
mov @stCf.dwMask,CFM_FACE or CFM_SIZE or CFM_BOLD
invoke lstrcpy,addr @stCf.szFaceName,addr szFont
invoke SendMessage,hWinEdit,EM_SETCHARFORMAT,0,addr @stCf
invoke SendMessage,hWinEdit,EM_EXLIMITTEXT,0,-1
ret
_Init endp
;####################################################################
_Quit proc
invoke _CheckModify
.if eax
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
.if hFile
上页:第09章 通用控件 · 9.4 使用Richedit控件(2) 下页:第09章 通用控件 · 9.4 使用Richedit控件(4)
第09章 通用控件
版权所有 © 云南伯恩科技 证书:粤ICP备09170368号