2016-03-05 36 views
0

我试过以下几个教程似乎有麻烦。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();’应用程序,而不引发任何错误,不响应

回答

0

原来我的问题是需要在 “App.config中” 文件使用

<startup useLegacyV2RuntimeActivationPolicy="true"> 

解决方案在这里找到:Mixed mode assembly is built against version 'v1.1.4322'

虽然我从来没有得到OP所述的错误。我只是有这个问题,如评论中所述: “谢谢!!!!这是我遇到过的最奇怪的问题在VS 2012 .Net 4.0中,我的应用程序只会暂停我初始化任何类型的变量与这个DLL相关的,我从来没有见过这样的东西,直到我找到这个,才发现有关这个问题的任何信息!“ - Quinxy von Besiex