我正在尝试将我的代码从WinForms转移到WPF,以更好地控制UI,但遇到了一些问题。
以下代码片段在WinForms中返回True,在WPF中返回False。我怀疑WPF面板对光标有影响,所以我尝试最小化启动应用程序,但仍然失败了。由于GetCursorInfo是PInvoke,我认为它在编程语言中应该是相同的。你有什么建议吗?
private CURSORINFO ci;
[StructLayout(LayoutKind.Sequential)]
public struct CURSORINFO
{
public Int32 cbSize; // Specifies the size, in bytes, of the structure.
public Int32 flags; // Specifies the cursor state.
public IntPtr hCursor; // Handle to the cursor.
Point point; // Should already marshal correctly.
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorInfo(ref CURSORINFO pci);
public MainWindow()
{
InitializeComponent();
ci = new CURSORINFO();
ci.cbSize = Marshal.SizeOf(ci);
MessageBox.Show(GetCursorInfo(ref ci).ToString());
}
Loaded
事件中吗? - rene