yawnobleix
yawnobleix

Reputation: 1342

trouble making drive insertion detection c#

I am trying to add drive detection to my program but I am having a bit of difficulty. When I try to use the code specified on this code project. I am currently using windows for my project and I am having trouble getting it working.

    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);
        }
        }      
    }

For WndProc I need to have using System.Windows.Forms; but I also have using System.Windows.Controls; which gives me the following error

is an ambiguous reference between 'System.Windows.Controls.MenuItem' and 'System.Windows.Forms.MenuItem'

For base.WndProc(m); I get the error:'System.Windows.Window' does not contain a definition for 'WndProc'

and protected override void WndProc(ref Message m) gives the error: 'Project.MainWindow.WndProc(ref System.Windows.Forms.Message)': no suitable method found to override

I am clearly doing something really wrong but not sure what

Upvotes: 0

Views: 303

Answers (1)

Mike D.
Mike D.

Reputation: 391

I'm not seeing your actual MenuItem, but wherever it is, you're referencing both System.Windows.Controls and System.Windows.Forms, and so you'll have to clarify. Somewhere it's going to be something like:

private MenuItem _mItem;

And that'll have to change to:

private System.Windows.Forms.MenuItem _mItem;

(or System.Windows.Control; try one and see if it breaks!)

The second error is probably accurate: change MainWindow from inheriting from Window to inheriting from System.Windows.Forms.Form and see if that fixes it. Alternately, remove the override. It's correct that System.Windows.Window has no method for WndProc, but Form does...

Upvotes: 2

Related Questions