我想做两个EDIT控件,分别表示用户名和密码,然后再用INI文件来存取用户名和密码..
每当程序运行时就去读INI文件.点击BUTTON来判断输入的用户名和密码是否与INI的用户名及密码一致,如是则返回TRUE否则返回False,请给个实例好吗?
这样方便用户修改用户名和密码..谢

解决方案 »

  1.   

    调用WIN API的ini文件读写函数
      

  2.   

    INI File Functions
    MSLU supports Unicode versions of the following INI file functions.
    GetPrivateProfileInt
    GetPrivateProfileSection
    GetPrivateProfileSectionNames
    GetPrivateProfileString
    GetPrivateProfileStruct
    GetProfileInt
    GetProfileSection
    GetProfileString
    WritePrivateProfileSection
    WritePrivateProfileString
    WritePrivateProfileStruct
    WriteProfileSection
    WriteProfileString
      

  3.   

    放两个控件并关联变量,控件型m_username
    m_password在OnInitDialog中char buf[ 200 ] = "";
    GetPrivateProfileString( "AAA", "name", "", buf, sizeof( buf ), "c:\\a.ini" );
    m_username.SetWindowText( buf );对于m_password也是这样。
      

  4.   

    这样也不行呀,我试了一下出现了一个错误C:\Documents and Settings\Administrator\桌面\Test\TestDlg.cpp(125) : error C2039: 'SetWindowTextA' : is not a member of 'CString'
            c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'其它功能未验证过,,
      

  5.   

    支持4楼的说法。
    楼上不对的原因是因为你将Edit控件的关联变量设置成了CString型。 改为Control
      

  6.   

    不好意思,,可能意思弄错了..我是想用户去输入用户名和密码,然后再判断用户输入的用户名和密码是否OK...密码和用户名存储在INI文件中INI文件如下
    [Password1]
    username=abc
    password=123
      

  7.   

    那你得到CEdit控件的数据,和你ini文件的数据比对一下,不就可以了吗?
      

  8.   

    使用GetPrivateProfileString 获取INI中的用户名和密码,使用CString成员Compare比较不久完了。
      

  9.   

    //你只是进行用户名和密码的验证,所以只需要读ini文件就行,假设ini文件(PASSWORD.INI)的内容如下
    [Administrator]
        Username = wxj
        Password = wxj//在登录对话框的确认按钮响应函数中:(以验证密码为例,验证用户名同理)
    UpdateData(true);
    CString  strPasswordTemp;GetPrivateProfileString("Administrator","Password",NULL,
    strPasswordTemp.GetBuffer(50),50,".\\PASSWORD.INI");
    if(m_strpassword != strPasswordTemp)  //m_strpassword为密码编辑框关联的CString变量
    {
        MessageBox("密码错误,请重新输入!   ","登录对话框",0);
        m_strpassword = "";
        UpdateData(false);
        m_editpassword.SetFocus();
    }
    else
        OnOK();