Load an embedded animated Cursor from the Resource

前端 未结 2 1733
余生分开走
余生分开走 2021-01-24 22:18

I have an animated Cursor file (*.ani) in the resources and want to show it as a cursor in my application. How can I load it from the resources?

I looked up in the Inter

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 23:00

    Embed the ani file as a resource and use windows functions CreateIconFromResource to create it and DestroyIcon when done.

    IntPtr hCursor;
    try
    {
       hCursor = CreateIconFromResource(resource, (uint)resource.Length, false, 0x00030000);
       this.Cursor = new Cursor(hCursor);
       ...
    }
    finally
    {
       this.Cursor = Cursors.Normal;
       DestroyIcon(hCursor);
    }
    

提交回复
热议问题