【问题标题】:trouble making drive insertion detection c#麻烦制作驱动器插入检测c#
【发布时间】:2013-08-07 16:36:54
【问题描述】:

我正在尝试将驱动器检测添加到我的程序中,但我遇到了一些困难。当我尝试使用此code project 上指定的代码时。我目前正在为我的项目使用 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)':找不到合适的方法来覆盖

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

【问题讨论】:

    标签: c# detection drive


    【解决方案1】:

    我没有看到您的实际 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 有...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-01
      • 2015-01-21
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      相关资源
      最近更新 更多