捕捉动画系统光标在Windows上显示的步骤

Capture which step of an animated system cursor is being shown on Windows

本文关键字:显示 Windows 动画 系统 光标      更新时间:2023-10-16

我想尽可能准确地将Windows操作系统上的系统光标捕获为位图。据我所知,为此提供的API是GetCursorInfo,DrawIconEx。

简单的行动链是:

  • 使用GetCursorInfo获取光标
  • 使用DrawIconEx在内存DC中绘制光标

以下是代码的大致外观。

CURSORINFO  CursorInfo;
(VOID)memset(&CursorInfo, 0, sizeof(CursorInfo));
CursorInfo.cbSize = sizeof(CursorInfo);
if (GetCursorInfo(&CursorInfo) &&
    CursorInfo.hCursor)
{
    // ... create here the memory DC, memory bitmap
    boError |= !DrawIconEx(hCursorDC,   // device context
        0,              // xLeft
        0,              // yTop
        CursorInfo.hCursor,     // cursor handle
        0,              // width, use system default
        0,              // height, use system default
        0,              // step of animated cursor !!!!!!!!!
        NULL,               // flicker free brush, don't use it now
        DI_MASK | DI_DEFAULTSIZE);  // flags
    // ... do whatever we want with the cursor in our memory DC
}

现在,有人知道我如何才能得到动画光标的哪一步正在绘制(我需要可以传递给DrawIconEx的istepIfAniCur参数的值…)?目前,上面的代码显然总是只呈现动画光标的第一步。

我怀疑这不是一件容易的事,但无论如何都值得一问。

遗憾的是,我认为没有Windows API公开光标动画的当前帧。我想这就是你想要的:在你制作快照的那一刻光标的外观。

我怀疑您遗漏了一个步骤。

你需要创建一个位图来选择你的设备上下文,否则你的位图只是一个像素。

请参阅MSDN文档中的CreateCompatibleBitmap:

HBITMAP创建兼容位图(HDC HDC,//DC句柄int nWidth,//位图的宽度,以像素为单位int nHeight//位图的高度,以像素为单位);

使用DrawIconEx,UINT istepIfAniCur参数允许您选择要绘制的帧(如果它是动画光标)。

它在你的评论中说:

0,//动画光标的步长