"隐藏"系统光标 [英] "Hiding" System Cursor

查看:157
本文介绍了"隐藏"系统光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:




  • 我试图创造一个老鼠藏的应用程序,一组后,从屏幕隐藏用户的鼠标的时间。

  • 我试过很多东西,并且使用的 的setCursor只从当前应用程序隐藏鼠标,矿井必须能够在盘(例如)坐下来,仍然起作用。

  • 我想我已经发现SetSystemCursor的解决方案只有一个问题



我的问题:




  • 我需要能够捕捉到任何类型的鼠标光标,并更换完全相同的那种鼠标光标。

  • 当更换鼠标,我需要提供我想通过手柄引用的鼠标来代替鼠标的类型的ID,但没有我使用的功能,为我提供了复制的鼠标的ID(或类型)。



我的问题:




  • 将它足以继续做这种方式,但将鼠标移动到0,0第一,隐藏它,并移回后,取消隐藏到它原来的位置?

  • (取消隐藏,通过简单地移动鼠标来实现)请问鼠标在0,0永远是一个OCR_NORMAL鼠标? (该标准的箭头。)

  • 如果没有,怎么可以在鼠标类型/ ID被找到,让我用正确的手柄更换相应的鼠标?



来源:



 函数[DllImport(user32.dll中) ] 
公共静态外部的IntPtr LoadCursorFromFile函数(字符串lpFileName的对象);
函数[DllImport(user32.dll中)]
公共静态外部布尔SetSystemCursor(IntPtr的HCUR,UINT ID);
函数[DllImport(user32.dll中)]
静态外部布尔GetCursorInfo(出PCI cursorinfo段);

[StructLayout(LayoutKind.Sequential)]
公共结构POINT
{
公众的Int32 X;
公众的Int32ÿ;
}

[StructLayout(LayoutKind.Sequential)]
关于cursorinfo结构
{
公众的Int32 CBSIZE; //指定大小,以字节为单位的结构。
//调用者必须将其设置为Marshal.SizeOf(typeof运算(cursorinfo段))。
公众的Int32标志; //指定游标状态。此参数可以是下列值之一:
// 0光标是隐藏的。
// CURSOR_SHOWING光标显示。
公众的IntPtr HCURSOR; //处理光标。
公共点ptScreenPos; //接收光标的屏幕坐标点的结构。
}

私人POINT cursorPosition;
私人的IntPtr cursorHandle;
私人布尔mouseVisible = FALSE;
私人常量UINT OCR_NORMAL = 32512;

//取得当前鼠标的,所以我们可以更换一次,我们想再次显示鼠标。
PCI cursorinfo段;
pci.cbSize = Marshal.SizeOf(typeof运算(的关于cursorinfo));
GetCursorInfo(出PCI);
cursorPosition = pci.ptScreenPos;
cursorHandle = CopyIcon(pci.hCursor);

//覆盖当前光标正常使用空白光标移动到隐藏了。
IntPtr的光标= LoadCursorFromFile函数(@./资源/光标/ blank.cur);
SetSystemCursor(光标,OCR_NORMAL);
mouseVisible = FALSE;

//处理...

//显示了我们在前面复制的鼠标手柄鼠标。
布尔RETVAL = SetSystemCursor(cursorHandle,OCR_NORMAL);
mouseVisible = TRUE;


解决方案

一个应用程序可以在不影响其他应用程序的光标。你必须写一些为了做到这一点的鼠标驱动程序。


BACKGROUND:

  • I'm trying to create a "mouse hiding" application that hides the user's mouse from the screen after a set amount of time.
  • I've tried many things, and using SetCursor only hides the mouse from the current application, mine must be able to sit in the tray (for example) and still function.
  • I think I've found a solution with SetSystemCursor except for one problem.

MY PROBLEM:

  • I need to be able to capture any kind of mouse cursor, and replace the exact same kind of mouse cursor.
  • When replacing the mouse, I need to provide the id of the type of mouse I'd like to replace with the mouse referenced by the handle, but none of the functions I'm using provide me with the copied mouse's id (or type).

MY QUESTION:

  • Would it be sufficient to continue doing it this way, but move the mouse to 0,0 first, hiding it, and moving it back to it's original location upon un-hiding? (Unhiding is accomplished by simply moving the mouse)
  • Would a mouse at 0,0 always be an OCR_NORMAL mouse? (The standard arrow.)
  • If not, how could the mouse type/id be found to enable me to replace the proper mouse with the proper handle?

SOURCE:

[DllImport("user32.dll")]
public static extern IntPtr LoadCursorFromFile(string lpFileName);
[DllImport("user32.dll")]
public static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public Int32 x;
public Int32 y;
}

[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public Int32 cbSize;        // Specifies the size, in bytes, of the structure. 
// The caller must set this to Marshal.SizeOf(typeof(CURSORINFO)).
public Int32 flags;         // Specifies the cursor state. This parameter can be one of the following values:
//    0             The cursor is hidden.
//    CURSOR_SHOWING    The cursor is showing.
public IntPtr hCursor;          // Handle to the cursor. 
public POINT ptScreenPos;       // A POINT structure that receives the screen coordinates of the cursor. 
}

private POINT cursorPosition;
private IntPtr cursorHandle;
private bool mouseVisible = false;
private const uint OCR_NORMAL = 32512;

//Get the current mouse, so we can replace it once we want to show the mouse again.
CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out pci);
cursorPosition = pci.ptScreenPos;
cursorHandle = CopyIcon(pci.hCursor);

//Overwrite the current normal cursor with a blank cursor to "hide" it.
IntPtr cursor = LoadCursorFromFile(@"./Resources/Cursors/blank.cur");
SetSystemCursor(cursor, OCR_NORMAL);
mouseVisible = false;

//PROCESSING...

//Show the mouse with the mouse handle we copied earlier.
bool retval = SetSystemCursor(cursorHandle, OCR_NORMAL);
mouseVisible = true;

解决方案

One application can't affect another applications cursor. You'd have to write a mouse driver of some sort in order to do this.

这篇关于"隐藏"系统光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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