Click to See Complete Forum and Search --> : KILLFOCUS and CEdits


thomas hueckel
April 27th, 1999, 06:36 AM
I have a CDialog-derived dialog using CEdits. Now I want
to check the content of these CEdits BEFORE they lose
the focus.

Step 1:
I used the ON_EN_KILLFOCUS Message and two functions
OnICDKillFocus and OnDatumKillFocus.

Problem:
By going this way, the application is jumping between the
two MessageBoxes in the OnKill-functions, because the CEdit
which I want to check already lost the focus to the second
CEdit wich will be checked when I set the focus to the first
CEdit in the OnKill-function. (see code below)

Please see Step 2 below.


/* PatICDMask*/
class CPatICDMask : public CDialog
{
public:
CStatic Static_1;
CStatic Static_2;
CEdit ICD;
CEdit Datum;

CPatICDMask(CWnd *pParent=NULL);
~CPatICDMask();

DECLARE_MESSAGE_MAP()

BOOL PreTranslateMessage(MSG *msg);
void OnCancel();
BOOL OnInitDialog();
void OnDestroy();
void OnICDKillFocus();
void OnDatumKillFocus();
void DoDataExchange(CDataExchange *);
};

BEGIN_MESSAGE_MAP(CPatICDMask, CDialog)
ON_WM_DESTROY()
ON_EN_KILLFOCUS(ID_PATICDMASK_ICD, OnICDKillFocus)
ON_EN_KILLFOCUS(ID_PATICDMASK_DATUM, OnDatumKillFocus)
END_MESSAGE_MAP()
.
.
.
void CPatICDMask::OnICDKillFocus()
{
char str[128];

ICD.GetWindowText(str, 128);
if( //check content of str )
{
AfxMessageBox("ICD falsch !"); // wrong ICD
ICD.SetFocus();
}
}

void CPatICDMask::OnDatumKillFocus()
{
char str[128];

Datum.GetWindowText(str, 128);
if( //check content of str )
{
AfxMessageBox("Datum falsch !"); // wrong date
Datum.SetFocus();
}
}




Step 2:
So I tried a second way. I modified the PreTranslateMessage
of the dialog to catch the WM_KILLFOCUS message BEFORE the
CEdit loses the focus. But this doesn't work. Everything
else in the PreTranslateMessage works fine. (see code below)

Who can help ?

Thank you



BOOL CPatICDMask::PreTranslateMessage(MSG *msg)
{
if(msg->message == WM_KILLFOCUS)
{
switch(GetFocus()->GetDlgCtrlID())
{
case ID_PATICDMASK_ICD : //Here I want to check the content of ID_PATICDMASK_ICD
if(not ok)
{
ICD.SetFocus();
return -1;
}
break;
case ID_PATICDMASK_DATUM : //Here I want to check the content of ID_PATICDMASK_DATUM
if(not ok)
{
Datum.SetFocus();
return -1;
}
break;
}
}

if(msg->message == WM_KEYDOWN)
switch ( msg->wParam )
{
case VK_F1 : { GUIPatICDSuchen(this); //Search
return -1;
}
case VK_RETURN : { GUIPatICDMaskOK(this); // Check Return-Key
return -1;
}
case VK_DOWN : { msg->wParam = VK_TAB;
break;
}
case VK_UP : { PrevDlgCtrl();
return -1;
}
};

return CDialog::PreTranslateMessage(msg);
}