如何确定当前鼠标光标是否为动画
How do I determine if the current mouse cursor is animated?
是否有一种方法可以确定当前鼠标光标是否为动画
我正在寻找一种方法如何保存当前光标一段时间前。我发现DrawIconEx函数非常适合我的目的。不幸的是,我不知道如何确定当前光标是否为动画。我希望如果我设置istepIfAniCur参数为1,在静态光标的情况下,DrawIconEx返回False,但它真的忽略了这个参数并返回True,它不允许我在循环中使用它来获取静态光标以及动画中的所有帧。在动画的情况下,一个工作如预期的,所以当你离开范围与istepIfAniCur它返回False。
那么我如何发现HICON (HCURSOR)是动画光标呢?DrawIconEx如何确定光标是动画的?
Thanks to lot
我找到了一个解决方案-传递到DrawIconEx函数的istepIfAniCur参数的UINT的最大值。不可能有人创建4,294,967,295帧的动画光标(对于某些光标电影可能是可能的)
有了这个事实,你可以将这个值传递给DrawIconEx函数,如果光标是动画的(因为超出了帧范围),它将返回False,如果是静态的,它将返回True,因为它忽略了istepIfAniCur参数。您应该将0传递给diFlags参数,因为不需要绘制任何东西。
下面是Delphi的例子:
if not DrawIconEx(Canvas.Handle, 0, 0, hCursor, 0, 0, High(Cardinal), 0, 0) then
Caption := 'Cursor is animated ...'
else
Caption := 'Cursor is not animated ...';
因为我承诺c++标签这是我的翻译尝试
if (!DrawIconEx(this->Canvas->Handle, 0, 0, hCursor, 0, 0, UINT_MAX, NULL, 0))
this->Caption = "Cursor is animated ...";
else
this->Caption = "Cursor is not animated ...";
超出帧范围也由操作系统错误ERROR_INVALID_PARAMETER指示,当DrawIconEx失败时,您可以使用GetLastError函数检查。
最佳方式:
typedef HCURSOR(WINAPI* GET_CURSOR_FRAME_INFO)(HCURSOR, LPCWSTR, DWORD, DWORD*, DWORD*);
GET_CURSOR_FRAME_INFO fnGetCursorFrameInfo = 0;
HMODULE libUser32 = LoadLibraryA("user32.dll");
if (!libUser32)
{
return false;
}
fnGetCursorFrameInfo = reinterpret_cast<GET_CURSOR_FRAME_INFO>(GetProcAddress(libUser32, "GetCursorFrameInfo"));
if (!fnGetCursorFrameInfo)
{
return false;
}
DWORD displayRate, totalFrames;
fnGetCursorFrameInfo(hcursor, L"", 0, &displayRate, &totalFrames);
以下是Delphi中的示例(并尝试翻译为c++)我如何尝试使用GetIconInfo函数获得光标尺寸,但它不像我预期的那样工作。在动画光标的情况下,它总是返回一帧的宽度,所以似乎GetIconInfo根本不关心帧。还是我错了?
procedure TForm1.Timer1Timer(Sender: TObject);
var
IconInfo: TIconInfo;
CursorInfo: TCursorInfo;
Bitmap: Windows.TBitmap;
begin
CursorInfo.cbSize := SizeOf(CursorInfo);
GetCursorInfo(CursorInfo);
GetIconInfo(CursorInfo.hCursor, IconInfo);
if GetObject(IconInfo.hbmColor, SizeOf(Bitmap), @Bitmap) <> 0 then
begin
Caption := 'Cursor size: ' +
IntToStr(Bitmap.bmWidth) + ' x ' +
IntToStr(Bitmap.bmHeight) + ' px';
end;
DeleteObject(IconInfo.hbmColor);
DeleteObject(IconInfo.hbmMask);
end;
我的Visual c++尝试(注意,我不懂c++,也没有编译器:)
CString txt;
ICONINFO ii;
CURSORINFO ci;
BITMAP bitmap;
ci.cbSize = SizeOf(CURSORINFO);
GetCursorInfo(ci);
GetIconInfo(ci.hCursor, ii);
GetObject(ii.hbmColor, sizeof(BITMAP), &bitmap);
txt.Format("Cursor width: %d px", bitmap.bmWidth);
MessageBox(txt);
- 在提升multi_index容器中,是否定义了"default index"?
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 检查输入是否不是整数或数字
- 是否可以初始化不可复制类型的成员变量(或基类)
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 此代码是否违反一个定义规则
- 是否需要删除包含对象的"pair"?
- 是否可以从int转换为enum类类型
- 无论条件是否为true,if总是在c++中执行
- 如何找到大小'x'数组是否完全填充,在C++?
- 检查值是否在集合p1和p2中,但不在p3中
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 检查 std::shared_ptr<> 的当前底层类型是否为 T
- 如何检测是否在缓冲绘画动画中绘制最后一帧?
- 是否可以在QT GUI应用程序中处理事件时播放加载动画指示器?
- 是否可以创建编码的动画壁纸
- 我是否在 WinApi 中正确执行动画
- 如何确定当前鼠标光标是否为动画