Windows Forms & Panda3D


I was wondering if it is possible to use Windows Forms with Panda3D (I am not using python but C++).

I found a forum thread where someone else asked a similar question but It didn’t make much sense to me.
(for reference : [url]C# Window Form and Panda3D] )

I have created “myForm” (via form designer of VS2008)
and now I would like to reparent the panda3d window to my newly created form.

I had a look at the WindowsProperties class and in particular the Set_parent_window function which takes a WindowHandle* .
How do I convert my IntPtr (managed c++) which is a widows handle to “myForm” into a WindowHandle* (Panda3D) ?

Also would I be interested to hear your general thoughts about using Windows Forms as container for Panda3D.

something likethis :


You can use:

PT(WindowHandle) wh = NativeWindowHandle::make_win(my_hwnd);

to convert your HWND windows handle to a Panda WindowHandle.

More simply, you can use the version of WindowProperties::set_parent_window() that receives a size_t instead of a WindowHandle pointer, and cast your pointer to size_t:



thanks that worked! :slight_smile:

			//TODO: Add the constructor code here

			int argc = 0;
			char** argv = NULL;
			theFramework.open_framework(argc, argv);

			WindowProperties props;
			props.set_title("Panda Test...");
			props.set_size(this->Size.Width, this->Size.Height);

			IntPtr my_hwnd = this->Handle;

			theFramework.open_window(props, NULL , NULL);


now I tried to resize the window when i resize Form1.

This is the OnResize event of Form1…

		virtual System::Void OnResize(System::EventArgs ^ e) override

			WindowProperties props;

			props.set_size(this->Size.Width, this->Size.Height);
			//and now ??


but I am not sure how to set the new size of the panda window.
I have also seen there is somethig in PandaFramework to use
event_window_event ? Any hints ?

Actually I just realised theFramework.get_default_window_props(props); does not do the desired effect (getting the actualy windows properties i had setup initially).
At this point I am conviced I am missing something somewhere either in PandaFramework or WindowFrameWork?

You resize the window by making a request, like this:

WindowProperties props;
props.set_size(this->Size.Width, this->Size.Height);


this doesnt seem to work, though I think I am still missing something.

here is where it fails

//     Function: GraphicsWindow::request_properties
//       Access: Published
//  Description: Requests a property change on the window.  For
//               example, use this method to request a window change
//               size or minimize or something.
//               The change is not made immediately; rather, the
//               request is saved and will be applied the next time
//               the window task is run (probably at the next frame).
void GraphicsWindow::
request_properties(const WindowProperties &requested_properties) {
  LightReMutexHolder holder(_properties_lock);

  if (!_has_size && _requested_properties.has_size()) {
    // If we just requested a particular size, anticipate that it will
    // stick.  This is helpful for the MultitexReducer, which needs to
    // know the size of the textures that it will be working with,
    // even if the texture hasn't been fully generated yet.
    _x_size = _requested_properties.get_x_size();
    _y_size = _requested_properties.get_y_size();

    // Don't set _has_size yet, because we don't really know yet.

it never passes that if statement.

also I wonder where I would add the theFramework.main_loop();

I think I need register it somehow to be executed by the Form.

It’s actually expected for it not to pass that if statement–that has nothing to do with the actual resizing of the window. That is handled in a sub-class, in WinGraphicsWindow::do_reshape_request(). However, note that the resize doesn’t happen immediately; it happens during the next frame, which means it won’t happen if you’re not calling the Panda loop. :slight_smile:


I wanted share my code with others who like me want to use Panda with Windows Forms. So I wrote a little test application with panda3d and managed C++ using windows forms.

hope it helps :slight_smile:

Features :

Screenshot :

and Source Code :

you will need to update the project with your own “standard” panda libraries, (the ones from the 1.7.0 SDK for example