there is a WinAPI function SetParent

HWND WINAPI SetParent( _In_ HWND hWndChild, _In_opt_ HWND hWndNewParent ); 

Return value

Type: HWND
If the function succeeds, the return value is the handle to the previous parent window.
If the function fails, the return value is NULL. For more information, call GetLastError.

I use pinvoke wrapper from the corresponding site.

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

How can I check that the function returned NULL ?

    1 answer 1

    Use IntPtr.Zero :

    When you call the Windows API from a managed code, you can pass IntPtr.Zero instead of null .
    ...
    You can also use the command line for Windows API to return the value from IntPtr.Zero . For example, you can retrieve the handle of a non-existent window. If it was a return code, IntPtr.Zero .

    MSDN

      public static void Main() { IntPtr hwnd = new IntPtr(3); IntPtr hOwner = GetWindow(hwnd, GW_OWNER); if (hOwner == IntPtr.Zero) Console.WriteLine("Window not found."); }