Hi;

I have an edit control that takes string input from user and a CButton 'Record' to record that input. I want to catch the control and disable it when the user input is empty. I want to make sure that this enable/diable happens with the click of Record CButton.

void CCTRL::OnBnClickedAns() // code for Cbutton
{
	CString txt;
	
	if(!end)
	{
	    IsCorrect(s); // comparing and checking user input 
	    m_input.SetCheck(0);
	    if(Check())
	    Run();
		
	}
	
}

* IsCorrect() is where user input is checked and compard with correct text.

Can I use OnEnUpdateAns() control to achieve it. e.g.

vodi CCTRL::OnEnUpdateAns() 
{

if (txt!="")
 {
m_rec.EnableWindow(TRUE);
 }
else
 {
if (txt=="")
 {
m_rec.EnableWindow(FALSE);
}

Any suggestions to get this done or if you have some otehr idea, kindly share.

hi,

void CCTRL::OnBnClickedAns()
{
       UpdateData(TRUE); // 1. Bind control and data

       // Check string associated with your Edit Box is empty or not
       if(m_strEdit == "")
       {
               // If yes then disable the control
               GetDlgItem(IDC_ID_EDITBOX)->EnableWindow(FALSE);
       }
    
       UpdateData(FALSE);       
}

How about another approach where some functionality is enabled only when there is some user input? Maybe this would suit you better, if not, just discard this post.

Anyways, that would look like ..

// in message map ..
ON_EN_UPDATE(IDC_EDIT_CTRL,  OnUpdateEdit)

// Handler for EN_UPDATE
void someDialog::OnUpdateEdit() 
{
    // m_button - a member variable of type CButton
    // m_edit -  a member variable of type CEdit

    // toggle the window's state based on whether there is
    // any user input at all in the edit control ...
    m_button.EnableWindow(m_edit.GetWindowTextLength());
}

@mitrmkar & ashishchoure
Thanks a lot for your suggestions. But this didn't work for me. My problem is that I ask user to input for 30 times and this loop works with a timed control event, if there is an input, it will show either right or wrong input messages. If a user doesn't input anything, then he should be ask to input again for the same query/text again and I am not able to do this. OnBtnClickedAns() simply moves to the next query in this case.

If you have noticed the code I put.
if(!end)
{
IsCorrect(s); // comparing and checking user input
m_input.SetCheck(0);
if(Check())
Run();
}
Run() is the function which is retrieving data from a db and IsCorrect(s) is the one which compares correct txt with user input and this all happens in one click.

This article has been dead for over six months. Start a new discussion instead.