/// <summary>
        /// Message received from the WndProc of a registered form
        /// </summary>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <param name="info"></param>
        public bool NotificationReceipt(IntPtr wParam, IntPtr lParam, ref NotifyInfos info)
        {
            SHNOTIFYSTRUCT shNotify = (SHNOTIFYSTRUCT)Marshal.PtrToStructure(wParam, typeof(SHNOTIFYSTRUCT));

            if (info.Notification == SHCNE.SHCNE_FREESPACE || info.Notification == SHCNE.SHCNE_UPDATEIMAGE)
            {
                return(false);
            }

            info.Item1 = GetPathFromPidl(shNotify.dwItem1);
            info.Item2 = GetPathFromPidl(shNotify.dwItem2);
            return(true);
        }
Beispiel #2
0
  /// <summary>
  /// Message Pump
  /// </summary>
  /// <param name="msg"></param>
  protected override void WndProc(ref Message msg)
  {
    try
    {
      switch (msg.Msg)
      {
        case (int)ShellNotifications.WmShnotify:
          NotifyInfos info = new NotifyInfos((ShellNotifications.SHCNE)(int)msg.LParam);
          
          if (Notifications.NotificationReceipt(msg.WParam, msg.LParam, ref info))
          {
            if (info.Notification == ShellNotifications.SHCNE.SHCNE_MEDIAINSERTED)
            {
              string path = info.Item1;

              if (Utils.IsRemovable(path))
              {
                string driveName = Utils.GetDriveName(info.Item1);
                GUIMessage gmsg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ADD_REMOVABLE_DRIVE, 0, 0, 0, 0, 0, 0);
                gmsg.Label = info.Item1;
                gmsg.Label2 = String.Format("({0}) {1}", path, driveName);
                GUIGraphicsContext.SendMessage(gmsg);
              }
            }

            if (info.Notification == ShellNotifications.SHCNE.SHCNE_MEDIAREMOVED)
            {
              string path = info.Item1;

              if (Utils.IsRemovable(path))
              {
                string driveName = Utils.GetDriveName(info.Item1);
                GUIMessage gmsg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_REMOVE_REMOVABLE_DRIVE, 0, 0, 0, 0, 0, 0);
                gmsg.Label = info.Item1;
                gmsg.Label2 = String.Format("({0}) {1}", path, driveName);
                GUIGraphicsContext.SendMessage(gmsg);
              }
            }
          }
          return;

        // power management
        case WM_POWERBROADCAST:
          OnPowerBroadcast(ref msg);
          break;

        // set maximum and minimum form size in windowed mode
        case WM_GETMINMAXINFO:
          OnGetMinMaxInfo(ref msg);
          PluginManager.WndProc(ref msg);
          break;

        case WM_ENTERSIZEMOVE:
          Log.Debug("Main: WM_ENTERSIZEMOVE");
          PluginManager.WndProc(ref msg);
          break;

        case WM_EXITSIZEMOVE:
          Log.Debug("Main: WM_EXITSIZEMOVE");
          PluginManager.WndProc(ref msg);
          break;

        // only allow window to be moved inside a valid working area
        case WM_MOVING:
          OnMoving(ref msg);
          PluginManager.WndProc(ref msg);
          break;
        
        // verify window size in case it was not resized by the user
        case WM_SIZE:
          OnSize(ref msg);
          PluginManager.WndProc(ref msg);
          break;

        // aspect ratio save window resizing
        case WM_SIZING:
          OnSizing(ref msg);
          PluginManager.WndProc(ref msg);
          break;
        
        // handle display changes
        case WM_DISPLAYCHANGE:
          OnDisplayChange(ref msg);
          PluginManager.WndProc(ref msg);
          break;
        
        // handle device changes
        case WM_DEVICECHANGE:
          OnDeviceChange(ref msg);
          PluginManager.WndProc(ref msg);
          break;

        case WM_QUERYENDSESSION:
          Log.Debug("Main: WM_QUERYENDSESSION");
          PluginManager.WndProc(ref msg);
          base.WndProc(ref msg);
          ShuttingDown = true;
          msg.Result = (IntPtr)1;
          break;

        case WM_ENDSESSION:
          Log.Info("Main: WM_ENDESSION");
          PluginManager.WndProc(ref msg);
          base.WndProc(ref msg);
          Application.ExitThread();
          Application.Exit();
          msg.Result = (IntPtr)0;
          break;
        
        // handle activation and deactivation requests
        case WM_ACTIVATE:
          OnActivate(ref msg);
          PluginManager.WndProc(ref msg);
          break;

        // handle system commands
        case WM_SYSCOMMAND:
          // do not continue with rest of method in case we aborted screen saver or display powering off
          if (!OnSysCommand(ref msg))
          {
            return;
          }
          PluginManager.WndProc(ref msg);
          break;

        // handle default commands needed for plugins
        default:
          PluginManager.WndProc(ref msg);
          break;
      }

      // TODO: extract to method and change to correct code
      // forward message to input devices
      Action action;
      char key;
      Keys keyCode;
      if (InputDevices.WndProc(ref msg, out action, out key, out keyCode))
      {
        if (msg.Result.ToInt32() != 1)
        {
          msg.Result = new IntPtr(0);
        }

        if (action != null && action.wID != Action.ActionType.ACTION_INVALID)
        {
          Log.Info("Main: Incoming action: {0}", action.wID);
          if (ActionTranslator.GetActionDetail(GUIWindowManager.ActiveWindowEx, action) && (action.SoundFileName.Length > 0 && !g_Player.Playing))
          {
            Utils.PlaySound(action.SoundFileName, false, true);
          }
          GUIGraphicsContext.ResetLastActivity();
          GUIGraphicsContext.OnAction(action);
        }

        if (keyCode != Keys.A)
        {
          Log.Info("Main: Incoming Keycode: {0}", keyCode.ToString());
          var ke = new KeyEventArgs(keyCode);
          OnKeyDown(ke);
          return; // abort WndProc()
        }

        if (key != 0)
        {
          Log.Info("Main: Incoming Key: {0}", key);
          var e = new KeyPressEventArgs(key);
          OnKeyPress(e);
          return; // abort WndProc()
        }

        return; // abort WndProc()
      }

      // forward message to player
      g_Player.WndProc(ref msg);

      // forward message to form class
      base.WndProc(ref msg);
    }

    catch (Exception ex)
    {
      Log.Error(ex);
    }
  }
    /// <summary>
    /// Message received from the WndProc of a registered form
    /// </summary>
    /// <param name="wParam"></param>
    /// <param name="lParam"></param>
    /// <param name="info"></param>
    public bool NotificationReceipt(IntPtr wParam, IntPtr lParam, ref NotifyInfos info)
    {
      SHNOTIFYSTRUCT shNotify = (SHNOTIFYSTRUCT)Marshal.PtrToStructure(wParam, typeof(SHNOTIFYSTRUCT));

      if (info.Notification == SHCNE.SHCNE_FREESPACE || info.Notification == SHCNE.SHCNE_UPDATEIMAGE)
      {
        return false;
      }

      info.Item1 = GetPathFromPidl(shNotify.dwItem1);
      info.Item2 = GetPathFromPidl(shNotify.dwItem2);
      return true;
    }