Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MIDL
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 CButton.

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

}

C#
IsCorrect() is where user input is checked and compared with correct text.


The edit control is time driven and need to be disabled for a certain time before user can again click it.

Could it be possible that before display of control, cbutton is disabled and becomes enable once some text is input into edit control.
Waiting for suggestions.

Thanks in advance.
Posted

I believe what you are looking for is the .EnableWindow() method.

example:
MIDL
m_someControlVariable.EnableWindow(TRUE);

or
MIDL
m_someControlVariable.EnableWindow(FALSE);
 
Share this answer
 
OK, your question isn't all that clear to me. Let's see if I can sort it out.

You have a button and an edit control.

1) You want the button disabled when the edit control is empty, enabled otherwise.

2) You want the edit control disabled for some time period after the button is clicked.

You already know how to enable/disable a control.

For #2 you will want to use a timer. Here[^] is some information.

For #1, it sounds to me like you already know about CEdit's ON_EN_CHANGE message handler. You would derive a new class from CEdit implementing such a message handler and include it in the message map for that class.

You would then use an instance of that class for your edit control. How you do that depends on how you are creating the control in the first place.

To check if the edit control is empty, have you considered using CWnd::GetWindowText[^] or CWnd::GetWindowTextLength[^] ?
 
Share this answer
 
@kinar
I know this method but I want to bind it with some control like ONEnUpdate() or ONEnChange() where I can use some if statement like

<br />
if (str!="")<br />
{<br />
m_an.EnableWindow(TRUE)<br />
}<br />
else<br />
{
 
Share this answer
 
@Avi

Let me clear few things to give you a better idea. Run() is the function on which all other functions are depending. In one cycle of 100 iterations, a text is shown by Run() and is checked by Check() and compared with user input by IsCorrect(s) and all this is happening within OnBtClicked() till 100 iterations are completed.

Within IsCorrect() I have strcmpare(CString, CString) function that takes both strings and returns a float value depeneding on which the input is either marked corect or incorrect.

What I want is:
to disable the Cbutton when user interface is loaded before the start of 1st iteration and enable it when there is some text in edit contrl.

In message map, I have the entry

ON_BN_CLICKED(IDC_IT_START, &CIT::OnBnClickedStart)
// loads the ui

ON_EN_UPDATE(C_IT_ANS, &CIT::OnEnUpdateBt())


and I want to use this edit contrl for enabl/disble Cbutton.

C#
void CIT::OnEnUpdateBt()
{

 if(str!="")
        {
            m_record.EnableWindow(TRUE);

        }


}


But this control doesn't get activated the way as is desired.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900