剪辑光标不起作用
我正在开发 DX11 游戏,我想在全屏模式下将光标剪辑到全屏窗口。我使用这种方法
void MyClass::_SetupCursor( BOOL bFullscreen ) {
// Clip cursor if requested
if( bFullscreen ) {
if(m_bShowCursorWhenFullscreen) {
ShowCursor(m_bShowCursorWhenFullscreen);
}
if(m_bClipCursorWhenFullscreen) {
// Confine cursor to full screen window
RECT windowRect;
GetWindowRect( m_hWnd, &windowRect );
ClipCursor( &windowRect );
}
}
else {
ShowCursor( TRUE );
ClipCursor( NULL );
}
}
但是,当我处于有 2 个显示器的全屏模式时,我仍然可以将鼠标移到另一个显示器上。在全屏模式下将分辨率设置为 2048x1152,我得到的窗口矩形为 1360x768,这就是它被剪切的值。我确认它是使用 GetClippedRect 进行裁剪的。
所以我有两个问题:
1)为什么鼠标没有被夹到我的窗口所在的监视器上?
2)当我知道显示器是2048x1152并且我将分辨率设置为2048x1152时,为什么窗口矩形测量为1360x768?
I am working on a DX11 game, and I want to clip the cursor during fullscreen mode to the fullscreen window. I use this method
void MyClass::_SetupCursor( BOOL bFullscreen ) {
// Clip cursor if requested
if( bFullscreen ) {
if(m_bShowCursorWhenFullscreen) {
ShowCursor(m_bShowCursorWhenFullscreen);
}
if(m_bClipCursorWhenFullscreen) {
// Confine cursor to full screen window
RECT windowRect;
GetWindowRect( m_hWnd, &windowRect );
ClipCursor( &windowRect );
}
}
else {
ShowCursor( TRUE );
ClipCursor( NULL );
}
}
However, when I am in fullscreen mode with 2 monitors, I can still move the mouse over to the other monitor. With resolution set to 2048x1152 in fullscreen mode, I get the window rectangle as 1360x768, and that is what it gets clipped to. I confirm that it is clipped using GetClippedRect.
So I have two questions:
1) Why isn't the mouse getting clipped to the monitor my window is in?
2) Why is the window rectangle measured as 1360x768 when I know for a fact the monitor is 2048x1152, and I have the resolution set to 2048x1152?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,要使 ClipCursor 正常工作,您必须确保所有 DX11 缓冲区和窗口大小正确。我通过首先在全屏模式下运行我的应用程序而不切换到它来发现这一点,并且 ClipCursor 工作得很好,即使在多个显示器上也是如此。有关 ClipCursor 何时失败的更多信息,请查看我在 stackoverflow 上的其他问题: 为什么在我的 DX11 游戏中加载 D3D10SDKLayers.dll? .
每当出现我在该问题中描述的情况时,ClipCursor 就会失败。另外,为了回答我的第二个问题,由于我在链接问题中描述的情况,窗口大小不正确。
It turns out that for ClipCursor to work, you must have all your DX11 buffers and your window size correct. I found this out by running my application in fullscreen first, without toggling into it, and ClipCursor worked just fine, even with multiple monitors. For more information on when ClipCursor will fail, check out my other question on stackoverflow: Why is D3D10SDKLayers.dll loaded during my DX11 game? .
ClipCursor will fail ever time the situations i describe in that question arise. Also, in response to my 2nd question, the window size is incorrect because of the situation I describe in the linked question.
不幸的是,根据文档的评论< /a> (由用户)看来这不适用于多监视器设置。您可能想要开发一种方法,在鼠标离开屏幕时重新定位鼠标,关闭其渲染,然后在将光标移回窗口时将其重新打开(以检测鼠标是否移出窗口或不,有 Windows 消息)。
Unfortunately according to a comment on the documentation (by a user) it appears that this does not work for multimonitor setups. You may want to develop a method that will reposition the mouse when it goes off screen, turns off the rendring for it, then turn it back on when you move the cursor back to the window (to detect if the mouse moves off the window or not, there is windows messages for that).