0

我正在尝试将驱动器检测添加到我的程序中,但我遇到了一些困难。当我尝试使用此代码项目上指定的代码时。我目前正在为我的项目使用 Windows,但无法使其正常工作。

    namespace Project
    {
        public partial class MainWindow : Window
        {

        OTHER CODE 

        private const int WM_DEVICECHANGE = 0x219;

        protected override void WndProc(ref Message m)
        {

            switch (m.Msg)
            {
                case WM_DEVICECHANGE:
                    // The WParam value identifies what is occurring.
                    // n = (int)m.WParam;
                    break;
            }
            base.WndProc(m);
        }
        }      
    }

对于 WndProc,我需要使用 System.Windows.Forms;但我也有使用 System.Windows.Controls; 这给了我以下错误

是 'System.Windows.Controls.MenuItem' 和 'System.Windows.Forms.MenuItem' 之间的模棱两可的引用

对于 base.WndProc(m); 我收到错误:“System.Windows.Window”不包含“WndProc”的定义

和 protected override void WndProc(ref Message m) 给出错误:'Project.MainWindow.WndProc(ref System.Windows.Forms.Message)':找不到合适的方法来覆盖

我显然做错了什么,但不确定是什么

4

1 回答 1

2

我没有看到您的实际 MenuItem,但无论它在哪里,您都在引用 System.Windows.Controls 和 System.Windows.Forms,因此您必须澄清一下。在某处它会是这样的:

private MenuItem _mItem;

这将不得不改为:

private System.Windows.Forms.MenuItem _mItem;

(或 System.Windows.Control;尝试一个,看看它是否坏了!)

第二个错误可能是准确的:将 MainWindow 从从 Window 继承更改为从 System.Windows.Forms.Form 继承,看看是否可以修复它。或者,删除覆盖。System.Windows.Window 没有 WndProc 的方法是正确的,但 Form 确实...

于 2013-08-07T16:43:45.537 回答