fn_pathmustexist invoke getsavefilename,addr ofn .if eax!=0 invoke createfile,addr alternatefilename,generic_write,file_share_read,null,create_always,file_attribute_normal,0 .if eax!=invalid_handle_value jmp @b .endif .endif .elseif ax==idm_find .if hsearch==0 invoke createdialogparam,hinstance,idd_finddlg,hwnd,addr searchproc,0 .endif .elseif ax==idm_replace .if hsearch==0 invoke createdialogparam,hinstance,idd_replacedlg,hwnd,addr replaceproc,0 .endif .elseif ax==idm_gotoline .if hsearch==0 invoke createdialogparam,hinstance,idd_gotodlg,hwnd,addr gotoproc,0 .endif .elseif ax==idm_findnext invoke lstrlen,addr findbuffer .if eax!=0 invoke sendmessage,hwndrichedit,em_exgetsel,0,addr findtext.chrg mov eax,findtext.chrg.cpmin .if eax!=findtext.chrg.cpmax push findtext.chrg.cpmax pop findtext.chrg.cpmin .endif mov findtext.chrg.cpmax,-1 mov findtext.lpstrtext,offset findbuffer invoke sendmessage,hwndrichedit,em_findtextex,fr_down,addr findtext .if eax!=-1 invoke sendmessage,hwndrichedit,em_exsetsel,0,addr findtext.chrgtext .endif .endif .elseif ax==idm_findprev invoke lstrlen,addr findbuffer .if eax!=0 invoke sendmessage,hwndrichedit,em_exgetsel,0,addr findtext.chrg mov findtext.chrg.cpmax,0 mov findtext.lpstrtext,offset findbuffer invoke sendmessage,hwndrichedit,em_findtextex,0,addr findtext .if eax!=-1 invoke sendmessage,hwndrichedit,em_exsetsel,0,addr findtext.chrgtext .endif .endif .elseif ax==idm_exit invoke sendmessage,hwnd,wm_close,0,0 .endif .endif .elseif umsg==wm_close invoke checkmodifystate,hwnd .if eax==true invoke destroywindow,hwnd .endif .elseif umsg==wm_size mov eax,lparam mov edx,eax and eax,0ffffh shr edx,16 invoke movewindow,hwndrichedit,0,0,eax,edx,true .elseif umsg==wm_destroy invoke postquitmessage,null .else invoke defwindowproc,hwnd,umsg,wparam,lparam ret .endif xor eax,eax ret wndproc endp end start
analysis
the search-for-text capability is implemented with em_findtextex. when the user clicks on find menuitem, idm_find message is sent and the find dialog box is displayed.
invoke getdlgitemtext,hwnd,idc_findedit,addr findbuffer,sizeof findbuffer .if eax!=0
when the user types the text to search for and then press ok button, we get the text to be searched for into findbuffer.
mov uflags,0 invoke sendmessage,hwndrichedit,em_exgetsel,0,addr findtext.chrg
if the text string is not null, we continue to initialize uflags variable to 0.this variable is used to store the search flags used with em_findtextex. after that, we obtain the current selection with em_exgetsel because we need to know the starting point of the search operation.