// #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()); } }
public static string CaptureActiveWindow(string savingDirectory) { IntPtr hwnd = Win32Wrap.GetForegroundWindow(); return(DoCapture(hwnd, savingDirectory)); }
static void DoCapture() { IntPtr hwnd = Win32Wrap.GetForegroundWindow(); DoCapture(hwnd); }