如何将当前使用的光标保存到流(资源或文件)中? [英] How can I save currently used cursor into the stream (resource or file)?

查看:161
本文介绍了如何将当前使用的光标保存到流(资源或文件)中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何将游标(当前是我的应用程序使用的,即使是自定义的还是动画的)保存到流或文件中,这样我就可以通过网络将其发送到另一台加载我的应用程序的计算机上并使用它?只是,我想从远程计算机克隆光标。

Does anyone know how to save the cursor (currently used by my application, even if it's custom or animated) into the stream or file, so that I'll be able to send it over network to another computer where my application load and use it ? Simply, I want to clone the cursor from a remote computer.

正如我在本文,大多数图标功能也可以用于游标,但是我找不到任何易于翻译的示例。 这是一个使用COM的示例,但我不确定 IPicture 接口也可用于游标。 此处例如,有关将图像保存到* .cur文件的讨论,但是我找不到适合于将游标保存和加载到流,资源中的东西,或者我可以通过网络发送并加载到目标上的东西计算机。

As I found in this article, most of icon functions can be used for cursors as well, but I can't find any easy to translate example. Here's one example using COM, but I'm not sure if the IPicture interface is useable also for cursors. Here for instance is the discussion about saving the image into the *.cur file, but I can't find anything suitable for saving and loading cursors into stream, resource or something what I'll be able to send over network and load on a target computer.

PS您可能会期望。

感谢任何建议

推荐答案

我认为 DrawIconEx 可能对帮助有所帮助有了这个。有了它,您可以简单地将整个光标图像绘制到某个画布上。也可以通过将指定的动画光标帧的索引传递到istepIfAniCur参数来绘制该帧。下面的示例演示如何将当前光标保存到流(Button1Click)中,然后将其加载回并显示(Button2Click)。

I think that DrawIconEx might be useful to help with this. With it you can simply draw the entire cursor image to a certain canvas. There is also possibility to draw the specified animated cursor frame by passing its index into the istepIfAniCur parameter. The following example shows how to save the current cursor into the stream (Button1Click) and load it back and display (Button2Click).

另一个问题是如何检测光标是否为动画

var
  Stream: TMemoryStream;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Stream := TMemoryStream.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Stream.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Picture: TPicture;
  CursorInfo: TCursorInfo;
begin
  Picture := TPicture.Create;

  CursorInfo.cbSize := SizeOf(CursorInfo);
  GetCursorInfo(CursorInfo);

  Picture.Bitmap.Transparent := True;
  Picture.Bitmap.Width := GetSystemMetrics(SM_CXCURSOR);
  Picture.Bitmap.Height := GetSystemMetrics(SM_CYCURSOR);

  DrawIconEx(
              Picture.Bitmap.Canvas.Handle, // handle to the target canvas
                                         0, // left coordinate
                                         0, // top coordinate
                        CursorInfo.hCursor, // handle to the current cursor
                                         0, // width, 0 for autosize
                                         0, // height, 0 for autosize
                                         0, // animated cursor frame index
                                         0, // flicker-free brush handle
                                  DI_NORMAL // flag for drawing image and mask
            );

  Picture.Bitmap.SaveToStream(Stream);
  Picture.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  Picture: TPicture;
begin
  Stream.Position := 0;

  Picture := TPicture.Create;
  Picture.Bitmap.Transparent := True;
  Picture.Bitmap.Width := GetSystemMetrics(SM_CXCURSOR);
  Picture.Bitmap.Height := GetSystemMetrics(SM_CYCURSOR);
  Picture.Bitmap.LoadFromStream(Stream);

  SetBkMode(Canvas.Handle, TRANSPARENT);
  Canvas.FillRect(Rect(0, 0, 32, 32));
  Canvas.Draw(0, 0, Picture.Graphic);

  Picture.Free;
end;

这篇关于如何将当前使用的光标保存到流(资源或文件)中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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