更改窗口标题中的光标 [英] Change cursor in window caption
问题描述
我有一个WinForm,现在当它在Windows标题部分中时,我需要更改光标.我有一些代码在工作,它有2个问题:
I have a WinForm and now I need to change the cursor when it's in the windows caption part. I have some code working, it has 2 problems:
- <罢工>
当位于边缘时,它也会更改光标(应该显示正常的调整大小光标).
我发现我需要这样的
WM_NCHITTEST
&HTTOP
,但是我该如何结合呢? - 移动鼠标时会有一些闪烁.
It also changes the cursor when on the edges (normal resize cursor should be shown). I found out the I need something like thisWM_NCHITTEST
&HTTOP
, but how do I combine that?- There's some flicker when moving the mouse.
我还尝试将代码放置在base.WndProc(ref m);
下面.
I also tried placing the code below the base.WndProc(ref m);
.
这是我已经拥有的代码:
This is the code I already have:
if ((m.Msg == Win32.WM.NCMOUSEMOVE
|| m.Msg == Win32.WM.NCLBUTTONDOWN || m.Msg == Win32.WM.NCLBUTTONUP
|| m.Msg == Win32.WM.NCRBUTTONDOWN || m.Msg == Win32.WM.NCRBUTTONUP)
)
{
if (m.WParam.ToInt32() != Win32.HT.TOP && m.WParam.ToInt32() != Win32.HT.RIGHT && m.WParam.ToInt32() != Win32.HT.BOTTOM && m.WParam.ToInt32() != Win32.HT.LEFT)
{
Cursor = Cursors.Hand;
}
}
我没有在Spy ++中正确记录消息.找到了窗口边缘的解决方案(请参阅更新的代码).
I wasn't logging the message correctly in Spy++. Found the solution to the window edges (see updated code).
Thnx,J
推荐答案
它闪烁,因为您使用了错误的消息. WM_SETCURSOR跟随鼠标的任何移动,以允许应用更改光标.因此,光标会变回默认值.改为拦截WM_SETCURSOR. LParam的低位字包含点击测试代码.
It flickers because you use the wrong message. Any mouse move is followed by WM_SETCURSOR to allow the app to change the cursor. So the cursor changes back to the default. Intercept WM_SETCURSOR instead. The low word of LParam contains the hit test code.
protected override void WndProc(ref Message m) {
if (m.Msg == 0x20) { // Trap WM_SETCUROR
if ((m.LParam.ToInt32() & 0xffff) == 2) { // Trap HTCAPTION
Cursor.Current = Cursors.Hand;
m.Result = (IntPtr)1; // Processed
return;
}
}
base.WndProc(ref m);
}
这篇关于更改窗口标题中的光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!