我試過以下幾個教程似乎有麻煩。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();’應用程序,而不引發任何錯誤,不響應