WndProc
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Windows messages are floating all around your application, but only by referencing WndProc can you allow your application to access the wealth of information stored within them.
Contents |
Basics
The best way to start finding out about them is just by printing out each message to Debug. Even if you application doesn’t have focus Debug still lists any actions performed.
Example
using System; using System.Windows.Forms; using System.Diagnostics; namespace messages { public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void WndProc(ref Message m) { Debug.WriteLine(m); base.WndProc(ref m); } } }
The Details
WM_DEVICECHANGE - 0x0219
With this message you can detect when a user adds a new USB device. Be careful though as this message can be sent out several times depending on what device is added.
[edit]DBT_DEVICEARRIVAL - 0x8000
This message will only be sent out once the device has been installed by Windows.
Note: This message may not be sent so don't rely on this.
[edit]DBT_DEVICEREMOVECOMPLETE - 0x8004
This message will only be sent out once the device has been powered down or removed from the computer.
Note: This message may not be sent so don't rely on this.