首页 文章

从窗口中删除 Headers 栏 . 窗口过程由不同的用户启动

提问于
浏览
0

我正在使用此代码(在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;

当我调整与我开始的过程相关的窗口时,一切正常 . 但是,当我想与其他用户窗口这样做时,它什么都不做 . 如何让它适用于其他用户的窗口?

2 回答

  • 0

    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 . 您可能还想删除一些扩展样式 .

  • 0

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

    请阅读此答案以获取更多信息:https://stackoverflow.com/a/15445510 .

相关问题