/* * The following code will create a time based trigger and connect that trigger to a notification that will fire up \windows\fexplore.exe. * Note that you need to compile this sample with the /unsafe switch. You could always hard code the size of CE_NOTIFICATION_TRIGGER in which case /unsafe won't be necessary. If hard coded; the value is 52. * Also don't forget to pass NULL instead of ceun if you change the trigger type to CNT_EVENT. */ public void newRunAtTime(SYSTEMTIME stStart, SYSTEMTIME stEnd) { CE_NOTIFICATION_TRIGGER cnt = new CE_NOTIFICATION_TRIGGER(); CE_USER_NOTIFICATION ceun = new CE_USER_NOTIFICATION(); cnt.Type = CeNotificationType.CNT_TIME; cnt.StartTime = stStart; cnt.EndTime = stEnd; cnt.pApplication = @"\windows\fexplore.exe"; cnt.pArgs = ""; cnt.Size = (UInt32)Marshal.SizeOf(cnt); // Needs to compile with /unsafe ceun.ActionFlags = PUN_FLAGS.PUN_LED; ceun.sDialogText = "Dialogtext"; ceun.sDialogTitle = "Title"; ceun.nMaxSound = 0; uint hNotificationEx = SetUserNotificationEx(0, cnt, ceun); if (hNotificationEx > 0) { MessageBox.Show("Successfully created a notification. Handle: " + hNotificationEx.ToString()); } else { MessageBox.Show("Failed to create a notification"); } }
public CE_NOTIFICATION_INFO_HEADER(byte[] Buf, uint Size) { int Index = 0; try { this.hNotification = BitConverter.ToUInt32(Buf, Index); Index += 4; this.dwStatus = BitConverter.ToUInt32(Buf, Index); Index += 4; uint pcent = BitConverter.ToUInt32(Buf, Index); Index += 4; uint pceun = BitConverter.ToUInt32(Buf, Index); Index += 4; if (pcent > 0 && Buf[Index] == Marshal.SizeOf(new CE_NOTIFICATION_TRIGGER())) { this.cent = new CE_NOTIFICATION_TRIGGER(Buf, Size, ref Index); } if (pceun > 0) { this.ceun = new CE_USER_NOTIFICATION(Buf, Size, ref Index); } } catch (Exception ex) { throw ex; } }
public CE_USER_NOTIFICATION[] getUserNotifications(){ //how many usernotifications are there? IntPtr[] unHandles = new IntPtr[1]; uint iHandleCount = 1; uint iHandlesNeeded = 0; if (!GetUserNotificationHandles(unHandles, iHandleCount, ref iHandlesNeeded)) return null; //we got some handle count unHandles = new IntPtr[iHandlesNeeded]; iHandleCount = iHandlesNeeded; if (!GetUserNotificationHandles(unHandles, iHandleCount, ref iHandlesNeeded)) return null; CE_USER_NOTIFICATION[] userNotifications = new CE_USER_NOTIFICATION[iHandleCount]; for (int i = 0; i < iHandleCount; i++) { uint uBytesNeeded=0; if (GetUserNotification(unHandles[i], 0, out uBytesNeeded, null)==false) { byte[] buf = new byte[uBytesNeeded]; uint uBufSize = uBytesNeeded; GetUserNotification(unHandles[i], uBufSize, out uBytesNeeded, buf); int iIdx = 0; userNotifications[i] = new CE_USER_NOTIFICATION(buf, (uint)buf.Length, ref iIdx); } else System.Diagnostics.Debug.WriteLine("GetUserNotification: " + Marshal.GetLastWin32Error().ToString()); } return userNotifications; }
public static void NotifyDialog(string title, string text, DateTime start) { CE_NOTIFICATION_TRIGGER nt = new CE_NOTIFICATION_TRIGGER(start); CE_USER_NOTIFICATION un = new CE_USER_NOTIFICATION(title, text); using (nt) using ( un ) { IntPtr hNotify = CeSetUserNotificationEx(IntPtr.Zero, ref nt, ref un); if (hNotify == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } }
public CE_USER_NOTIFICATION[] getUserNotifications() { //how many usernotifications are there? IntPtr[] unHandles = new IntPtr[1]; uint iHandleCount = 1; uint iHandlesNeeded = 0; if (!GetUserNotificationHandles(unHandles, iHandleCount, ref iHandlesNeeded)) { return(null); } //we got some handle count unHandles = new IntPtr[iHandlesNeeded]; iHandleCount = iHandlesNeeded; if (!GetUserNotificationHandles(unHandles, iHandleCount, ref iHandlesNeeded)) { return(null); } CE_USER_NOTIFICATION[] userNotifications = new CE_USER_NOTIFICATION[iHandleCount]; for (int i = 0; i < iHandleCount; i++) { uint uBytesNeeded = 0; if (GetUserNotification(unHandles[i], 0, out uBytesNeeded, null) == false) { byte[] buf = new byte[uBytesNeeded]; uint uBufSize = uBytesNeeded; GetUserNotification(unHandles[i], uBufSize, out uBytesNeeded, buf); int iIdx = 0; userNotifications[i] = new CE_USER_NOTIFICATION(buf, (uint)buf.Length, ref iIdx); } else { System.Diagnostics.Debug.WriteLine("GetUserNotification: " + Marshal.GetLastWin32Error().ToString()); } } return(userNotifications); }
public static void NotifyDialog( string title, string text, NOTIFICATION_EVENT notificationEvent ) { CE_NOTIFICATION_TRIGGER nt = new CE_NOTIFICATION_TRIGGER( notificationEvent ); CE_USER_NOTIFICATION un = new CE_USER_NOTIFICATION( title, text ); using( nt ) using( un ) { IntPtr hNotify = CeSetUserNotificationEx( IntPtr.Zero, ref nt, ref un ); if( hNotify == IntPtr.Zero ) { throw new Win32Exception( Marshal.GetLastWin32Error() ); } } }
private static extern IntPtr CeSetUserNotificationEx( IntPtr h, ref CE_NOTIFICATION_TRIGGER nt, ref CE_USER_NOTIFICATION un );
private static extern IntPtr CeSetUserNotificationEx(IntPtr notification, CE_NOTIFICATION_TRIGGER notificationTrigger, CE_USER_NOTIFICATION userNotification);
public static extern uint SetUserNotificationEx([MarshalAs(UnmanagedType.U4)] uint hNotification, CE_NOTIFICATION_TRIGGER Trigger, CE_USER_NOTIFICATION Notification);
public static extern uint SetUserNotificationEx([MarshalAs(UnmanagedType.U4)]uint hNotification, CE_NOTIFICATION_TRIGGER Trigger, CE_USER_NOTIFICATION Notification);
public CE_NOTIFICATION_INFO_HEADER(byte[] Buf, uint Size) { int Index = 0; try { this.hNotification = BitConverter.ToUInt32(Buf, Index); Index += 4; this.dwStatus = BitConverter.ToUInt32(Buf, Index); Index += 4; uint pcent = BitConverter.ToUInt32(Buf, Index); Index += 4; uint pceun = BitConverter.ToUInt32(Buf, Index); Index += 4; if (pcent > 0 && Buf[Index] == Marshal.SizeOf(new CE_NOTIFICATION_TRIGGER())) this.cent = new CE_NOTIFICATION_TRIGGER(Buf, Size, ref Index); if (pceun > 0) this.ceun = new CE_USER_NOTIFICATION(Buf, Size, ref Index); } catch (Exception ex) { throw ex; } }
/* The following code will create a time based trigger and connect that trigger to a notification that will fire up \windows\fexplore.exe. Note that you need to compile this sample with the /unsafe switch. You could always hard code the size of CE_NOTIFICATION_TRIGGER in which case /unsafe won't be necessary. If hard coded; the value is 52. Also don't forget to pass NULL instead of ceun if you change the trigger type to CNT_EVENT. */ public void newRunAtTime(SYSTEMTIME stStart, SYSTEMTIME stEnd){ CE_NOTIFICATION_TRIGGER cnt = new CE_NOTIFICATION_TRIGGER(); CE_USER_NOTIFICATION ceun = new CE_USER_NOTIFICATION(); cnt.Type =CeNotificationType.CNT_TIME; cnt.StartTime = stStart; cnt.EndTime = stEnd; cnt.pApplication = @"\windows\fexplore.exe"; cnt.pArgs = ""; cnt.Size = (UInt32)Marshal.SizeOf(cnt); // Needs to compile with /unsafe ceun.ActionFlags = PUN_FLAGS.PUN_LED; ceun.sDialogText = "Dialogtext"; ceun.sDialogTitle = "Title"; ceun.nMaxSound = 0; uint hNotificationEx = SetUserNotificationEx(0, cnt, ceun); if (hNotificationEx > 0) MessageBox.Show("Successfully created a notification. Handle: " + hNotificationEx.ToString()); else MessageBox.Show("Failed to create a notification"); }