To show a remote window in a WinForm using C#, you can use the Windows API function "SetParent" to set the remote window as a child of a WinForm control. Here's an example code:

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace RemoteWindowDemo
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        private const int SWP_NOZORDER = 0x0004;
        private const int SWP_SHOWWINDOW = 0x0040;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Get the handle of the remote window, e.g. using Process.GetProcessesByName()
            IntPtr remoteWindowHandle = new IntPtr(0x12345678); // Replace with the actual handle

            // Set the remote window as a child of a WinForm control, e.g. a panel
            SetParent(remoteWindowHandle, panel1.Handle);

            // Adjust the position and size of the remote window to fit the panel
            // Note: This may require some trial and error to get the right values
            int x = 0, y = 0, width = panel1.ClientSize.Width, height = panel1.ClientSize.Height;
            SetWindowPos(remoteWindowHandle, IntPtr.Zero, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW);
        }
    }
}

In this example, we're using the "SetParent" function to set the remote window as a child of a WinForm panel control. Then, we're using the "SetWindowPos" function to adjust the position and size of the remote window to fit the panel. You may need to adjust the position and size values to fit your specific use case.

Note that this approach only works for windows that use the same graphics subsystem as the calling process (i.e. both the remote window and the WinForm must use GDI or both must use DirectX). If the remote window uses a different graphics subsystem, you may need to use a different approach such as capturing the remote window image and displaying it in the WinForm

c# how to show the remote window in the winform

原文地址: https://www.cveoy.top/t/topic/dxEx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录