如何更改窗口从默认(|)垂直的光标形状闪烁到像dos(_)中使用的水平。
是否有一些好的function,照顾呢?
操作系统:win7
触摸屏隐藏光标
光标不改变自定义控制出口
自定义鼠标光标的阴影
多鼠标/鼠标/光标?
如何获得鼠标光标图标VS c + +
在Python上模拟鼠标点击
是否有可能自动反转gvim中的光标颜色或当前线颜色的颜色
如何获取terminal中的光标位置?
如何在插入模式下更改Vim文本指针大小?
移动鼠标光标在C#
这实际上被称为插入符 ,而不是游标 。 这可能是混淆来自何处,为什么寻找解决方案没有得到太多的使用。 NullPonyPointer的评论也反映了这种普遍的困惑。 SetCursor函数确实是你想要改变鼠标光标,但它不会改变插入符号。
幸运的是,有一整套Windows功能可以使用ShowCaret HideCaret : CreateCaret , ShowCaret , HideCaret , SetCaretPos和DestroyCaret 。 还有一些其他的操作闪烁时间,但我建议坚持用户的当前设置(这将是默认)。
首先,有一点背景。 我强烈建议阅读有关插入符号和使用插入符号的两个介绍性MSDN文章。 但是这里有一个简单的总结: 特别是目前有重点的窗口。 这个窗口可能会像文本框控件一样。 当窗户收到焦点时,它会创建一个可以使用的插入符号,然后当它失去焦点时,便会破坏它的插入符号。 很明显,如果你不手动做这些,你会收到默认的实现。
现在,示例代码。 因为我喜欢糖果机界面,所以我把它包装在一个函数中:
bool CreateCustomCaret(HWND hWnd,int width,int height,int x,int y) { // Create the caret for the control receiving the focus. if (!CreateCaret(hWnd,/* handle to the window that will own the caret */ NULL,/* create a solid caret using specified size */ width,/* width of caret,in logical units */ height)) /* height of caret,in logical units */ return false; // Set the position of the caret in the window. if (!SetCaretPos(x,y)) return false; // Show the caret. It will begin flashing automatically. if (!ShowCaret(hWnd)) return false; return true; }
然后,为了响应WM_SETFOCUS , EN_SETFOCUS或类似的通知,我会调用CreateCustomCaret函数。 为了响应WM_KILLFOCUS , EN_KILLFOCUS或其他类似的通知,我会调用DestroyCaret() 。
或者, CreateCustomCaret可以从位图创建插入符号。 我可能会提供以下重载:
bool CreateCustomCaret(HWND hWnd,HBITMAP hbmp,/* handle to the window that will own the caret */ hBmp,/* create a caret using specified bitmap */ 0,0)) /* width and height parameters ignored for bitmap */ return false; // Set the position of the caret in the window. if (!SetCaretPos(x,y)) return false; // Show the caret. It will begin flashing automatically. if (!ShowCaret(hWnd)) return false; return true; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。