m_initmenupopup mov eax,lparam .if ax==0 ; file menu .if fileopened==true ; a file is already opened invoke enablemenuitem,wparam,idm_open,mf_grayed invoke enablemenuitem,wparam,idm_close,mf_enabled invoke enablemenuitem,wparam,idm_save,mf_enabled invoke enablemenuitem,wparam,idm_saveas,mf_enabled .else invoke enablemenuitem,wparam,idm_open,mf_enabled invoke enablemenuitem,wparam,idm_close,mf_grayed invoke enablemenuitem,wparam,idm_save,mf_grayed invoke enablemenuitem,wparam,idm_saveas,mf_grayed .endif .elseif ax==1 ; edit menu invoke prepareeditmenu,wparam .elseif ax==2 ; search menu bar .if fileopened==true invoke enablemenuitem,wparam,idm_find,mf_enabled invoke enablemenuitem,wparam,idm_findnext,mf_enabled invoke enablemenuitem,wparam,idm_findprev,mf_enabled invoke enablemenuitem,wparam,idm_replace,mf_enabled invoke enablemenuitem,wparam,idm_gotoline,mf_enabled .else invoke enablemenuitem,wparam,idm_find,mf_grayed invoke enablemenuitem,wparam,idm_findnext,mf_grayed invoke enablemenuitem,wparam,idm_findprev,mf_grayed invoke enablemenuitem,wparam,idm_replace,mf_grayed invoke enablemenuitem,wparam,idm_gotoline,mf_grayed .endif .endif .elseif umsg==wm_command .if lparam==0 ; menu commands mov eax,wparam .if ax==idm_open invoke rtlzeromemory,addr ofn,sizeof ofn mov ofn.lstructsize,sizeof ofn push hwnd pop ofn.hwndowner push hinstance pop ofn.hinstance mov ofn.lpstrfilter,offset asmfilterstring mov ofn.lpstrfile,offset filename mov byte ptr [filename],0 mov ofn.nmaxfile,sizeof filename mov ofn.flags,ofn_filemustexist or ofn_hidereadonly or ofn_pathmustexist invoke getopenfilename,addr ofn .if eax!=0 invoke createfile,addr filename,generic_read,file_share_read,null,open_existing,file_attribute_normal,0 .if eax!=invalid_handle_value mov hfile,eax ;================================================================ ; stream the text into the richedit control ;================================================================ mov editstream.dwcookie,eax mov editstream.pfncallback,offset streaminproc invoke sendmessage,hwndrichedit,em_streamin,sf_text,addr editstream ;========================================================== ; initialize the modify state to false ;========================================================== invoke sendmessage,hwndrichedit,em_setmodify,false,0 invoke closehandle,hfile mov fileopened,true .else invoke messagebox,hwnd,addr openfilefail,addr appname,mb_ok or mb_iconerror .endif .endif .elseif ax==idm_close invoke checkmodifystate,hwnd .if eax==true invoke setwindowtext,hwndrichedit,0 mov fileopened,false .endif .elseif ax==idm_save invoke createfile,addr filename,generic_write,file_share_read,null,create_always,file_attribute_normal,0 .if eax!=invalid_handle_value @@: mov hfile,eax ;================================================================ ; stream the text to the file ;================================================================ mov editstream.dwcookie,eax mov editstream.pfncallback,offset streamoutproc invoke sendmessage,hwndrichedit,em_streamout,sf_text,addr editstream ;========================================================== ; initialize the modify state to false ;========================================================== invoke sendmessage,hwndrichedit,em_setmodify,false,0 invoke closehandle,hfile .else invoke messagebox,hwnd,addr openfilefail,addr appname,mb_ok or mb_iconerror .endif .elseif ax==idm_copy invoke sendmessage,hwndrichedit,wm_copy,0,0 .elseif ax==idm_cut invoke sendmessage,hwndrichedit,wm_cut,0,0 .elseif ax==idm_paste invoke sendmessage,hwndrichedit,wm_paste,0,0 .elseif ax==idm_delete invoke sendmessage,hwndrichedit,em_replacesel,true,0 .elseif ax==idm_selectall mov chrg.cpmin,0 mov chrg.cpmax,-1 invoke sendmessage,hwndrichedit,em_exsetsel,0,addr chrg .elseif ax==idm_undo invoke sendmessage,hwndrichedit,em_undo,0,0 .elseif ax==idm_redo invoke sendmessage,hwndrichedit,em_redo,0,0 .elseif ax==idm_option invoke dialogboxparam,hinstance,idd_optiondlg,hwnd,addr optionproc,0 .elseif ax==idm_saveas invoke rtlzeromemory,addr ofn,sizeof ofn mov ofn.lstructsize,sizeof ofn push hwnd pop ofn.hwndowner push hinstance pop ofn.hinstance mov ofn.lpstrfilter,offset asmfilterstring mov ofn.lpstrfile,offset alternatefilename mov byte ptr [alternatefilename],0 mov ofn.nmaxfile,sizeof alternatefilename mov ofn.flags,ofn_filemustexist or ofn_hidereadonly or o