Good evening everyone So sorry for my mediocre english
I have a question about the SetParent API. When I run the window on Windows 10, it works correctly and contains any program I want
But when the program is executed on Windows 11, it does nothing, and Notepad, for example, runs normally and belongs to the desktop, and not to the container in my window.
This is what I am currently using:
Public Class WindowsApiSetAnyWindowParent
Public Declare Function SetParent Lib "user32.dll" (
ByVal hWndChild As IntPtr,
ByVal hWndNewParent As IntPtr
) As IntPtr
Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongPtrA" (
ByVal hwnd As IntPtr,
ByVal nIndex As Integer,
ByVal dwNewLong As Long
) As Long
Public Declare Function MoveWindow Lib "user32.dll" (
ByVal hwnd As IntPtr,
ByVal x As Integer,
ByVal y As Integer,
ByVal cx As Integer,
ByVal cy As Integer,
ByVal repaint As Boolean
) As Boolean
Public Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (
ByVal hwnd As IntPtr,
ByVal Msg As UInteger,
ByVal wParam As Long,
ByVal lParam As Long
) As Boolean
Public Const SWP_NOOWNERZORDER As Integer = &H200
Public Const SWP_NOREDRAW As Integer = &H8
Public Const SWP_NOZORDER As Integer = &H4
Public Const SWP_SHOWWINDOW As Integer = &H40
Public Const WS_EX_MDICHILD As Integer = &H40
Public Const SWP_FRAMECHANGED As Integer = &H20
Public Const SWP_NOACTIVATE As Integer = &H10
Public Const SWP_ASYNCWINDOWPOS As Integer = &H4000
Public Const SWP_NOMOVE As Integer = &H2
Public Const SWP_NOSIZE As Integer = &H1
Public Const GWL_STYLE As Integer = -16
Public Const WS_VISIBLE As Integer = &H10000000
Public Const WM_CLOSE As Integer = &H10
Public Const WS_CHILD As Integer = &H40000000
End Class
So i called:
Dim TheNotePad As ProcessStartInfo = New ProcessStartInfo("notepad.exe")
TheNotePad.WindowStyle = ProcessWindowStyle.Minimized
Dim TheProcess As Process = Process.Start(TheNotePad)
TheProcess.WaitForInputIdle()
WindowsApiSetAnyWindowParent.SetParent(TheProcess.MainWindowHandle, HostTabPanel.Handle)
WindowsApiSetAnyWindowParent.SetWindowLong(TheProcess.MainWindowHandle, WindowsApiSetAnyWindowParent.GWL_STYLE, WindowsApiSetAnyWindowParent.WS_VISIBLE)
WindowsApiSetAnyWindowParent.MoveWindow(TheProcess.MainWindowHandle, 0, 0, HostTabPanel.Width, HostTabPanel.Height, True)
TheNotePad.WindowStyle = ProcessWindowStyle.Normal
Many thanks for any help