Discussion of article "Graphical Interfaces VI: the Checkbox Control, the Edit Control and their Mixed Types (Chapter 1)" - page 2

 
Thomas Schwabhäuser:

...

Thanks for the tip!

I will add this capability. Watch for updates future articles in this series.

 

in your examples there is always output id, lparam, dparam, sparam.

   if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)

     {

      ::Print(__FUNCTION__," > id: ",id,"; lparam: ",lparam,"; dparam: ",dparam,"; sparam: ",sparam);

      //Print(m_spin_edit1.GetValue());

     }

we get the following

TestLibrary (NZDUSD,H1) CProgram::OnEvent > id: 1020; lparam: 12; dparam: -1.0; sparam: Spin Edit 1:

id - element identifier

lparam - ?

dparam - ?

sparam - element name

we are considering an input field - of course it is interesting to get the entered value, how to do it as fast as possible?

 
Pavel Kolchin:

in your examples there is always id, lparam, dparam, sparam output.

...

id - element identifier

lparam - ?

dparam - ?

sparam - element name

Controls generate messages and parameters in most cases mean the following:

  • id - event identifier.
  • lparam - element identifier.
  • dparam - element index.
  • sparam - displayed text specified by the library user (element name).

I will prepare later a table showing the set of event parameters from each element.

Pavel Kolchin:

...

we consider an input field - of course it is interesting to get the entered value, how to do it as fast as possible?

Just using the CSpinEdit::GetValue() method you can get the current value in the input field.

Example:

//--- An event from the input field has arrived
   if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
     {
      //--- If the item ID is from the first input field
      if(lparam==m_spin_edit1.Id())
        {
         //--- Output its value
         Print("m_spin_edit1.GetValue(): ",m_spin_edit1.GetValue());
        }
      //---
      return;
     }
 
And if we don't know the name or we have a hundred fields, maybe there is a method by id to see what is there or something like this.GetValue()
 
Pavel Kolchin:
And if we don't know the name or we have a hundred fields, maybe there is a method by id to see what is there or something like this.GetValue().
So each element has its own unique element id.
 
Anatoli Kazharski:
So each element has its own unique element identifier.


if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{

   if(lparam==m_spin_edit1.Id()){Print(m_spin_edit1.GetValue());}

   if(lparam==m_spin_edit2.Id()){Print(m_spin_edit2.GetValue());}

   if(lparam==m_spin_edit3.Id()){Print(m_spin_edit3.GetValue());}

   if(lparam==m_spin_edit4.Id()){Print(m_spin_edit4.GetValue());}

   if(lparam==m_spin_edit5.Id()){Print(m_spin_edit5.GetValue());}

   if(lparam==m_spin_edit6.Id()){Print(m_spin_edit6.GetValue());}

   if(lparam==m_spin_edit7.Id()){Print(m_spin_edit7.GetValue());}

   if(lparam==m_spin_edit8.Id()){Print(m_spin_edit8.GetValue());}

   if(lparam==m_spin_edit9.Id()){Print(m_spin_edit9.GetValue());}

   ...

}

I meant not to write such code, maybe it makes sense to do it.

if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{

    Print(GetValue(lparam));

   или

   Print(this.GetValue());

}

but I don't have a lot of fields, the first option is fine for me.

 

Pavel Kolchin:

...

I meant not to write such code, maybe it makes sense to do it.

if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{

    Print(GetValue(lparam));

   или

   Print(this.GetValue());

}

I don't have a solution yet how to do it for all get-methods of all elements. But I will think about it.
 
//+------------------------------------------------------------------+
//| ChartEvent function|
//+------------------------------------------------------------------+
void OnChartEvent(const int    id,
                  const long   &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   program.ChartEvent(id,lparam,dparam,sparam);
   if(lparam==program.m_checkbox.Id())
      if(program.m_checkbox.CheckButtonState())
        {
         program.m_checkbox.LabelColor(clrGreen);
        }
   else
     {
      program.m_checkbox.LabelColor(clrRed);
     }
  }
//+------------------------------------------------------------------+
Simple task. Change the colour of the checkbox label when clicking on the checkbox. Ticked - green text, unchecked - red. It doesn't work. Unchecked it becomes blue, ticked it is still blue.
 

Alexander Fedosov:

Simple task. Change the colour of the checkbox label when clicking on the checkbox. Ticked - green text, unchecked - red. It doesn't work. Unchecked it becomes blue, ticked it is still blue.

Now you can set colours for different states only before the item is installed(example below):

//+------------------------------------------------------------------+
//|| Creates checkbox 1|
//+------------------------------------------------------------------+
bool CProgram::CreateCheckBox1(const int x_gap,const int y_gap,string text)
  {
//--- Save the window pointer
   m_checkbox1.WindowPointer(m_window1);
//--- Set properties before creation
   m_checkbox1.XSize(90);
   m_checkbox1.YSize(18);
   m_checkbox1.LabelColor(clrGreen);
   m_checkbox1.LabelColorOff(clrRed);
   m_checkbox1.LabelColorHover(clrCornflowerBlue);
   m_checkbox1.LabelColorLocked(clrSilver);

//--- Create a control
   if(!m_checkbox1.CreateCheckBox(m_chart_id,m_subwin,text,x_gap,y_gap))
      return(false);
//--- Add the object to the common array of object groups
   CWndContainer::AddToElementsArray(0,m_checkbox1);
   return(true);
  }
 
Alexander Fedosov:
//+------------------------------------------------------------------+
//| ChartEvent function|
//+------------------------------------------------------------------+
void OnChartEvent(const int    id,
                  const long   &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   program.ChartEvent(id,lparam,dparam,sparam);
   if(lparam==program.m_checkbox.Id())
      if(program.m_checkbox.CheckButtonState())
        {
         program.m_checkbox.LabelColor(clrGreen);
        }
   else
     {
      program.m_checkbox.LabelColor(clrRed);
     }
  }
//+------------------------------------------------------------------+
Simple task. Change the colour of the checkbox label when clicking on the checkbox. Ticked - green text, unchecked - red. It doesn't work. Unchecked it becomes blue, ticked it is still blue.

How about this?

   if(lparam==program.m_checkbox.Id())
     {
      if(program.m_checkbox.CheckButtonState()) program.m_checkbox.LabelColor(clrGreen);
      else program.m_checkbox.LabelColor(clrRed);
     }