Now calling display init. Not getting the expected error code though. MiniDisplay
authorStephaneLenclud
Mon, 04 Feb 2013 00:47:01 +0100
branchMiniDisplay
changeset 4359ffcd8ed8537
parent 434 480652d72031
child 436 e9aefd454d1e
Now calling display init. Not getting the expected error code though.
GUI/MainForm.cs
GUI/SoundGraphDisplay.cs
     1.1 --- a/GUI/MainForm.cs	Sun Feb 03 19:06:01 2013 +0100
     1.2 +++ b/GUI/MainForm.cs	Mon Feb 04 00:47:01 2013 +0100
     1.3 @@ -25,6 +25,7 @@
     1.4  using OpenHardwareMonitor.WMI;
     1.5  using OpenHardwareMonitor.Utilities;
     1.6  
     1.7 +
     1.8  namespace OpenHardwareMonitor.GUI {
     1.9    public partial class MainForm : Form {
    1.10  
    1.11 @@ -133,17 +134,6 @@
    1.12        systemTray.ExitCommand += exitClick;
    1.13    
    1.14        soundGraphDisplay = new SoundGraphDisplay(computer, settings, unitManager);
    1.15 -      if (soundGraphDisplay.IsDllLoaded)
    1.16 -      {
    1.17 -          //Try init
    1.18 -          //NativeWindow window;
    1.19 -          
    1.20 -
    1.21 -          //= Window.GetWindow(this);
    1.22 -          //var wih = new WindowInteropHelper(window);
    1.23 -          //IntPtr hWnd = wih.Handle;
    1.24 -      }
    1.25 -      
    1.26   
    1.27  
    1.28        int p = (int)Environment.OSVersion.Platform;
    1.29 @@ -328,6 +318,20 @@
    1.30  
    1.31        InitializePlotForm();
    1.32  
    1.33 +      //
    1.34 +      if (soundGraphDisplay.IsDllLoaded)
    1.35 +      {
    1.36 +          //Try init
    1.37 +          //NativeWindow window;
    1.38 +          soundGraphDisplay.Init(Handle);
    1.39 +
    1.40 +          //= Window.GetWindow(this);
    1.41 +          //var wih = new WindowInteropHelper(window);
    1.42 +          //IntPtr hWnd = wih.Handle;
    1.43 +      }
    1.44 +      
    1.45 +
    1.46 +
    1.47        startupMenuItem.Visible = startupManager.IsAvailable;
    1.48        
    1.49        if (startMinMenuItem.Checked) {
    1.50 @@ -773,25 +777,64 @@
    1.51        const int SC_MINIMIZE = 0xF020;
    1.52        const int SC_CLOSE = 0xF060;
    1.53  
    1.54 -      if (minimizeToTray.Value && 
    1.55 -        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE) {
    1.56 -        SysTrayHideShow();
    1.57 -      } else if (minimizeOnClose.Value &&
    1.58 -        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE) {
    1.59 -        /*
    1.60 -         * Apparently the user wants to minimize rather than close
    1.61 -         * Now we still need to check if we're going to the tray or not
    1.62 -         * 
    1.63 -         * Note: the correct way to do this would be to send out SC_MINIMIZE,
    1.64 -         * but since the code here is so simple,
    1.65 -         * that would just be a waste of time.
    1.66 -         */
    1.67 -        if (minimizeToTray.Value)
    1.68 +      if (m.Msg == SoundGraph.WM_DSP_PLUGIN_NOTIFY)
    1.69 +      {
    1.70 +        //Handling messages from our iMON Display
    1.71 +          switch ((SoundGraph.DSPNotifyCode)m.WParam.ToInt32())
    1.72 +          {
    1.73 +              case SoundGraph.DSPNotifyCode.DSPNM_PLUGIN_SUCCEED:
    1.74 +              case SoundGraph.DSPNotifyCode.DSPNM_IMON_RESTARTED:
    1.75 +              case SoundGraph.DSPNotifyCode.DSPNM_HW_CONNECTED:
    1.76 +                  {
    1.77 +                      //Connection with our display is now open
    1.78 +                      //Check if we have LCD or VFD
    1.79 +                      //if ((lParam & DSPN_DSP_VFD) == DSPN_DSP_VFD) m_bVfdConnected = TRUE;
    1.80 +                      //if ((lParam & DSPN_DSP_LCD) == DSPN_DSP_LCD) m_bLcdConnected = TRUE;
    1.81 +                      soundGraphDisplay.DisplayPluginMessage(m.WParam.ToInt32(),false);
    1.82 +                  }
    1.83 +                  break;
    1.84 +
    1.85 +              case SoundGraph.DSPNotifyCode.DSPNM_PLUGIN_FAILED:
    1.86 +              case SoundGraph.DSPNotifyCode.DSPNM_HW_DISCONNECTED:
    1.87 +              case SoundGraph.DSPNotifyCode.DSPNM_IMON_CLOSED:
    1.88 +                  {
    1.89 +                      //Connection with our display is closed
    1.90 +                      soundGraphDisplay.DisplayPluginMessage(m.LParam.ToInt32(), true);
    1.91 +                  }
    1.92 +                  break;
    1.93 +
    1.94 +              case SoundGraph.DSPNotifyCode.DSPNM_LCD_TEXT_SCROLL_DONE:
    1.95 +                  {
    1.96 +                      //Scroll finnished
    1.97 +                  }
    1.98 +                  break;
    1.99 +          }
   1.100 +
   1.101 +      }
   1.102 +      else if (minimizeToTray.Value &&
   1.103 +        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE)
   1.104 +      {
   1.105            SysTrayHideShow();
   1.106 -        else
   1.107 -          WindowState = FormWindowState.Minimized;
   1.108 -      } else {      
   1.109 -        base.WndProc(ref m);
   1.110 +      }
   1.111 +      else if (minimizeOnClose.Value &&
   1.112 +      m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE)
   1.113 +      {
   1.114 +          /*
   1.115 +           * Apparently the user wants to minimize rather than close
   1.116 +           * Now we still need to check if we're going to the tray or not
   1.117 +           * 
   1.118 +           * Note: the correct way to do this would be to send out SC_MINIMIZE,
   1.119 +           * but since the code here is so simple,
   1.120 +           * that would just be a waste of time.
   1.121 +           */
   1.122 +          if (minimizeToTray.Value)
   1.123 +              SysTrayHideShow();
   1.124 +          else
   1.125 +              WindowState = FormWindowState.Minimized;
   1.126 +      }
   1.127 +      else
   1.128 +      {
   1.129 +          base.WndProc(ref m);
   1.130        }
   1.131      }
   1.132  
     2.1 --- a/GUI/SoundGraphDisplay.cs	Sun Feb 03 19:06:01 2013 +0100
     2.2 +++ b/GUI/SoundGraphDisplay.cs	Mon Feb 04 00:47:01 2013 +0100
     2.3 @@ -13,6 +13,7 @@
     2.4  using System.Drawing;
     2.5  using System.Text;
     2.6  using System.Windows.Forms;
     2.7 +using System.Windows;
     2.8  using OpenHardwareMonitor.Hardware;
     2.9  using OpenHardwareMonitor.Utilities;
    2.10  using System.Runtime.InteropServices;
    2.11 @@ -51,11 +52,14 @@
    2.12   */
    2.13  static class SoundGraph
    2.14  {
    2.15 +
    2.16 +    const int WM_APP = 0x8000;
    2.17 +    public const int WM_DSP_PLUGIN_NOTIFY = WM_APP + 1121;
    2.18      /**DSPResult
    2.19      @brief	These enumeration values represent the returned result for iMON Display API function calls.\n
    2.20  			    All iMON Display API function calls return one of this result values.\n
    2.21  			    For meaning of each result, refer the comment of each line below*/
    2.22 -    public enum DSPResult : uint
    2.23 +    public enum DSPResult : int
    2.24      {
    2.25  	    DSP_SUCCEEDED = 0,				//// Function Call Succeeded Without Error
    2.26  	    DSP_E_FAIL,						//// Unspecified Failure
    2.27 @@ -75,7 +79,7 @@
    2.28      @brief	These enumeration values represent the result status for requesting Display Plug-in Mode to iMON.\n
    2.29  			    iMON Display API notifies one of this result values to the caller application after requesting Display Plug-in Mode to iMON.\n
    2.30  			    For more information, refer the comment of each line below*/
    2.31 -    public enum DSPNInitResult : uint
    2.32 +    public enum DSPNInitResult : int
    2.33      {
    2.34  	    DSPN_SUCCEEDED = 0,				//// Display Plug-in Mode is Initialized Successfully
    2.35  	    DSPN_ERR_IN_USED = 0x0100,		//// Display Plug-in is Already Used by Other Application
    2.36 @@ -90,7 +94,7 @@
    2.37      /**DSPType
    2.38      @brief	These enumeration values represent display type.\n
    2.39  			    Currently iMON Display API supports VFD and LCD products.*/
    2.40 -    public enum DSPType : uint
    2.41 +    public enum DSPType : int
    2.42      {
    2.43  	    DSPN_DSP_NONE	= 0,
    2.44  	    DSPN_DSP_VFD	= 0x01,			//// VFD products
    2.45 @@ -104,7 +108,7 @@
    2.46  			    The caller application should assign the message and the winodw handle to receivce message with IMON_Display_Init fucntion.\n
    2.47  			    These enumeration values are used with WPARAM parameter of the message.\n 
    2.48  			    For more information, see the explanation of each notification code below*/
    2.49 -    public enum DSPNotifyCode : uint
    2.50 +    public enum DSPNotifyCode : int
    2.51      {
    2.52  	    /**DSPNM_PLUGIN_SUCCEED
    2.53  	    @brief	When API succeeds to get the control for the display, API will post caller-specified message with DSPNM_PLUGIN_SUCCEED as WPARAM parameter.\n
    2.54 @@ -345,17 +349,17 @@
    2.55               */
    2.56          }
    2.57  
    2.58 -        private void Init(IntPtr aHWND)
    2.59 +        public void Init(IntPtr aHWND)
    2.60          {
    2.61 -            //iIMON_Display_Init
    2.62 +            iIMON_Display_Init(aHWND, SoundGraph.WM_DSP_PLUGIN_NOTIFY);
    2.63          }
    2.64  
    2.65 -        private void Uninit()
    2.66 +        public void Uninit()
    2.67          {
    2.68              iIMON_Display_Uninit();
    2.69          }
    2.70  
    2.71 -        private void SetText(string aUpperLine, string aLowerLine)
    2.72 +        public void SetText(string aUpperLine, string aLowerLine)
    2.73          {
    2.74  
    2.75          }
    2.76 @@ -379,5 +383,42 @@
    2.77          {
    2.78              get { return iSoundGraphDll!=IntPtr.Zero; }
    2.79          }
    2.80 +
    2.81 +        public void DisplayPluginMessage(int uErrCode, bool bError)
    2.82 +        {
    2.83 +	        if(bError)
    2.84 +	        {
    2.85 +                switch ((SoundGraph.DSPNInitResult)uErrCode)
    2.86 +		        {
    2.87 +                    case SoundGraph.DSPNInitResult.DSPN_ERR_IN_USED: 
    2.88 +                        Console.Write("Display Plug-in is Already Used by Other Application.\n"); break;
    2.89 +                    case SoundGraph.DSPNInitResult.DSPN_ERR_HW_DISCONNECTED: 
    2.90 +                        Console.Write("iMON HW is Not Connected."); break;
    2.91 +                    case SoundGraph.DSPNInitResult.DSPN_ERR_NOT_SUPPORTED_HW: 
    2.92 +                        Console.Write("The Connected iMON HW doesn't Support Display Plug-in.\n"); break;
    2.93 +                    case SoundGraph.DSPNInitResult.DSPN_ERR_PLUGIN_DISABLED: 
    2.94 +                        Console.Write("Display Plug-in Mode Option is Disabled.\n"); break;
    2.95 +                    case SoundGraph.DSPNInitResult.DSPN_ERR_IMON_NO_REPLY: 
    2.96 +                        Console.Write("The Latest iMON is Not Installed or iMON Not Running.\n"); break;
    2.97 +                    case SoundGraph.DSPNInitResult.DSPN_ERR_UNKNOWN: 
    2.98 +                        Console.Write("Unknown Failure.\n"); break;
    2.99 +		        }
   2.100 +    	    }
   2.101 +	        else
   2.102 +            {
   2.103 +                switch ((SoundGraph.DSPNotifyCode)uErrCode)
   2.104 +		        {
   2.105 +                    case SoundGraph.DSPNotifyCode.DSPNM_PLUGIN_SUCCEED: 
   2.106 +                        Console.Write("Plug-in Mode Inited Successfully.\n"); break;
   2.107 +                    case SoundGraph.DSPNotifyCode.DSPNM_IMON_RESTARTED: 
   2.108 +                        Console.Write("iMON Started and Plug-in Mode Inited.\n"); break;
   2.109 +                    case SoundGraph.DSPNotifyCode.DSPNM_HW_CONNECTED: 
   2.110 +                        Console.Write("iMON HW Connected and Plug-in Mode Inited.\n"); break;
   2.111 +		        }
   2.112 +	        }
   2.113 +	    
   2.114 +            //GetDlgItem(IDC_STATIC_INFO)->SetWindowText((LPCTSTR)strErrMsg);
   2.115 +        }
   2.116 +
   2.117      }
   2.118  }