先看一段代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
namespace USBThief
{
public partial class Form1 : Form
{
Thread thread = null;
bool IsStop = false;
string Flag = string.Empty;
string Des = "D:\\MyStudy";
string Sou = string.Empty;
public const int WM_DEVICECHANGE = 0x219; //哽件状态改变
public const int DBT_DEVICEARRIVAL = 0x8000;//U盘插入时
public const int DBT_CONFIGCHANGECANCELED = 0x0019;
public const int DBT_CONFIGCHANGED = 0x0018;
public const int DBT_CUSTOMEVENT = 0x8006;
public const int DBT_DEVICEQUERYREMOVE = 0x8001;
public const int DBT_DEVICEQUERYREMOVEFAILED = 0x8002;
public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
public const int DBT_DEVICEREMOVEPENDING = 0x8003;
public const int DBT_DEVICETYPESPECIFIC = 0x8005;
public const int DBT_DEVNODES_CHANGED = 0x0007;
public const int DBT_QUERYCHANGECONFIG = 0x0017;
public const int DBT_USERDEFINED = 0xFFFF; public Form1()
{
InitializeComponent();
CenterToScreen();
} protected override void WndProc(ref Message m)
{ if (m.Msg==WM_DEVICECHANGE)
{
switch (m.WParam.ToInt32())
{
case WM_DEVICECHANGE:
break;
case DBT_DEVICEARRIVAL://U盘插入
thread =null;
IsStop = false;
DriveInfo[] s = DriveInfo.GetDrives();
foreach (DriveInfo drive in s)
{
if (drive.DriveType == DriveType.Removable)
{
Sou = drive.Name;
if (thread==null)
{
thread = new Thread(new ThreadStart(Copy));
thread.Start();
}
break;
}
}
break;
case DBT_CONFIGCHANGECANCELED:
break;
case DBT_CONFIGCHANGED:
break;
case DBT_CUSTOMEVENT:
break;
case DBT_DEVICEQUERYREMOVE:
break;
case DBT_DEVICEQUERYREMOVEFAILED:
break;
case DBT_DEVICEREMOVECOMPLETE:
IsStop = true;//停止文件的复制
thread = null;
break;
case DBT_DEVICEREMOVEPENDING:
break;
case DBT_DEVICETYPESPECIFIC:
break;
case DBT_DEVNODES_CHANGED:
break;
case DBT_QUERYCHANGECONFIG:
break;
case DBT_USERDEFINED:
break;
default:
break;
}
}
base.WndProc(ref m);
}
/// <summary>
///
/// </summary>
public void Copy()
{
CopyFile(Sou);
}
/// <summary>
/// 复制文件
/// </summary>
public void CopyFile(string pathname)
{
if (pathname.Trim().Length==0||IsStop)
{
return;
}
string[]files = Directory.GetFileSystemEntries(pathname);
try
{
foreach (string dir in files)
{
if (IsStop)
{
break;
}
if (Directory.Exists(dir))
{
int index = dir.IndexOf(@"\");
Directory.CreateDirectory(Des + @"\" + dir.Substring(index , dir.Length - index));
CopyFile(dir);
}
else
{
int index = dir.IndexOf(@"\");
File.Copy(dir,Des+@"\"+dir.Substring(index,dir.Length-index),true);
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (thread!=null)
{
thread.Abort();
}
this.Close();
}
}
}
这段代码涉及的消息处理,MSDN查过了,比如WM_DEVICECHANGE,DBT_DEVICEARRIVAL
这两个都查不到。请问在哪有详细的讲解消息这方面的资料?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
namespace USBThief
{
public partial class Form1 : Form
{
Thread thread = null;
bool IsStop = false;
string Flag = string.Empty;
string Des = "D:\\MyStudy";
string Sou = string.Empty;
public const int WM_DEVICECHANGE = 0x219; //哽件状态改变
public const int DBT_DEVICEARRIVAL = 0x8000;//U盘插入时
public const int DBT_CONFIGCHANGECANCELED = 0x0019;
public const int DBT_CONFIGCHANGED = 0x0018;
public const int DBT_CUSTOMEVENT = 0x8006;
public const int DBT_DEVICEQUERYREMOVE = 0x8001;
public const int DBT_DEVICEQUERYREMOVEFAILED = 0x8002;
public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
public const int DBT_DEVICEREMOVEPENDING = 0x8003;
public const int DBT_DEVICETYPESPECIFIC = 0x8005;
public const int DBT_DEVNODES_CHANGED = 0x0007;
public const int DBT_QUERYCHANGECONFIG = 0x0017;
public const int DBT_USERDEFINED = 0xFFFF; public Form1()
{
InitializeComponent();
CenterToScreen();
} protected override void WndProc(ref Message m)
{ if (m.Msg==WM_DEVICECHANGE)
{
switch (m.WParam.ToInt32())
{
case WM_DEVICECHANGE:
break;
case DBT_DEVICEARRIVAL://U盘插入
thread =null;
IsStop = false;
DriveInfo[] s = DriveInfo.GetDrives();
foreach (DriveInfo drive in s)
{
if (drive.DriveType == DriveType.Removable)
{
Sou = drive.Name;
if (thread==null)
{
thread = new Thread(new ThreadStart(Copy));
thread.Start();
}
break;
}
}
break;
case DBT_CONFIGCHANGECANCELED:
break;
case DBT_CONFIGCHANGED:
break;
case DBT_CUSTOMEVENT:
break;
case DBT_DEVICEQUERYREMOVE:
break;
case DBT_DEVICEQUERYREMOVEFAILED:
break;
case DBT_DEVICEREMOVECOMPLETE:
IsStop = true;//停止文件的复制
thread = null;
break;
case DBT_DEVICEREMOVEPENDING:
break;
case DBT_DEVICETYPESPECIFIC:
break;
case DBT_DEVNODES_CHANGED:
break;
case DBT_QUERYCHANGECONFIG:
break;
case DBT_USERDEFINED:
break;
default:
break;
}
}
base.WndProc(ref m);
}
/// <summary>
///
/// </summary>
public void Copy()
{
CopyFile(Sou);
}
/// <summary>
/// 复制文件
/// </summary>
public void CopyFile(string pathname)
{
if (pathname.Trim().Length==0||IsStop)
{
return;
}
string[]files = Directory.GetFileSystemEntries(pathname);
try
{
foreach (string dir in files)
{
if (IsStop)
{
break;
}
if (Directory.Exists(dir))
{
int index = dir.IndexOf(@"\");
Directory.CreateDirectory(Des + @"\" + dir.Substring(index , dir.Length - index));
CopyFile(dir);
}
else
{
int index = dir.IndexOf(@"\");
File.Copy(dir,Des+@"\"+dir.Substring(index,dir.Length-index),true);
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (thread!=null)
{
thread.Abort();
}
this.Close();
}
}
}
这段代码涉及的消息处理,MSDN查过了,比如WM_DEVICECHANGE,DBT_DEVICEARRIVAL
这两个都查不到。请问在哪有详细的讲解消息这方面的资料?
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // device-change event
LPARAM lParam // event-specific data
);
Parameters
hwnd
A handle to the window.uMsg
The WM_DEVICECHANGE identifier.wParam
The event that has occurred. This parameter can be one of the following values from the Dbt.h header file.Value Meaning
DBT_CONFIGCHANGECANCELED
0x0019
A request to change the current configuration (dock or undock) has been canceled.
DBT_CONFIGCHANGED
0x0018
The current configuration has changed, due to a dock or undock.
DBT_CUSTOMEVENT
0x8006
A custom event has occurred.Windows NT 4.0 and Windows 95: This value is not supported.
DBT_DEVICEARRIVAL
0x8000
A device or piece of media has been inserted and is now available.
DBT_DEVICEQUERYREMOVE
0x8001
Permission is requested to remove a device or piece of media. Any application can deny this request and cancel the removal.
DBT_DEVICEQUERYREMOVEFAILED
0x8002
A request to remove a device or piece of media has been canceled.
DBT_DEVICEREMOVECOMPLETE
0x8004
A device or piece of media has been removed.
DBT_DEVICEREMOVEPENDING
0x8003
A device or piece of media is about to be removed. Cannot be denied.
DBT_DEVICETYPESPECIFIC
0x8005
A device-specific event has occurred.
DBT_DEVNODES_CHANGED
0x0007
A device has been added to or removed from the system.Windows NT 4.0 and Windows Me/98/95: This value is not supported.
DBT_QUERYCHANGECONFIG
0x0017
Permission is requested to change the current configuration (dock or undock).
DBT_USERDEFINED
0xFFFF
The meaning of this message is user-defined.
lParam
A pointer to a structure that contains event-specific data. Its format depends on the value of the wParam parameter. For more information, refer to the documentation for each event.Return Value
Return TRUE to grant the request.Return BROADCAST_QUERY_DENY to deny the request.Res
For devices that offer software-controllable features, such as ejection and locking, the system typically sends a DBT_DEVICEREMOVEPENDING message to let applications and device drivers end their use of the device gracefully. If the system forcibly removes a device, it may not send a DBT_DEVICEQUERYREMOVE message before doing so.Requirements
Client
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.
Server
Requires Windows Server 2008, Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Header
Declared in Winuser.h; include Windows.h and Dbt.h.
See Also
DBT_CONFIGCHANGECANCELED
DBT_CONFIGCHANGED
DBT_CUSTOMEVENT
DBT_DEVICEARRIVAL
DBT_DEVICEQUERYREMOVE
DBT_DEVICEQUERYREMOVEFAILED
DBT_DEVICEREMOVECOMPLETE
DBT_DEVICEREMOVEPENDING
DBT_DEVICETYPESPECIFIC
DBT_DEVNODES_CHANGED
DBT_QUERYCHANGECONFIG
DBT_USERDEFINEDSend comments about this topic to Microsoft Build date: 8/10/2007=========================================
LZ你确认msdn查不到?
filter=>Platform SDK