我想捕获屏幕,然后显示一个带有鼠标指针的矩形(就像shareX一样)。我正在使用以下代码获取前景窗口,然后制作矩形:
IntPtr activeWindow = GetForegroundWindow();
List<String> strListProcesses = new List<string>();
foreach (Process process in Process.GetProcesses())
{
if (activeWindow == process.MainWindowHandle)
{
RECT t21;
GetWindowRect(activeWindow , out t21);
this.Dispatcher.Invoke((Action)(() =>
{
rectangle.Stroke = Brushes.Red;
Canvas.SetLeft(rectangle, t21.Left);
Canvas.SetTop(rectangle, t21.Top);
rectangle.Width = t21.Right - t21.Left;
rectangle.Height = t21.Bottom - t21.Top;
rectangle.Margin = new
Thickness(t21.Left,t21.Top- 8, 0, 0);
rectangle.Visibility = Visibility.Visible;
}));
}}
我希望它像ShareX,CloudShare等一样实时显示矩形。我当前的工具运行良好,用于抓取屏幕,然后用户可以对其进行编辑。现在,我要添加此功能。我尽力找到解决方案,但是全部徒劳,因为我不了解如何检测窗口的z阶,然后获得特定区域的矩形。 在此先感谢您的帮助。