我想在使用编码的ui进行自动化运行期间获取鼠标光标的屏幕截图。 [英] I want to take the screenshot of the mouse cursor during automation run using coded ui.

查看:54
本文介绍了我想在使用编码的ui进行自动化运行期间获取鼠标光标的屏幕截图。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2015编码的UI来自动化我的应用程序。我想捕捉一个带有鼠标光标的窗口。任何人都可以拥有或完成这种类型的鼠标光标捕获场景。



请帮助



问候,

Ranjit



我尝试过:



当前我使用in build功能尝试了很多方法。但是我无法捕获鼠标光标。

I am using Visual studio 2015 coded UI for automating my application. I want capture an window with mouse cursor on it. Could any one have or done this type of mouse cursor capture scenario.

Please help

Regards,
Ranjit

What I have tried:

Current I have tried many method using the in build functionality. But I was not able to capture mouse cursor.

推荐答案

在这里你去:



Here you go:

[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
    public Int32 cbSize;
    public Int32 flags;
    public IntPtr hCursor;
    public POINTAPI ptScreenPos;
}

[StructLayout(LayoutKind.Sequential)]
struct POINTAPI
{
    public int x;
    public int y;
}

[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);

[DllImport("user32.dll")]
static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);

const Int32 CURSOR_SHOWING = 0x00000001;

public static Bitmap CaptureScreen(bool CaptureMouse)
{
    Bitmap result = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format24bppRgb);

    try
    {
        using (Graphics g = Graphics.FromImage(result))
        {
            g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            if (CaptureMouse)
            {
                CURSORINFO pci;
                pci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(CURSORINFO));

                if (GetCursorInfo(out pci))
                {
                    if (pci.flags == CURSOR_SHOWING)
                    {
                        DrawIcon(g.GetHdc(), pci.ptScreenPos.x, pci.ptScreenPos.y, pci.hCursor);
                        g.ReleaseHdc();
                    }
                }
            }
        }
    }
    catch
    {
        result = null;
    }

    return result;
}


这篇关于我想在使用编码的ui进行自动化运行期间获取鼠标光标的屏幕截图。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆