(私は VS++2005 を使用しています)
ダイアログにエディット ボックス コントロール (ID - を使用ID_edit_box
) を配置し、(ハンドラー ウィザードを使用して) コントロール ( ) 変数c_editbox
と値 ( v_editbox
) 変数の 2 つの変数を関連付けます。また、ハンドラー関数OnEnChangeedit_box
をその編集ボックス コントロールに関連付けます。編集ボックスに数字を 1 つだけ入力するとします。その数字は 0 または 1 です。他の値を入力すると、その編集ボックスの内容が自動的にクリアされ、ユーザーが何でも入力します (つまり、ユーザーは編集ボックスに 0/1 以外は入力できません)。私はそのチェックインonEnChangeedit_box
機能を行います。コードは次のとおりです。
void CSDRDlg::OnEnChangeedit_box()
{
CWnd* pWnd;
CString edit_box_temp;
pWnd = GetDlgItem(ID_edit_box);
pWnd->GetWindowText(edit_box_temp);
if ((edit_box_temp == "0" || edit_box_temp == "1")
{...do something - i.e. setfocus on some other edit box }
else
{
pWnd->SetWindowText(""); // clear the content of edit box
//... any other statement below will not be executed because the
//above line cause again call of this function
}
}
私はその行をデバッグして発見しました:pWnd->SetWindowText("");
この関数の制御内容を変更すると、彼女の呼び出しが再びトリガーされるため、無限ループが発生します。
しかし、上記のコードを次のように変更します。
void CSDRDlg::OnEnChangeedit_box()
{
UpdateData(TRUE);
if ((v_editbox == "0" || v_editbox== "1")
{...do something - i.e. setfocus on some other edit box }
else
{
v_editbox = "";
UpdateData(FALSE);
}
}
それは私が望むように機能しますが、私たちが電話するときに誰かが理由を説明できますか
v_editbox = "";
UpdateData(FALSE);
それは無限ループを引き起こしません。