コード例 #1
0
ファイル: frmMain.cs プロジェクト: z3nth10n/PCStats
        private void Form1_Load(object sender, EventArgs e)
        {
            bool existsKey = StartupManager.ExistsStartupKey(Program.appName),
                 isAdmin   = StartupManager.IsUserAdministrator();

            if (!StartupManager.CheckIfRunningUnderVsHost())
            {
                if (!existsKey)
                {
                    if (isAdmin)
                    {
                        StartupManager.AddApplicationToStartup(Program.appName);
                    }
                    else
                    {
                        StartupManager.RunAsAdmin();
                    }
                }
            }
            else
            {
                Console.WriteLine("Cannot run as an admin in vshost environment!");
            }

            m_GlobalHook = Hook.GlobalEvents();

            m_GlobalHook.MouseMoveExt += ExtMouseMoved;
            m_GlobalHook.KeyDown      += ExtKeyPress;

            /*foreach (var screen in Screen.AllScreens)
             * {
             *  // For each screen, add the screen properties to a list box.
             *  //listBox1.Items.Add("Device Name: " + screen.DeviceName);
             *  //listBox1.Items.Add("Bounds: " + screen.Bounds.ToString());
             *  //listBox1.Items.Add("Type: " + screen.GetType().ToString());
             *  //listBox1.Items.Add("Working Area: " + screen.WorkingArea.ToString());
             *  //listBox1.Items.Add("Primary Screen: " + screen.Primary.ToString());
             *  Console.WriteLine("Name: {0}", screen.DeviceName);
             *  Console.WriteLine("Bounds: {0}", screen.Bounds.ToString());
             *  Console.WriteLine("Working area: {0}", screen.WorkingArea.ToString());
             * }
             *
             * Console.WriteLine("({0}, {1})", ScreenSize.Width, ScreenSize.Height);
             * mouse = new int[ScreenSize.Width, ScreenSize.Height];*/

            DEVMODE vDevMode = new DEVMODE();
            int     i        = 0;

            /*while (EnumDisplaySettings(null, i, ref vDevMode))
             * {
             *  Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}",
             *                          vDevMode.dmPelsWidth,
             *                          vDevMode.dmPelsHeight,
             *                          1 << vDevMode.dmBitsPerPel, vDevMode.dmDisplayFrequency
             *                      );
             ++i;
             * }*/

            Timer1.Tick    += Timer1_Tick;
            Timer1.Interval = timerInterval;
            Timer1.Start();

            dpi = GetSystemDpi();

            //Console.WriteLine("Screen phys size: " + new Point(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height));
            Console.WriteLine("Screen phys size: " + GetScreenPhysicalSize());
            Console.WriteLine("DPI: " + dpi);
            Console.WriteLine("Mouse Speed: " + GetMouseSpeed());

            KeysManager.GetPositions();

            counting = true;
        }