下面的函数从文件中加载 2 个字符串:
int loadsettings()
{
wstring a,b;
int retrn = 1;
wfstream myFile;
myFile.open ("settings.txt");
if ((!myFile.is_open())||(myFile.fail()))
MessageBox(NULL, "Error openning settings file!", "Error", MB_ICONINFORMATION);
else
{
if(myFile.fail())
{
myFile.close();
myFile.clear();
retrn = 0;
savedefault(); //creates a settings.txt with default values
myFile.open ("settings.txt", ios::in);
}
myFile >> b; //b becomes "user"
myFile >> a; // a becomes "password"
user = (LPARAM)b.c_str();
password = (LPARAM)a.c_str();
SendMessage(hEdit,
WM_SETTEXT,
NULL,
user); // sets the text box to "u"
SendMessage(hEdit2,
WM_SETTEXT,
NULL,
password); //sets the text box to "p"
myFile.close();
}
return retrn;
}
我想将从文件中取出的两个字符串转到文本框 hEdit 和 hEdit2。尝试使用 Sendmessage settext 来做到这一点。但只有字符串中的第一个字符到达那里。我应该怎么办?