//----------------------------------------------------------------------- // // Copyright © 2012 Nils Hammar. All rights reserved. // //----------------------------------------------------------------------- /* * Software to access vehicle information via the OBD-II connector. * * Copyright © 2012 Nils Hammar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Alternative licensing is possible, see the licensing document. * * The above text may not be removed or modified. */ namespace UserInterface.GUI.Popup { using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; using global::UserInterface.GUI.Popup.Herminator; /// /// The rude helper strikes again! /// public partial class Herman : Form { /// /// Index of page to display. /// private int basePage; /// /// Initializes a new instance of the class. /// /// Index of page to display. public Herman(int basePage) { this.basePage = basePage; this.InitializeComponent(); this.timer1.Enabled = true; } /// /// Handle mouse events. /// /// Event data. public void mouseAction(MouseEventArgs e) { if (e != null) { // drag the form without the caption bar // present on left mouse button if (e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessageW(this.Handle, 0xa1, (IntPtr)0x2, IntPtr.Zero); } } } /// /// Kick Timer 2 to start. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "goOn", Justification = "Reviewed.")] public void goOn() { this.timer2.Enabled = true; } #region Form Dragging API Support /// /// The SendMessage function sends a message to a window or windows. /// /// A handle to the window whose window procedure will receive the message. /// The message to be sent. /// Primary message-specific information. /// Secondary message-specific information. /// The return value specifies the result of the message processing; it depends on the message sent. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Reviewed.")] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] private static extern IntPtr SendMessageW(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); /// /// ReleaseCapture releases a mouse capture /// /// If the function succeeds, the return value is nonzero. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Reviewed.")] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool ReleaseCapture(); #endregion /// /// Timer 1 fired. /// /// Sending object. /// Event data. private void timer1_Tick(object sender, EventArgs e) { this.timer1.Enabled = false; UserControl content = null; switch (this.basePage) { case 0: content = new Intro(this); break; default: content = new Intro(this); break; } this.pictureBox2.Controls.Add(content); content.Location = new Point(76, 19); content.Show(); } /// /// Respond to the picture box mousedown event to /// drag the borderless form around (left click and drag) /// /// Sending object. /// Event data. private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { this.mouseAction(e); } /// /// Respond to the picture box mousedown event to /// drag the borderless form around (left click and drag) /// /// Sending object. /// Event data. private void pictureBox2_MouseDown(object sender, MouseEventArgs e) { this.mouseAction(e); } /// /// Timer 2 fired. /// /// Sending object. /// Event data. private void timer2_Tick(object sender, EventArgs e) { this.Dispose(); } } }