Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / some advice on structuring my program

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. some advice on structuring my program
#4983
Posted by: 2004-08-14 01:57:26
Hello,

  I'm relatively new to wxWindows, and experienced in C++.  I'm trying to build a simple data entry program. The basic idea is that the window (a wxDialog, newProgramDlg ) will have a series of wxCheckBox's and wxTextCtrl's.  I want each CheckBox to be associated with a single TextCtrl, so that we only try and read the data if the check box is true (thus the user can choose which fields to input).  I plan on having numFIELDS = 5 say, (TextCtrl,CheckBox) pairs.

My initial code:
 
void newProgramDlg::CreateGUIControls(int numFields )
{
  this->SetTitle(wxString("new Program Dialog")); 
  this->Center();
  this->SetIcon(wxNullIcon);

  wxFlexGridSizer *dialogSizer = new wxFlexGridSizer(2, 1, 10, 10);
  for( int i = 0; i < numFields; i++ ){
    wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
    button_sizer->Add(new wxCheckBox(this, pow( 2, i ),myNames[i] ), 0, wxALL );
    button_sizer->Add(new wxTextCtrl(this, pow(2,i+numFields)), 0, wxALL);
         dialogSizer->Add( button_sizer, 0, wxALIGN_CENTER );
  }

  SetSizer(dialogSizer);
  SetAutoLayout(TRUE);
  dialogSizer->Fit(this );
  dialogSizer->SetSizeHints( this );   
}


Question 1:  I'm currently using a binary coding (2^i or 2^(i+numFields)) to associate each CheckBox with a TextCtrl so that I can access them later through
newProgramDlg::FindWindow.  Is there an easier or more straightforward way to do this.

Question 2:  Eventually I want to add some buttons.  If the user clicks on OK, I want to validate each field (make sure it is a number in the proper range, I already built the validator).  If all fields are valid, I want to return the values for those fields to the parent window and close the window.  Otherwise, I want to keep the window on the screen and highlight the invalid fields.

How do I return these values to the parent window?  Do I need to add a reference to an array in the newProgramDlg constructor? 

Question 3:  How will the parent window know when it's child closes?  Is there some type of event it should catch?

Sorry if these questions are really basic, like I said, I'm just getting started.
Thanks in advance for any help.

Message2. Re: some advice on structuring my program
#5019
Posted by: upCASE 2004-08-25 18:20:33
Hi!
I answered this posting at http://forum.upcase.de ;)
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Tue 2022-11-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0