【问题标题】:Problems in setparent new cmd windows 10setparent new cmd windows 10中的问题
【发布时间】:2020-06-09 19:31:00
【问题描述】:

一段时间以来,我通过集成多选项卡创建了一个控制台应用程序(cmd 和 powershell)。我正在使用user32setparent 函数。除非我移动父窗口,否则一切正常。无法访问子窗口。它是可见的,但无法单击它。为了解决这个问题,必须将父窗口替换到原来的位置。我注意到这个“错误”只出现在新的 Windows 10 控制台中。

我不知道该怎么做。

(对不起我的英语不好,我是法国人)

【问题讨论】:

  • 请添加您的代码。 Reparenting windows 总是一个复杂的杂耍行为。我知道您的第一语言不是英语,但您能否再试一试 “除了我移动父窗口,无法访问子窗口,它可见但无法单击它之外,一切正常”我>
  • 在我看到一些代码之前帮不上忙...
  • 我用我的代码和图片发布回复以更清晰

标签: c# powershell cmd user32 setparent


【解决方案1】:

我终于找到了解决方案,没那么复杂,但我不明白为什么会这样。

解决方案:

[DllImport("user32.dll")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll")]
static extern long SetWindowLongA(IntPtr hWnd, int nIndex, long dwNewLong);

[DllImport("User32.Dll")]
static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

[DllImport("user32.dll")]
private static extern void RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, uint flags);

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

[DllImport("user32.dll")]
static extern bool EnableWindow(IntPtr hWnd, bool bEnable);

[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);


[... Code ...]


Process process = new Process();
process.StartInfo.FileName = pProcess;
process.StartInfo.Arguments = pArgs;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
process.EnableRaisingEvents = true;
process.Exited += new EventHandler((s, e) =>
{
    FermerOnglet(tabpage);
});

process.Start();
while (process.MainWindowHandle == (IntPtr)0)
{
}
SetParent(process.MainWindowHandle, metroPanel1.Handle);
SetWindowLongA(process.MainWindowHandle, -16, 0x80000000L);


[... Code ...]


RedrawWindow(CurrentOngletSelect.HandleProcess.MainWindowHandle, (IntPtr)0, (IntPtr)0,  0x0400/*RDW_FRAME*/ | 0x0100/*RDW_UPDATENOW*/ | 0x0001/*RDW_INVALIDATE*/);
MoveWindow(CurrentOngletSelect.HandleProcess.MainWindowHandle, 0, 0, metroPanel1.Width, metroPanel1.Height, true);
SetWindowPos(CurrentOngletSelect.HandleProcess.MainWindowHandle, (IntPtr)(-1), 0, 0, 0, 0, 0);
ShowWindow(CurrentOngletSelect.HandleProcess.MainWindowHandle, 5);
EnableWindow(CurrentOngletSelect.HandleProcess.MainWindowHandle, true);

【讨论】:

    【解决方案2】:

    我会尽力解释得更好。我在一个位置启动一个子窗口,如果我移动父窗口,子窗口将被停用。像这样:

    开始设置父子窗口...

    移动父窗口..

    问题出现了..

    代码如下:

    [DllImport("user32.dll")]
    private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
    
    [... Code ...]
    
    
    Process process = new Process();
    process.StartInfo.FileName = pProcess;
    process.StartInfo.Arguments = pArgs;
    process.EnableRaisingEvents = true;
    process.Exited += new EventHandler((s, e) =>
    {
        FermerOnglet(tabpage);
    });
    
    process.Start();
    while (process.MainWindowHandle == (IntPtr)0)
    {
    }
    SetParent(process.MainWindowHandle, metroPanel1.Handle);
    

    【讨论】:

      猜你喜欢
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      相关资源
      最近更新 更多