首页 > 解决方案 > USER32 SetWindowPos 隐藏光标

问题描述

我正在尝试从我的控制台应用程序中使用 SetWindowPos定位窗口本身并且它可以工作,但是闪烁的光标消失了。我怎样才能避免它?

const int SWP_NOZORDER = 0x4;
const int SWP_NOACTIVATE = 0x10;

[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();

[DllImport("user32")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,int x, int y, int cx, int cy, int flags);

public static void SetWindowPosition(int x, int y, int width, int height)
{
    SetWindowPos(GetConsoleWindow(), IntPtr.Zero, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
}

void run()
{
   SetWindowPosition(0, 0, 300, 300);
}

标签: c#console-applicationuser32

解决方案


推荐阅读