C#:如何从资源文件加载光标?
private const uint OCR_NORMAL = 32512;
[DllImport("user32.dll")]
private static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll")]
private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref IntPtr pvParam, uint fWinIni);
private const uint SPI_SETCURSORS = 0x0057;
private const uint SPIF_UPDATEINIFILE = 0x01;
private const uint SPIF_SENDCHANGE = 0x02;
private static readonly IntPtr IDC_ARROW = new IntPtr(32512);
private static void SetDefaultCursor()
{
IntPtr cursorHandle = IDC_ARROW;
SystemParametersInfo(SPI_SETCURSORS, 0, ref cursorHandle, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
private void Btn_Click(object sender, EventArgs e)
{
System.IO.MemoryStream cursorMemoryStream = new System.IO.MemoryStream(Properties.Resources.文件名);
Cursor c = new Cursor(cursorMemoryStream);
//this.Cursor = c;
SetSystemCursor(c.Handle, OCR_NORMAL);
// 当不再需要自定义鼠标光标时,恢复默认鼠标光标
SetDefaultCursor();
}