我试过以下几个教程似乎有麻烦。Directx设备不初始化为窗口,程序挂起
我有一个现有的程序,我试图添加一个directx窗口作为一个额外的弹出式论坛,将作为一个孩子运行到主应用程序的形式。
下面是Windows窗体类:
public partial class DxWindow : Form
{
Device device;
public DxWindow()
{
InitializeComponent();
initDevice();
}
private void initDevice()
{
MessageBox.Show("hello");
PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
{
//render stuff
}
private void DxWindow_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
这里是我初始化形式(从主窗口中的UI按钮)
private void toolStripButton3_Click_1(object sender, EventArgs e)
{
if (DirectxWindow == null)
{
DirectxWindow = new DxWindow();
DirectxWindow.Show();
}
}
当我运行该程序,然后点击按钮。它似乎创造了记忆中的形式,但从来没有出现。当我在调试器中遍历它时,它会转到“DirectxWindow = new DxWindow();”然后自动跳出中断模式并继续在主窗口冻结并且没有新的Dxwindow()的情况下运行。
当我打破执行似乎仍然是“DirectxWindow = new DxWindow();”
此外,“MessageBox.Show(”hello“);”在DxWindow构造函数没有被调用”
编辑:我推断,只要它击中‘PresentParameters PP =新Microsoft.DirectX.Direct3D.PresentParameters();’应用程序,而不引发任何错误,不响应