GetActiveWindow()并不总是返回活动窗口吗?

| 我正在制作一个使用
Control.MouseButtons
GetActiveWindow()
的游戏,如下所示:
        Private Declare Auto Function GetActiveWindow Lib \"user32.dll\" () As IntPtr

        Public Sub GetMouseState(ByRef x As Integer, ByRef y As Integer, ByRef lButton As Boolean)
            Dim p As Point = Parent.PointToClient(Windows.Forms.Cursor.Position)
            x = p.X
            y = p.Y
            lButton = _
                (Control.MouseButtons And MouseButtons.Left) = MouseButtons.Left AndAlso _
                 Parent.Handle = GetActiveWindow()
        End Sub
Parent
Form
。) 不过,最奇怪的事情发生了。在我的游戏的第一个“场景”(菜单)中,它可以正常工作。在第二个(实际游戏)中,它似乎不起作用。最奇怪的事情发生了:我可以测试此方法是否可以在render方法中工作:
    Dim down As Boolean
    Game.GetMouseState(0, 0, down)
    If down Then g.Clear(Color.Red)
确实,当我单击鼠标时,屏幕变为红色。但是,我的对象不会移动。当我取下ѭ6支票时,我的物体确实移动了!这是该代码,尽管可能并不重要:
    Dim mouseX, mouseY As Integer, mouseDown As Boolean
    Game.GetMouseState(mouseX, mouseY, mouseDown)

    If mouseDown Then
        Dim mouseLocation As New PointF(mouseX - Game.Width \\ 2, mouseY - Game.Height \\ 2)

        centerParticle.MoveTowards(mouseLocation, centerParticle.Location)
    End If
仅当我的游戏运行时,GetActiveWindow()才会返回正确的值吗? :P     
已邀请:
没有足够的代码尝试对此问题进行再现。只是不要这样做。实现该窗体的Deactivate事件的处理程序,您的游戏循环应停止更新所有内容。包括鼠标轮询。使用Activate事件再次启用它。     

要回复问题请先登录注册