【问题标题】:Remove titlebar from window. Window process started by different user从窗口中删除标题栏。不同用户启动的窗口进程
【发布时间】:2016-07-20 21:04:28
【问题描述】:

我正在使用此代码(在 windows 2003 上)来删除和调整窗口大小:

Process process = Process.GetProcessById(12121);

IntPtr mwh = process.MainWindowHandle;
SetWindowLong(mwh, GWL_STYLE, WS_VISIBLE);
ShowWindowAsync(mwh, 3);
SetWindowPos(mwh, new IntPtr(0), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);

和声明:

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

[DllImport("USER32.DLL")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

static readonly int GWL_STYLE = -16;
static readonly int SWP_NOMOVE = 0x2;
static readonly int SWP_NOSIZE = 0x1;
static readonly int SWP_FRAMECHANGED = 0x20;
static readonly int WS_VISIBLE = 0x10000000;

当我调整与我启动的进程关联的窗口大小时,一切正常。但是当我想对其他用户窗口执行此操作时,它什么也不做。 如何使它适用于其他用户窗口?

【问题讨论】:

    标签: c# windows-server-2003 titlebar


    【解决方案1】:

    由于用户界面特权隔离 (UIPI),此行为是 Windows Vista 及更高版本中的设计使然。如果您可以访问受控应用程序的源代码,则可以解决它。

    阅读此答案了解更多信息:https://stackoverflow.com/a/15445510

    【讨论】:

    • 我忘记写了,它在 windows 2003 上运行。
    【解决方案2】:

    process.MainWindowHandle 是一个 .NET 概念,在本机桌面应用程序中没有主窗口之类的东西,因此可能无法在其他进程上始终正常工作。您应该检查mwh是否为IntPtr.Zero,如果是则需要使用EnumWindows + GetWindowThreadProcessId + IsWindowVisible 找到应用程序窗口。

    在您没有创建的窗口上调用SetWindowLong(mwh, GWL_STYLE, WS_VISIBLE); 是不行的。您需要先调用GetWindowLong 以获取现有样式remove all the styles you don't want 并添加WS_POPUP。您可能还想删除一些扩展样式。

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多