/ / Sendmessage settextでテキストボックステキストを設定すると、文字列win32の最初の文字のみが送信されます。c ++? - c ++、c、winapi、fstream

Sendmessage settextでテキストボックステキストを設定すると、文字列win32の最初の文字のみが送信されます。c ++? - c ++、c、winapi、fstream

以下の関数はファイルから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;
}

私は2つの弦をテキストボックスhEditとhEdit2に移動します。 Sendmessage settextを使ってそれを試みてください。しかし、文字列の最初の文字のみがそこに到着します。私は何をすべきか?

回答:

回答№1は0

Unicode文字列をANSIメソッドに送るため、文字が1文字しかないときはほとんど毎回です。
もう1つの方法は、ちょっとばかげた結果を示しています

  • ANSIサポートでコンパイルしたい場合

    uses string and not wstring

  • Unicodeサポートが必要な場合

    適切な場所(最上位のヘッダーまたはプロジェクトオプション)に必要な2定義済みのUnicodeサポートを追加する

    #define UNICODE // for windows api unicode
    #define _UNICODE // for libc unicode tchar and _TEXT macro...
    

    その後、 L"string" または _TEXT("string") あるいは _T("string") コード内の静的な文字列に変換します。