From: Landon on
I have a form with 3 CEdit which are Year, Month and Day fields.

If one of them is empty and user click OK or press Enter, an error message
will displayed and the focus will back on where it was.

I have tried this code but it won't focused back on where it was, it just
back to the form but nothing is focused.

void CMochikoshiDlg::OnOK()
{
// TODO: この位置にその他の検証用のコードを追加してください
if ( m_edt_mochi_date_year.IsEmpty() || m_edt_mochi_date_month.IsEmpty() ||
m_edt_mochi_date_day.IsEmpty() ) {
MessageBox( "Error" );
return;
}
CDialog::OnOK();
}

How to do that?

Thank you very much.
From: robert on
You can use GetDlgItem to get the edit box by its id, then call SetFocus on
it.
Another way is that you can utilize dynamic data exchange of MFC to check if
the data of one control is valid.

Thanks
Robert

"Landon" <Landon(a)discussions.microsoft.com> д����Ϣ����:9B3F8997-1FC9-4722-9CC7-40EF4EA76E63(a)microsoft.com...
>I have a form with 3 CEdit which are Year, Month and Day fields.
>
> If one of them is empty and user click OK or press Enter, an error message
> will displayed and the focus will back on where it was.
>
> I have tried this code but it won't focused back on where it was, it just
> back to the form but nothing is focused.
>
> void CMochikoshiDlg::OnOK()
> {
> // TODO: ����λ�äˤ�����Η��^�äΥ��`�ɤ�׷�Ӥ��Ƥ��$���
> if ( m_edt_mochi_date_year.IsEmpty() || m_edt_mochi_date_month.IsEmpty()
> ||
> m_edt_mochi_date_day.IsEmpty() ) {
> MessageBox( "Error" );
> return;
> }
> CDialog::OnOK();
> }
>
> How to do that?
>
> Thank you very much.


From: Landon on
> You can use GetDlgItem to get the edit box by its id, then call SetFocus on
> it.
> Another way is that you can utilize dynamic data exchange of MFC to check if
> the data of one control is valid.
>
> Thanks
> Robert

Will it focus to the right CEdit control? I mean if there are 5 CEdit for
example, when I was on the 3rd CEdit, I click OK or Enter then it should be
back to CEdit number 3 right? Does the GetDlgItem make this possible?

Thank you very much.
From: robert on
Maybe you don't need to check its data until you click the OK button, and do
that when the control lost the focus.
This is some part of the idea of DDX.
Otherwise, you need to save the last control with focus, right?

"Landon" <Landon(a)discussions.microsoft.com> д����Ϣ����:AF41CFE3-F595-4552-BD53-3CCA204664CA(a)microsoft.com...
>> You can use GetDlgItem to get the edit box by its id, then call SetFocus
>> on
>> it.
>> Another way is that you can utilize dynamic data exchange of MFC to check
>> if
>> the data of one control is valid.
>>
>> Thanks
>> Robert
>
> Will it focus to the right CEdit control? I mean if there are 5 CEdit for
> example, when I was on the 3rd CEdit, I click OK or Enter then it should
> be
> back to CEdit number 3 right? Does the GetDlgItem make this possible?
>
> Thank you very much.


From: Landon on
"robert" wrote:

> Maybe you don't need to check its data until you click the OK button, and do
> that when the control lost the focus.
> This is some part of the idea of DDX.
> Otherwise, you need to save the last control with focus, right?

I don't understand with your explanation above, can you be more specific?

According to you, how is the best way to solve my problem?

Thank you very much.