Exemplo n.º 1
0
        public static UserNotificationInfoHeader GetUserNotification(int handle)
        {
            int pcBytesNeeded = 0;

            NativeMethods.CeGetUserNotification(handle, 0, ref pcBytesNeeded, IntPtr.Zero);
            IntPtr pBuffer = Marshal.AllocHGlobal(pcBytesNeeded);

            if (!NativeMethods.CeGetUserNotification(handle, (uint)pcBytesNeeded, ref pcBytesNeeded, pBuffer))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Error getting UserNotification");
            }
            UserNotificationInfoHeader header = new UserNotificationInfoHeader
            {
                hNotification = Marshal.ReadInt32(pBuffer, 0),
                dwStatus      = Marshal.ReadInt32(pBuffer, 4)
            };
            IntPtr ptr  = (IntPtr)Marshal.ReadInt32(pBuffer, 8);
            IntPtr ptr3 = (IntPtr)Marshal.ReadInt32(pBuffer, 12);

            header.pcent = new UserNotificationTrigger();
            if (ptr != IntPtr.Zero)
            {
                header.pcent.dwSize      = Marshal.ReadInt32(ptr);
                header.pcent.Type        = (NotificationType)Marshal.ReadInt32(ptr, 4);
                header.pcent.Event       = (NotificationEvent)Marshal.ReadInt32(ptr, 8);
                header.pcent.Application = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr, 12));
                header.pcent.Arguments   = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr, 0x10));
                header.pcent.stStartTime = (SYSTEMTIME)Marshal.PtrToStructure((IntPtr)(ptr.ToInt32() + 20), typeof(SYSTEMTIME));
                header.pcent.stEndTime   = (SYSTEMTIME)Marshal.PtrToStructure((IntPtr)(ptr.ToInt32() + 0x24), typeof(SYSTEMTIME));
            }
            header.pceun = new UserNotification();
            if (ptr3 != IntPtr.Zero)
            {
                header.pceun.Action   = (NotificationAction)Marshal.ReadInt32(ptr3, 0);
                header.pceun.Title    = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr3, 4));
                header.pceun.Text     = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr3, 8));
                header.pceun.Sound    = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr3, 12));
                header.pceun.MaxSound = Marshal.ReadInt32(ptr3, 0x10);
            }
            Marshal.FreeHGlobal(pBuffer);
            return(header);
        }
Exemplo n.º 2
0
 public static UserNotificationInfoHeader GetUserNotification(int handle)
 {
     int pcBytesNeeded = 0;
     NativeMethods.CeGetUserNotification(handle, 0, ref pcBytesNeeded, IntPtr.Zero);
     IntPtr pBuffer = Marshal.AllocHGlobal(pcBytesNeeded);
     if (!NativeMethods.CeGetUserNotification(handle, (uint)pcBytesNeeded, ref pcBytesNeeded, pBuffer))
     {
         throw new Win32Exception(Marshal.GetLastWin32Error(), "Error getting UserNotification");
     }
     UserNotificationInfoHeader header = new UserNotificationInfoHeader
     {
         hNotification = Marshal.ReadInt32(pBuffer, 0),
         dwStatus = Marshal.ReadInt32(pBuffer, 4)
     };
     IntPtr ptr = (IntPtr)Marshal.ReadInt32(pBuffer, 8);
     IntPtr ptr3 = (IntPtr)Marshal.ReadInt32(pBuffer, 12);
     header.pcent = new UserNotificationTrigger();
     if (ptr != IntPtr.Zero)
     {
         header.pcent.dwSize = Marshal.ReadInt32(ptr);
         header.pcent.Type = (NotificationType)Marshal.ReadInt32(ptr, 4);
         header.pcent.Event = (NotificationEvent)Marshal.ReadInt32(ptr, 8);
         header.pcent.Application = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr, 12));
         header.pcent.Arguments = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr, 0x10));
         header.pcent.stStartTime = (SYSTEMTIME)Marshal.PtrToStructure((IntPtr)(ptr.ToInt32() + 20), typeof(SYSTEMTIME));
         header.pcent.stEndTime = (SYSTEMTIME)Marshal.PtrToStructure((IntPtr)(ptr.ToInt32() + 0x24), typeof(SYSTEMTIME));
     }
     header.pceun = new UserNotification();
     if (ptr3 != IntPtr.Zero)
     {
         header.pceun.Action = (NotificationAction)Marshal.ReadInt32(ptr3, 0);
         header.pceun.Title = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr3, 4));
         header.pceun.Text = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr3, 8));
         header.pceun.Sound = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(ptr3, 12));
         header.pceun.MaxSound = Marshal.ReadInt32(ptr3, 0x10);
     }
     Marshal.FreeHGlobal(pBuffer);
     return header;
 }