How to retrieve individual controls from a wxFrame in wxPHP?

177 views Asked by At

I'm loading wxWidgets assets in a PHP program using wxXmlResource(). This loads the window very well, but I am not sure how to get an object reference to named window elements.

Here is my code:

// Load the window
$resource = new wxXmlResource();
$resource->InitAllHandlers();
$resource->Load(__DIR__ . '/forms.xrc.xml');

// Get a reference to a window
$frame = new wxFrame();
$resource->LoadFrame($frame, NULL, 'frmOne');
$frame->Show();

// Fetch a named element - the class returned is the base class
$textCtrl = $frame->FindWindow('m_staticText12');
echo get_class($textCtrl) . "\n";

The $textCtrl item should be a wxStaticText object but it has been returned as a wxWindow (which is a parent class). Since it is not cast as the correct object type, I can't call methods belonging to the control's own class (such as Wrap()).

I think the FindWindow() call is working, since if I get the name deliberately wrong, it returns null.

What am I doing wrong?

1

There are 1 answers

4
JGM On BEST ANSWER

You will need to use the wxDynamicCast function to cast object to proper type like:

$textCtrl = wxDynamicCast(
    $frame->FindWindow('m_staticText12'), 
    "wxStaticText"
);