Exemple #1
0
        /// <summary>
        /// Captures an Oculus Mirror screenshot.
        /// </summary>
        private void CaptureScreenshot()
        {
            Process[] processes = Process.GetProcessesByName("GalGun2-Win64-Shipping");
            Process   proc      = null;

            if (processes.Length > 0)
            {
                proc = processes[0];
            }
            else
            {
                return;
            }
            var rect = new WindowRect();

            APIMethods.GetClientRect(proc.MainWindowHandle, ref rect);

            int width  = rect.Right - rect.Left;
            int height = rect.Bottom - rect.Top;

            Bitmap   bmp       = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            Graphics graphics  = Graphics.FromImage(bmp);
            IntPtr   hdcBitmap = graphics.GetHdc();

            APIMethods.PrintWindow(proc.MainWindowHandle, hdcBitmap, 1);

            graphics.ReleaseHdc();
            graphics.Dispose();

            string picFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);

            try
            {
                string targetFolder = picFolder + @"\GG2VR";
                if (!Directory.Exists(targetFolder))
                {
                    Directory.CreateDirectory(targetFolder);
                }

                DateTime dt   = DateTime.Now;
                string   fn   = dt.ToString("yyyy-MM-dd_HH-mm-ss", CultureInfo.InvariantCulture);
                int      add  = 1;
                string   addS = "";
                while (File.Exists(targetFolder + "\\" + fn + addS + ".png"))
                {
                    add++;
                    addS = add.ToString();
                }
                bmp.Save(targetFolder + "\\" + fn + addS + ".png", ImageFormat.Png);
            } catch (Exception ex)
            {
                //Apparently I'm not allowed to write the library. Ah well.
            }
        }