Issues with rendering into a splitcontainer

Started by
8 comments, last by exextatic 12 years, 3 months ago
Hi all,

Just trying to make an editor for my game. Im aiming to have directx render into a Split Container (C++ forms). I've managed to have it render into a picturebox, but moving it onto a split container panel has proved problematic. I also have an issue with some of the controls on the form rendering incorrectly (I've got a feeling its related to the directx renderer..?). Anyways, pictures will describe better:
dx_forms_error_1.PNG

And what it should look like (according to visual studio):
dx_forms_error_2.PNG

The DX renderer is initialized like this:
Form1(HINSTANCE hInstance)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//

WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hbrBackground = NULL;
wc.lpszClassName = L"WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL, L"WindowClass", NULL, WS_CHILD,
this->splitContainer3->Panel1->ClientRectangle.X, this->splitContainer3->Panel1->ClientRectangle.Y,
this->splitContainer3->Panel1->Width, this->splitContainer3->Panel1->Height,
(HWND)this->splitContainer3->Panel1->Handle.ToPointer(),
NULL,
hInstance,
NULL);

if(hWnd == NULL)
MessageBoxA(NULL, "Error in HWND!", "ERROR", MB_OK | MB_ICONEXCLAMATION);

ShowWindow(hWnd, SW_SHOW);

directxHandle = new DXHandler((HWND)this->splitContainer3->Panel1->Handle.ToPointer(), this->splitContainer3->Panel1->Size.Height, this->splitContainer3->Panel1->Size.Width);
HInstance = hInstance;
}


Thanks,
James Warner
Advertisement
You seem to be creating a new window, but then attaching your DXHandler class to the Panel's window rather than your new window.

You seem to be creating a new window, but then attaching your DXHandler class to the Panel's window rather than your new window.

Changing the initialiser to:
directxHandle = new DXHandler(hWnd, this->splitContainer3->Panel1->Size.Height, this->splitContainer3->Panel1->Size.Width);
Causes it to render into the whole panel, but when I got to resize it, the DX window doesnt resize.
dx_forms_error_3.PNG

Edit: Adding some code:
System::Void splitContainer3_Panel1_Resize(System::Object^ sender, System::EventArgs^ e)
{
if(directxHandle != NULL && directxHandle->getDevice() != NULL)
{
directxHandle->invalidateDeviceObjects();
directxHandle->updateBackBuffer(splitContainer3->Panel1->Width, splitContainer3->Panel1->Height);
directxHandle->restoreDeviceObjects();
}
}

And updateBackBuffer():
d3dpp.BackBufferWidth = LOWORD(lParam);
screenSize.x = LOWORD(lParam);
d3dpp.BackBufferHeight = HIWORD(lParam);
screenSize.y = HIWORD(lParam);

HRESULT hr = d3ddev->Reset(&d3dpp);

if(hr == D3DERR_INVALIDCALL)
{
MessageBox(NULL, L"Call to Reset() failed with D3DERR_INVALIDCALL! ",
L"ERROR", MB_OK | MB_ICONEXCLAMATION);
}
Bump, still have this issue. Waiting to get it resolved before I can move the code behind into its own DLL
You dont have to create a new window to render into it. Just passing the panels HWND to the device constructor should be enough.


directxHandle = new DXHandler(static_cast<HWND>(this->splitContainer3->Panel1->Handle.ToPointer()), this->splitContainer3->Panel1->Size.Height, this->splitContainer3->Panel1->Size.Width);

You dont have to create a new window to render into it. Just passing the panels HWND to the device constructor should be enough.


directxHandle = new DXHandler(static_cast<HWND>(this->splitContainer3->Panel1->Handle.ToPointer()), this->splitContainer3->Panel1->Size.Height, this->splitContainer3->Panel1->Size.Width);


Ok tried that, it seems to stop WM_PAINT being passed to windowproc (and in turn, stops rendering). When I resized the frame, it disappeared entirely (might also be related to WM_PAINT not being passed)
Try to Invalidate() or Refresh() the panel. Make sure proper rendering works before you move to resizing, since this will pose a heap of new issues that need to be solved.

Try to Invalidate() or Refresh() the panel. Make sure proper rendering works before you move to resizing, since this will pose a heap of new issues that need to be solved.

Iv managed to get it to render onto the panel with the help from MJP, but the only issue now is re-sizing the actual render (I would say backbuffer but im not sure thats the actual term).
Bump, still have this issue
Fixed - added a timer and set it to tick 60 times a second and used the code that DaftCode said to change

This topic is closed to new replies.

Advertisement