1

For some time, I have created a console application (cmd & powershell) by integrating the multi tab. I'm using the setparent function of user32. Everything works except when I move the parent window. It is impossible to access the child window. It is visible but impossible to click on it. To remedy this, the parent window must be replaced where it was. I noticed that this "bug" only appears with the new Windows 10 console.

I do not know how to do.

(Sorry for my bad English I'm French)

RBT
  • 24,161
  • 21
  • 159
  • 240
TheRake66
  • 11
  • 1
  • 2
    Please add your code. Reparenting windows is always a complicated juggling act. I realize your first language isn't English, but could you take another stab at *"Everything works except when I move the parent window, impossible to access the child window, it is visible but impossible to click on it"* – Flydog57 Feb 26 '20 at 00:50
  • Cant help till I see some code... – ArcSet Feb 26 '20 at 02:35
  • I post a response with my code and pictures to be clearer – TheRake66 Feb 26 '20 at 17:50

2 Answers2

0

I will try to explain better. I start a child window at a position, if I move the parent window, the child window will be deactivated. Like this :

Start set parent to child window... enter image description here

Move parent window.. enter image description here

And the problem appears..

Here is the code:

[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);
TheRake66
  • 11
  • 1
0

I finally found the solution, it was not that complicated but I did not understand why it did that.

Solution :

[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);
TheRake66
  • 11
  • 1