Esempio n. 1
0
        // #tabPage2
        private void timer2_Tick(object sender, EventArgs e)
        {
            sp             = Cursor.Position;            // スクリーン座標の取得
            cp             = this.PointToClient(sp);     // クライアント座標に変換
            text21[0].Text = $"{sp.X.ToString()},{sp.Y.ToString()}";
            StringBuilder sb = new StringBuilder(65535); //65535に特に意味はない

            Win32Wrap.GetWindowText(Win32Wrap.GetForegroundWindow(), sb, 65535);
            text21[3].Text = $"{sb}";
            toolTip2.SetToolTip(text21[3], $"{sb}");             // ツールチップ更新

            IntPtr hWnd = Win32Wrap.GetForegroundWindow();       // 1. フォアグランドのウィンドウハンドルを取得
            int    id   = 0;

            try {
                Win32Wrap.GetWindowThreadProcessId(hWnd, ref id);                 // 2.ウィンドウハンドル→プロセスIDを取得
                text21[2].Text = Process.GetProcessById(id).ProcessName;          // プロセスID → プロセス名

                Win32Wrap.RECT windowRect = new Win32Wrap.RECT();
                // 3.ハンドル→ウインドウの見た目通りのRectを取得する
                // (GetWindowRectだと見た目とのズレがあるため、DwmGetWindowAttribute()を使用。)
                Win32Wrap.DwmGetWindowAttribute(hWnd, Win32Wrap.DWMWA_EXTENDED_FRAME_BOUNDS, ref windowRect, 4 * 4);
                int width  = windowRect.right - windowRect.left;
                int height = windowRect.bottom - windowRect.top;
                text21[1].Text = $"{((sp.X-windowRect.left).ToString())},{((sp.Y-windowRect.top).ToString())}";
                text21[4].Text = $"{width.ToString()}x{height.ToString()}";
                text21[5].Text = $"{windowRect.left.ToString()},{windowRect.top.ToString()}";
                text21[6].Text = $"{windowRect.right.ToString()},{windowRect.bottom.ToString()}";
                if (m_curId != id)
                {
                    text31[4].Text = Process.GetProcessById(id).ProcessName;
                    text31[5].Text = windowRect.left.ToString();
                    text31[6].Text = windowRect.top.ToString();
                    text31[7].Text = windowRect.right.ToString();
                    text31[8].Text = windowRect.bottom.ToString();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 2
0
        public static string DoCapture(IntPtr hwnd, string savingDirectory)
        {
            ScreenCapture sc = new ScreenCapture();

            // ファイル名決定
            string fname = "";
            string fpath = "";
            bool   ok    = false;

            for (int i = 0; i <= 99; i++)
            {
                fname = "capt_" + DateTime.Now.ToString("yyyyMMdd_HHmmss_") + i.ToString().PadLeft(2, '0') + ".png";
                fpath = Path.Combine(savingDirectory, fname);
                if (!File.Exists(fpath))
                {
                    ok = true;
                    break;
                }
            }

            if (ok)
            {
                // capture this window, and save it
                sc.CaptureWindowToFile(hwnd, fpath, ImageFormat.Png);

                // title取得
                StringBuilder title = new StringBuilder(1048);
                Win32Wrap.GetWindowText(hwnd, title, 1024);

                // ファイル名表示
                Debug.WriteLine("{0} ({1})", fname, title.ToString());

                // ファイル名を返す
                return(fpath);
            }
            else
            {
                throw new Exception("Failed to decide filename");
            }
        }
Esempio n. 3
0
        static void DoCapture(IntPtr hwnd)
        {
            ScreenCapture sc = new ScreenCapture();

            // ファイル名決定
            string fname = "";
            string fpath = "";
            bool   ok    = false;

            for (int i = 0; i <= 99; i++)
            {
                fname = "capt_" + DateTime.Now.ToString("yyyyMMdd_HHmmss_") + i.ToString().PadLeft(2, '0') + ".png";
                fpath = "C:\\_tmp\\" + fname;
                if (!File.Exists(fpath))
                {
                    ok = true;
                    break;
                }
            }
            if (ok)
            {
                // capture this window, and save it
                sc.CaptureWindowToFile(hwnd, fpath, ImageFormat.Png);

                // title取得
                StringBuilder title = new StringBuilder(1048);
                Win32Wrap.GetWindowText(hwnd, title, 1024);

                // ファイル名表示
                Console.WriteLine("{0} ({1})", fname, title.ToString());
            }
            else
            {
                Console.WriteLine("failed to decide filename");
            }
        }