原来编辑框有密码属性,设置一个开关变量,当对话框启动时,如果开关变量为真,设置编辑框密码属性,否则取消,但是实现不了,大家有办法么?

解决方案 »

  1.   

    CWnd::ModifyStyle  Call this member function to modify a window's style. 
    BOOL ModifyStyle(
       DWORD dwRemove,
       DWORD dwAdd,
       UINT nFlags = 0 
    );
     
    Parameters
    dwRemove 
    Specifies window styles to be removed during style modification.dwAdd 
    Specifies window styles to be added during style modification.nFlags 
    Flags to be passed to SetWindowPos, or zero if SetWindowPos should not be called. The default is zero. See the Res section for a list of preset flags.Return Value
    Nonzero if style was successfully modified; otherwise, 0.Res
    Styles to be added or removed can be combined by using the bitwise OR (|) operator. See the topics Window Styles and CreateWindow in the Platform SDK for information about the available window styles.If nFlags is nonzero, ModifyStyle calls the Windows API function SetWindowPos and redraws the window by combining nFlags with the following four preset flags: SWP_NOSIZE   Retains the current size.SWP_NOMOVE   Retains the current position.SWP_NOZORDER   Retains the current Z order.SWP_NOACTIVATE   Does not activate the window.To modify a window's extended styles, see ModifyStyleEx.Note  
    For some styles in certain controls (the ES_READONLY style in the edit control, for example), ModifyStyle may not properly change the style because the control may need to perform special internal processing. In these cases, a corresponding message to change the style will be available (EM_SETREADONLY in the example mentioned).
     Example
      Copy Code 
    // This example adds the WS_CLIPCHILDREN style to the window.
    // No Styles are removed from the window.void CMyView::OnInitialUpdate()
    {
       CView::OnInitialUpdate();
       ModifyStyle(0, WS_CLIPCHILDREN);
    }
     
    你要的是这个:ES_PASSWORD   Displays all characters as an asterisk (*) as they are typed into the edit control. An application can use the SetPasswordChar member function to change the character that is displayed.
      

  2.   

    void CTestDialogDlg::OnRadio1() 
    {
    // TODO: Add your control notification handler code here
    m_bShowPassword = 0; // //m_password:编辑框控件
    m_password.SetPasswordChar(0); //取消密码显示
    //m_password.ModifyStyle(ES_PASSWORD,NULL); //这句好像不要也行
    m_password.Invalidate(); //这句必需
    }void CTestDialogDlg::OnRadio2() 
    {
    // TODO: Add your control notification handler code here
    m_bShowPassword = 1; // //m_password:编辑框控件
    m_password.SetPasswordChar('X'); //密码显示
    //m_password.ModifyStyle(NULL,ES_PASSWORD); //这句好像不要也行
    m_password.Invalidate(); //这句必需
    }
      

  3.   

    其实就是显示,SetPasswordChar就可以了。