Adding basic display functions: open, close, clear, fill, brightness control.
authorsl
Mon, 07 Jul 2014 21:32:02 +0200
changeset 371b55cfd8c05
parent 2 f516c3f656bf
child 4 0825370a7947
Adding basic display functions: open, close, clear, fill, brightness control.
Display.cs
MainForm.Designer.cs
MainForm.cs
SharpDisplayManager.csproj
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Display.cs	Mon Jul 07 21:32:02 2014 +0200
     1.3 @@ -0,0 +1,103 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Linq;
     1.7 +using System.Text;
     1.8 +using System.Threading.Tasks;
     1.9 +//
    1.10 +using System.Runtime.InteropServices;
    1.11 +using System.Text;
    1.12 +
    1.13 +namespace SharpDisplayManager
    1.14 +{
    1.15 +    class Display
    1.16 +    {
    1.17 +
    1.18 +        //Constructor
    1.19 +        public Display()
    1.20 +        {
    1.21 +            iDevice = IntPtr.Zero;
    1.22 +        }
    1.23 +
    1.24 +        //
    1.25 +        public bool Open()
    1.26 +        {
    1.27 +            if (iDevice == IntPtr.Zero)
    1.28 +            {
    1.29 +                iDevice = MiniDisplayOpen();                
    1.30 +            }
    1.31 +            return iDevice != IntPtr.Zero;
    1.32 +        }
    1.33 +
    1.34 +        public void Close()
    1.35 +        {
    1.36 +            MiniDisplayClose(iDevice);
    1.37 +            iDevice = IntPtr.Zero;
    1.38 +        }
    1.39 +
    1.40 +        public bool IsOpen()
    1.41 +        {
    1.42 +            return iDevice != IntPtr.Zero;
    1.43 +        }
    1.44 +
    1.45 +        public void Clear()
    1.46 +        {
    1.47 +            MiniDisplayClear(iDevice);
    1.48 +        }
    1.49 +
    1.50 +        public void Fill()
    1.51 +        {
    1.52 +            MiniDisplayFill(iDevice);
    1.53 +        }
    1.54 +
    1.55 +        public void SwapBuffers()
    1.56 +        {
    1.57 +            MiniDisplaySwapBuffers(iDevice);
    1.58 +        }
    1.59 +
    1.60 +        public int MaxBrightness()
    1.61 +        {
    1.62 +            return MiniDisplayMaxBrightness(iDevice);
    1.63 +        }
    1.64 +
    1.65 +        public int MinBrightness()
    1.66 +        {
    1.67 +            return MiniDisplayMinBrightness(iDevice);
    1.68 +        }
    1.69 +
    1.70 +        public void SetBrightness(int aBrightness)
    1.71 +        {
    1.72 +            if (!IsOpen()) return;
    1.73 +
    1.74 +            MiniDisplaySetBrightness(iDevice, aBrightness);
    1.75 +        }
    1.76 +
    1.77 +        //Our display device handle
    1.78 +        IntPtr iDevice;
    1.79 +
    1.80 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.81 +        public static extern IntPtr MiniDisplayOpen();
    1.82 +
    1.83 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.84 +        public static extern void MiniDisplayClose(IntPtr aDevice);
    1.85 +
    1.86 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.87 +        public static extern void MiniDisplayClear(IntPtr aDevice);
    1.88 +
    1.89 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.90 +        public static extern void MiniDisplayFill(IntPtr aDevice);
    1.91 +
    1.92 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.93 +        public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
    1.94 +
    1.95 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.96 +        public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
    1.97 +
    1.98 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.99 +        public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
   1.100 +
   1.101 +        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.102 +        public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
   1.103 +
   1.104 +
   1.105 +    }
   1.106 +}
     2.1 --- a/MainForm.Designer.cs	Mon Jun 16 12:18:46 2014 +0200
     2.2 +++ b/MainForm.Designer.cs	Mon Jul 07 21:32:02 2014 +0200
     2.3 @@ -37,11 +37,17 @@
     2.4              this.tabPageTests = new System.Windows.Forms.TabPage();
     2.5              this.fontDialog = new System.Windows.Forms.FontDialog();
     2.6              this.timer = new System.Windows.Forms.Timer(this.components);
     2.7 +            this.buttonOpen = new System.Windows.Forms.Button();
     2.8 +            this.buttonClose = new System.Windows.Forms.Button();
     2.9 +            this.buttonClear = new System.Windows.Forms.Button();
    2.10 +            this.buttonFill = new System.Windows.Forms.Button();
    2.11 +            this.trackBarBrightness = new System.Windows.Forms.TrackBar();
    2.12              this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
    2.13              this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
    2.14              this.tabControl.SuspendLayout();
    2.15              this.tabPageDisplay.SuspendLayout();
    2.16              this.tableLayoutPanel.SuspendLayout();
    2.17 +            ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit();
    2.18              this.SuspendLayout();
    2.19              // 
    2.20              // tabControl
    2.21 @@ -59,6 +65,11 @@
    2.22              // 
    2.23              // tabPageDisplay
    2.24              // 
    2.25 +            this.tabPageDisplay.Controls.Add(this.trackBarBrightness);
    2.26 +            this.tabPageDisplay.Controls.Add(this.buttonFill);
    2.27 +            this.tabPageDisplay.Controls.Add(this.buttonClear);
    2.28 +            this.tabPageDisplay.Controls.Add(this.buttonClose);
    2.29 +            this.tabPageDisplay.Controls.Add(this.buttonOpen);
    2.30              this.tabPageDisplay.Controls.Add(this.buttonCapture);
    2.31              this.tabPageDisplay.Controls.Add(this.tableLayoutPanel);
    2.32              this.tabPageDisplay.Controls.Add(this.buttonFont);
    2.33 @@ -87,7 +98,7 @@
    2.34              this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    2.35              this.tableLayoutPanel.Controls.Add(this.marqueeLabelTop, 0, 0);
    2.36              this.tableLayoutPanel.Controls.Add(this.marqueeLabelBottom, 0, 1);
    2.37 -            this.tableLayoutPanel.Location = new System.Drawing.Point(215, 165);
    2.38 +            this.tableLayoutPanel.Location = new System.Drawing.Point(180, 161);
    2.39              this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0);
    2.40              this.tableLayoutPanel.Name = "tableLayoutPanel";
    2.41              this.tableLayoutPanel.RowCount = 2;
    2.42 @@ -105,6 +116,14 @@
    2.43              this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.44              this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.45              this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.46 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.47 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.48 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.49 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.50 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.51 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.52 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.53 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
    2.54              this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
    2.55              this.tableLayoutPanel.TabIndex = 4;
    2.56              // 
    2.57 @@ -134,11 +153,62 @@
    2.58              this.timer.Interval = 50;
    2.59              this.timer.Tick += new System.EventHandler(this.timer_Tick);
    2.60              // 
    2.61 +            // buttonOpen
    2.62 +            // 
    2.63 +            this.buttonOpen.Location = new System.Drawing.Point(6, 6);
    2.64 +            this.buttonOpen.Name = "buttonOpen";
    2.65 +            this.buttonOpen.Size = new System.Drawing.Size(75, 23);
    2.66 +            this.buttonOpen.TabIndex = 6;
    2.67 +            this.buttonOpen.Text = "Open";
    2.68 +            this.buttonOpen.UseVisualStyleBackColor = true;
    2.69 +            this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
    2.70 +            // 
    2.71 +            // buttonClose
    2.72 +            // 
    2.73 +            this.buttonClose.Location = new System.Drawing.Point(6, 35);
    2.74 +            this.buttonClose.Name = "buttonClose";
    2.75 +            this.buttonClose.Size = new System.Drawing.Size(75, 23);
    2.76 +            this.buttonClose.TabIndex = 7;
    2.77 +            this.buttonClose.Text = "Close";
    2.78 +            this.buttonClose.UseVisualStyleBackColor = true;
    2.79 +            this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click);
    2.80 +            // 
    2.81 +            // buttonClear
    2.82 +            // 
    2.83 +            this.buttonClear.Location = new System.Drawing.Point(6, 64);
    2.84 +            this.buttonClear.Name = "buttonClear";
    2.85 +            this.buttonClear.Size = new System.Drawing.Size(75, 23);
    2.86 +            this.buttonClear.TabIndex = 8;
    2.87 +            this.buttonClear.Text = "Clear";
    2.88 +            this.buttonClear.UseVisualStyleBackColor = true;
    2.89 +            this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
    2.90 +            // 
    2.91 +            // buttonFill
    2.92 +            // 
    2.93 +            this.buttonFill.Location = new System.Drawing.Point(6, 93);
    2.94 +            this.buttonFill.Name = "buttonFill";
    2.95 +            this.buttonFill.Size = new System.Drawing.Size(75, 23);
    2.96 +            this.buttonFill.TabIndex = 9;
    2.97 +            this.buttonFill.Text = "Fill";
    2.98 +            this.buttonFill.UseVisualStyleBackColor = true;
    2.99 +            this.buttonFill.Click += new System.EventHandler(this.buttonFill_Click);
   2.100 +            // 
   2.101 +            // trackBarBrightness
   2.102 +            // 
   2.103 +            this.trackBarBrightness.BackColor = System.Drawing.SystemColors.Window;
   2.104 +            this.trackBarBrightness.Location = new System.Drawing.Point(470, 6);
   2.105 +            this.trackBarBrightness.Name = "trackBarBrightness";
   2.106 +            this.trackBarBrightness.Orientation = System.Windows.Forms.Orientation.Vertical;
   2.107 +            this.trackBarBrightness.Size = new System.Drawing.Size(45, 324);
   2.108 +            this.trackBarBrightness.TabIndex = 10;
   2.109 +            this.trackBarBrightness.TickStyle = System.Windows.Forms.TickStyle.Both;
   2.110 +            this.trackBarBrightness.Scroll += new System.EventHandler(this.trackBarBrightness_Scroll);
   2.111 +            // 
   2.112              // marqueeLabelTop
   2.113              // 
   2.114              this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
   2.115              this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
   2.116 -            this.marqueeLabelTop.Location = new System.Drawing.Point(1, -187);
   2.117 +            this.marqueeLabelTop.Location = new System.Drawing.Point(1, -313);
   2.118              this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
   2.119              this.marqueeLabelTop.Name = "marqueeLabelTop";
   2.120              this.marqueeLabelTop.OwnTimer = false;
   2.121 @@ -152,7 +222,7 @@
   2.122              // marqueeLabelBottom
   2.123              // 
   2.124              this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
   2.125 -            this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -61);
   2.126 +            this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -166);
   2.127              this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
   2.128              this.marqueeLabelBottom.Name = "marqueeLabelBottom";
   2.129              this.marqueeLabelBottom.OwnTimer = false;
   2.130 @@ -173,7 +243,9 @@
   2.131              this.Text = "Sharp Display Manager";
   2.132              this.tabControl.ResumeLayout(false);
   2.133              this.tabPageDisplay.ResumeLayout(false);
   2.134 +            this.tabPageDisplay.PerformLayout();
   2.135              this.tableLayoutPanel.ResumeLayout(false);
   2.136 +            ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).EndInit();
   2.137              this.ResumeLayout(false);
   2.138  
   2.139          }
   2.140 @@ -190,6 +262,11 @@
   2.141          private MarqueeLabel marqueeLabelBottom;
   2.142          private System.Windows.Forms.Button buttonCapture;
   2.143          private System.Windows.Forms.Timer timer;
   2.144 +        private System.Windows.Forms.Button buttonFill;
   2.145 +        private System.Windows.Forms.Button buttonClear;
   2.146 +        private System.Windows.Forms.Button buttonClose;
   2.147 +        private System.Windows.Forms.Button buttonOpen;
   2.148 +        private System.Windows.Forms.TrackBar trackBarBrightness;
   2.149      }
   2.150  }
   2.151  
     3.1 --- a/MainForm.cs	Mon Jun 16 12:18:46 2014 +0200
     3.2 +++ b/MainForm.cs	Mon Jul 07 21:32:02 2014 +0200
     3.3 @@ -14,10 +14,12 @@
     3.4      public partial class MainForm : Form
     3.5      {
     3.6          DateTime LastTickTime;
     3.7 +        Display iDisplay;
     3.8  
     3.9          public MainForm()
    3.10          {
    3.11              LastTickTime = DateTime.Now;
    3.12 +            iDisplay = new Display();
    3.13  
    3.14              InitializeComponent();
    3.15          }
    3.16 @@ -68,5 +70,37 @@
    3.17  
    3.18              LastTickTime = NewTickTime;
    3.19          }
    3.20 +
    3.21 +        private void buttonOpen_Click(object sender, EventArgs e)
    3.22 +        {
    3.23 +            if (iDisplay.Open())
    3.24 +            {
    3.25 +                trackBarBrightness.Minimum = iDisplay.MinBrightness();
    3.26 +                trackBarBrightness.Maximum = iDisplay.MaxBrightness();                
    3.27 +            }
    3.28 +            
    3.29 +        }
    3.30 +
    3.31 +        private void buttonClose_Click(object sender, EventArgs e)
    3.32 +        {
    3.33 +            iDisplay.Close();
    3.34 +        }
    3.35 +
    3.36 +        private void buttonClear_Click(object sender, EventArgs e)
    3.37 +        {
    3.38 +            iDisplay.Clear();
    3.39 +            iDisplay.SwapBuffers();
    3.40 +        }
    3.41 +
    3.42 +        private void buttonFill_Click(object sender, EventArgs e)
    3.43 +        {
    3.44 +            iDisplay.Fill();
    3.45 +            iDisplay.SwapBuffers();
    3.46 +        }
    3.47 +
    3.48 +        private void trackBarBrightness_Scroll(object sender, EventArgs e)
    3.49 +        {
    3.50 +            iDisplay.SetBrightness(trackBarBrightness.Value);
    3.51 +        }
    3.52      }
    3.53  }
     4.1 --- a/SharpDisplayManager.csproj	Mon Jun 16 12:18:46 2014 +0200
     4.2 +++ b/SharpDisplayManager.csproj	Mon Jul 07 21:32:02 2014 +0200
     4.3 @@ -48,6 +48,7 @@
     4.4    <ItemGroup>
     4.5      <Compile Include="CbtHook.cs" />
     4.6      <Compile Include="DialogBox.cs" />
     4.7 +    <Compile Include="Display.cs" />
     4.8      <Compile Include="MainForm.cs">
     4.9        <SubType>Form</SubType>
    4.10      </Compile>