#code=936

SET &EM_SETLIMITTEXT=0x00C5
SET &WM_COMMAND=0x0111
SET &EN_CHANGE=0x0300

WIN1
_SUB WIN1,W344H249,测试字符数,

    EDIT -vcenter &EDIT1,L75T50W161H30,汉字,,  //字符数
    CALL SetLimitText  &EDIT1   4
    
    SET &EDIT2_V=汉字
    EDIT -vcenter &EDIT2,L75T90W161H30,%&EDIT2_V%,,   //字节数
    SET &maxEDIT2=4

    ENVI @&EDIT2.ID=?;&&EDIT2_ID
    CALC -base=16 #&&EDIT2_CHANGE=%&EN_CHANGE% * 0x10000  + %&EDIT2_ID%   //低16位，控件ID   //高16位,操作码
    ENVI @this.MSG=_%&WM_COMMAND%::&&wp,&&lp, CALL OnCommand   //捕捉内容改变

_END

_SUB OnCommand 
    IFEX $%EDIT2_CHANGE%=%&wp%,  CALL OnEDIT2_CHANGE
_END

_SUB OnEDIT2_CHANGE 
    STRL -m &&len=%&EDIT2%
    IFEX $%&len%>%&maxEDIT2%, ENVI @&EDIT2=%&EDIT2_V%!  SET EDIT2_V=%&EDIT2%
_END


//SetLimitText 控件名 字符数
//设置EDIT MEMO 最大字符数
_SUB SetLimitText
     ENVI @%1.ID=?&&CWid
     ENVI @@SENDMSG=%&CWid%:%&EM_SETLIMITTEXT%;%2
_END

