📄 notify.cs
字号:
{
get
{
return BitConverter.ToInt32(data, 16);
}
}
#endregion
#region IDisposable Members
protected void Dispose(bool disposing)
{
//free up native memory
IntPtr titleptr = (IntPtr)BitConverter.ToInt32(data, 4);
if(titleptr!=IntPtr.Zero)
{
MarshalEx.FreeHGlobal(titleptr);
BitConverter.GetBytes((int)0).CopyTo(data, 4);
}
IntPtr textptr = (IntPtr)BitConverter.ToInt32(data, 8);
if(textptr!=IntPtr.Zero)
{
MarshalEx.FreeHGlobal(textptr);
BitConverter.GetBytes((int)0).CopyTo(data, 8);
}
IntPtr soundptr = (IntPtr)BitConverter.ToInt32(data, 12);
if(soundptr!=IntPtr.Zero)
{
MarshalEx.FreeHGlobal(soundptr);
BitConverter.GetBytes((int)0).CopyTo(data, 12);
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// This member overrides <see cref="M:System.Object.Finalize">Object.Finalize</see>.
/// </summary>
~UserNotification()
{
Dispose(false);
}
#endregion
}
#endregion
#region User Notification Info Header
/// <summary>
/// Contains information about notification events.
/// </summary>
public class UserNotificationInfoHeader
{
private const int Size = 16;
private byte[] data;
private UserNotificationTrigger trigger;
private UserNotification notify;
#region Constructor
/// <summary>
/// Create a new instance of UserNotificationInfoHeader
/// </summary>
public UserNotificationInfoHeader()
{
//16 byte structure
data = new byte[Size];
}
#endregion
#region From Pointer
/// <summary>
///
/// </summary>
/// <param name="pointer"></param>
/// <returns></returns>
internal static UserNotificationInfoHeader FromPtr(IntPtr pointer)
{
UserNotificationInfoHeader nih = new UserNotificationInfoHeader();
Marshal.Copy(pointer, nih.data, 0, Size);
//marshall trigger
nih.trigger = UserNotificationTrigger.FromPtr((IntPtr)BitConverter.ToInt32(nih.data, 8));
//marshall notification
IntPtr notifyptr = (IntPtr)BitConverter.ToInt32(nih.data, 12);
//if null pointer no notification
if(notifyptr!=IntPtr.Zero)
{
//else convert to managed notificatio object
nih.notify = UserNotification.FromPtr(notifyptr);
}
return nih;
}
#endregion
#region Handle
/// <summary>
/// Handle to the notification.
/// </summary>
public int Handle
{
get
{
return BitConverter.ToInt32(data, 0);
}
}
#endregion
#region Status
/// <summary>
/// Indicates current state of the notification.
/// </summary>
public NotificationStatus Status
{
get
{
return (NotificationStatus)BitConverter.ToInt32(data, 4);
}
}
#endregion
#region User Notification Trigger
/// <summary>
/// The UserNotificationTrigger object
/// </summary>
public UserNotificationTrigger UserNotificationTrigger
{
get
{
return trigger;
}
}
#endregion
#region User Notification
/// <summary>
/// The UserNotification object.
/// </summary>
public UserNotification UserNotification
{
get
{
return notify;
}
}
#endregion
}
#endregion
#region User Notification Trigger
/// <summary>
/// Defines what event activates a notification.
/// </summary>
public class UserNotificationTrigger : IDisposable
{
private const int Size = 52;
private byte[] data;
#region Constructor
/// <summary>
/// Create a new instance of UserNotificationTrigger
/// </summary>
public UserNotificationTrigger()
{
data = new byte[Size];
BitConverter.GetBytes(Size).CopyTo( data, 0);
/*sApplication = new char[OpenNETCF.IO.FileEx.MaxPath];
sApplicationHandle = GCHandle.Alloc(sApplication, GCHandleType.Pinned);
BitConverter.GetBytes((int)sApplicationHandle.AddrOfPinnedObject() + 4).CopyTo(data, 12);
sArgs = new char[OpenNETCF.IO.FileEx.MaxPath];
sArgsHandle = GCHandle.Alloc(sArgs, GCHandleType.Pinned);
BitConverter.GetBytes((int)sArgsHandle.AddrOfPinnedObject() + 4).CopyTo(data, 16);*/
}
#endregion
internal byte[] ToByteArray()
{
return data;
}
#region From Pointer
/// <summary>
/// Returns a UserNotificationTrigger object from a native pointer.
/// </summary>
/// <param name="pointer">Native memory pointer.</param>
/// <returns>New UserNotificationTrigger object.</returns>
public static UserNotificationTrigger FromPtr(IntPtr pointer)
{
UserNotificationTrigger trigger = new UserNotificationTrigger();
//copy the bytes
Marshal.Copy(pointer, trigger.data, 0, Size);
return trigger;
}
#endregion
#region Type
/// <summary>
/// Specifies the type of notification.
/// </summary>
public NotificationType Type
{
get
{
return (NotificationType)BitConverter.ToInt32(data, 4);
}
set
{
BitConverter.GetBytes((int)value).CopyTo(data, 4);
}
}
#endregion
#region Event
/// <summary>
/// Specifies the type of event should Type = Event.
/// </summary>
public NotificationEvent Event
{
get
{
return (NotificationEvent)BitConverter.ToInt32(data, 8);
}
set
{
BitConverter.GetBytes((int)value).CopyTo(data, 8);
}
}
#endregion
#region Application
/// <summary>
/// Name of the application to execute.
/// </summary>
public string Application
{
get
{
IntPtr appptr = (IntPtr)BitConverter.ToInt32(data, 12);
if(appptr!=IntPtr.Zero)
{
return Marshal.PtrToStringUni(appptr);
}
else
{
return null;
}
}
set
{
IntPtr appptr = (IntPtr)BitConverter.ToInt32(data, 12);
//if native string already allocated
if(appptr!=IntPtr.Zero)
{
//free previous value
MarshalEx.FreeHGlobal(appptr);
}
appptr = MarshalEx.StringToHGlobalUni(value);
//put value into array
BitConverter.GetBytes(appptr.ToInt32()).CopyTo(data, 12);
}
}
#endregion
#region Arguments
/// <summary>
/// Command line (without the application name).
/// </summary>
public string Arguments
{
get
{
IntPtr argptr = (IntPtr)BitConverter.ToInt32(data, 16);
if(argptr!=IntPtr.Zero)
{
return Marshal.PtrToStringUni(argptr);
}
else
{
return null;
}
}
set
{
IntPtr argptr = (IntPtr)BitConverter.ToInt32(data, 16);
//if native string already allocated
if(argptr!=IntPtr.Zero)
{
//free previous value
MarshalEx.FreeHGlobal(argptr);
}
argptr = MarshalEx.StringToHGlobalUni(value);
//put value into array
BitConverter.GetBytes(argptr.ToInt32()).CopyTo(data, 16);
}
}
#endregion
#region Start Time
/// <summary>
/// Specifies the beginning of the notification period.
/// </summary>
public DateTime StartTime
{
get
{
byte[] datebytes = new byte[16];
Buffer.BlockCopy(data, 20, datebytes, 0, 16);
SystemTime st = new SystemTime(datebytes);
return st.ToDateTime();
}
set
{
byte[] datebytes = SystemTime.FromDateTime(value).ToByteArray();
Buffer.BlockCopy(datebytes, 0, data, 20, 16);
}
}
#endregion
#region End Time
/// <summary>
/// Specifies the end of the notification period.
/// </summary>
public DateTime EndTime
{
get
{
byte[] datebytes = new byte[16];
Buffer.BlockCopy(data, 36, datebytes, 0, 16);
SystemTime st = new SystemTime(datebytes);
return st.ToDateTime();
}
set
{
byte[] datebytes = SystemTime.FromDateTime(value).ToByteArray();
Buffer.BlockCopy(datebytes, 0, data, 36, 16);
}
}
#endregion
#region IDisposable Members
protected void Dispose(bool disposing)
{
//free strings
IntPtr appptr = (IntPtr)BitConverter.ToInt32(data, 12);
if(appptr!=IntPtr.Zero)
{
MarshalEx.FreeHGlobal(appptr);
BitConverter.GetBytes(0).CopyTo(data,12);
}
IntPtr argptr = (IntPtr)BitConverter.ToInt32(data, 16);
//if native string already allocated
if(argptr!=IntPtr.Zero)
{
//free previous value
MarshalEx.FreeHGlobal(argptr);
BitConverter.GetBytes(0).CopyTo(data,16);
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~UserNotificationTrigger()
{
Dispose(false);
}
#endregion
}
#endregion
#region Notification Event
/// <summary>
/// System Event Flags
/// </summary>
public enum NotificationEvent : int
{
/// <summary>
/// No events梤emove all event registrations for this application.
/// </summary>
None = 0x00,
/// <summary>
/// When the system time is changed.
/// </summary>
TimeChange = 0x01,
/// <summary>
/// When data synchronization finishes.
/// </summary>
SyncEnd = 0x02,
/// <summary>
/// The user turned the AC power on.
/// </summary>
OnACPower = 0x03,
/// <summary>
/// The user turned the alternating current (AC) power off.
/// </summary>
OffACPower = 0x04,
/// <summary>
/// The device connected to a network.
/// </summary>
NetConnect = 0x05,
/// <summary>
/// The device disconnected from a network.
/// </summary>
NetDisconnect = 0x06,
/// <summary>
/// When a PC Card device is changed.
/// </summary>
DeviceChange = 0x07,
/// <summary>
/// The device discovered a server by using infrared communications.
/// </summary>
IRDiscovered = 0x08,
/// <summary>
/// When an RS232 connection is made.
/// </summary>
RS232Detected = 0x09,
/// <summary>
/// When a full device data restore completes.
/// </summary>
RestoreEnd = 0x0A,
/// <summary>
/// When the device wakes up.
/// </summary>
Wakeup = 0x0B,
/// <summary>
/// When the time zone is changed.
/// </summary>
TimeZoneChange = 0x0C,
/// <summary>
/// When the machines name changes.
/// Requires Windows CE.NET 4.2.
/// </summary>
MachineNameChange = 0x0D,
/// <summary>
/// RNDISFN interface is instantiated.
/// Requires Windows CE 5.0.
/// </summary>
RndisFNDetected = 0x0E,
/// <summary>
/// The Internet Proxy used by the device has changed.
/// Requires Windows CE 5.0.
/// </summary>
InternetProxyChange = 0x0f,
}
#endregion
#region Notification Action
/// <summary>
/// Specifies the action to take when a notification event occurs.
/// </summary>
[Flags()]
public enum NotificationAction : int
{
/// <summary>
/// Flashes the LED.
/// </summary>
Led = 1,
/// <summary>
/// Vibrates the device.
/// </summary>
Vibrate = 2,
/// <summary>
/// Displays the user notification dialog box.
/// </summary>
Dialog = 4,
/// <summary>
/// Plays the sound specified.
/// </summary>
Sound = 8,
/// <summary>
/// Repeats the sound for 10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -