Search code examples
c++parameterswxwidgets

Textfield - what is wxTextCtrlNameStr?


Question

I'm trying to create a basic wxWidgets program with a text entry box, in the constructor there is a variable wxTextCtrlNameStr - in researching I can't seem to find wxTextCtrlNameStr? any help?

Given Code documentation:

wxTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = "", const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr)

My Code:

MainFrame::MainFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{
 wxButton * Centigrade = new wxButton(this, 
                                      BUTTON_CENTIGRADE, 
                                      _T("to Centigrade"), 
                                      wxPoint(20, 20), 
                                      wxDefaultSize, 
                                      0);
 wxButton * Fahrenheit = new wxButton(this, 
                                      BUTTON_FAHRENHEIT, 
                                      _T("to Fahrenheit"), 
                                      wxPoint(20, 40), 
                                      wxDefaultSize, 
                                      0);

 F_txt = new wxTextCtrl(this, 
         TXT_F_Main, 
         "0", 
         wxDefaultPosition, 
         wxDefaultSize, 
         wxDefaultValidator, 
         wxTextCtrlNameStr);  /***********************************************/
 C_txt = new wxTextCtrl(this, 
         TXT_C_Main, 
         "0", 
         wxDefaultPosition, 
         wxDefaultSize, 
         wxDefaultValidator, 
         wxTextCtrlNameStr);  /***********************************************/

... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 

Solution

  • It's the name of the window. By default wxTextCtrlNameStr might be simply "text".

    You probably don't need it, but it gives you an alternative way to identify widgets.

    For example it allows you to find a Window or Widget if you know the name it was given when created: wxWindow::FindWindowByName

    Note that the argument has a default. If you are not going to use window names, just don't pass anything, as you don't pass the name to wxButton constructor (defaults to "button").