Changing text in a second dialog window from a first window

Apr 30, 2011 at 6:10pm
I haven't been exposed to this before, but I have a need to be able to (using code::blocks and wxwidgets 2.8.11 by the way):

Have the main frame showing.
Display a second dialog wndow appear on top with some text.
Periodically change the text in the second window from actions behind
the scenes in functions that are running within the first frame class.

I've got the second window with text to appear on top of the first and
everything with some default text in a little sample program but I'm
not sure of the syntax to use when trying to change the StaticText
value in the second from the first somewhere.

So I just put in a timer in the first frame and when it stopped, I
tried changing the second window StaticText1 value but I get a compiler
error:

"24 : Object missing in reference to StartUpDialog::StaticText1"

Obviously I'm not understanding the syntax of implementing this
correctly, so I'm hoping a patient person out there can help (probably
Vadim as he's been patient with everyone so far lol).


Below is partial code from the second frame header file.

class StartupDialog: public wxDialog
{
public:
StartupDialog(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint&
pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
virtual ~StartupDialog();

//(*Declarations(StartupDialog)
wxButton* Button1;
wxStaticText* StaticText1;
wxTimer Timer1;
//*)
>

> StartupDialog::~StartupDialog()
> {
> //(*Destroy(StartupDialog)
> //*)
>
> }

Somewhere at top of my first frame main cpp I have

StartupDialog *SDialog = (StartupDialog *) NULL;

Here is some of the code from the second frame initialization main cpp (just to show
the initial text I put into the statictext1 at design time..

StartupDialog::StartupDialog(wxWindow* parent,wxWindowID id,const
wxPoint& pos,const wxSize& size)
{
//(*Initialize(StartupDialog)
Create(parent, id, _("Startup Status Progression"),
wxDefaultPosition, wxDefaultSize, wxSTAY_ON_TOP|wxCAPTION, _T("id"));
SetClientSize(wxSize(446,286));
Move(wxDefaultPosition);
Button1 = new wxButton(this, ID_BUTTON1, _("Label"),
wxPoint(264,224), wxDefaultSize, 0, wxDefaultValidator,
_T("ID_BUTTON1"));
StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("This is a lot
\nof text on\na couple of\nlines."), wxPoint(88,72),
wxSize(432,104), 0, _T("ID_STATICTEXT1"));
Timer1.SetOwner(this, ID_TIMER1);
Center();

Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,
(wxObjectEventFunction)&StartupDialog::OnButton1Click);
Connect(ID_TIMER1,wxEVT_TIMER,
(wxObjectEventFunction)&StartupDialog::OnTimer1Trigger);
//*)

}

Here's some code from the button click on the first frame
that I click when I want the second frame window to be created and
shown, plus enabling the timer I mentioned.

void StartupConfigParseFrame::OnButton2Click(wxCommandEvent& event)
{
StartupDialog* SDialog = new StartupDialog(this);
testflag = true;
Timer1.Start(5000,TRUE);
SDialog->ShowModal();
}


Below is the call from the timer event in the first frame code.

void StartupConfigParseFrame::OnTimer1Trigger(wxTimerEvent& event)
{
SDialog::StaticText1->SetLabel("changing text");

}

Once again, I'm hoping someone can show an example of how to change
the text in a second form from the first form/frame actions.
Topic archived. No new replies allowed.