Running another application from C #

I am trying to run another application from a C # application, is there any way to show this application inside the main form of my application?

Thank,

+3
source share
4 answers

You can run other applications using Process.Start (...) :

Process.Start(@"C:\Path\OtherApp.exe");

To embed an application in your form, check out this CodeProject article that demonstrates how to place other application windows in your form.

+6
source

reparenting. . MSDN, WPF: Composite "shell" application.

WinForms. - . WS_CHILD. SetParent(), .

, Win32 . , WS_CHILD .

+1

:

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

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

    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

    [DllImport("user32.dll", SetLastError = true)]
    static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);

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


    private const int GWL_STYLE = (-16);
    private const int WS_VISIBLE = 0x10000000;
    private const int WS_MAXIMIZE = 0x01000000;

    private void Form1_Load(object sender, EventArgs e)
    {
        this.SuspendLayout();

        Process notepad = new Process();
        ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
        psi.WindowStyle = ProcessWindowStyle.Normal;
        notepad.StartInfo = psi;

        notepad.Start();

        this.ResumeLayout();

        notepad.WaitForInputIdle(3000);

        IntPtr old = SetParent(notepad.MainWindowHandle, this.Handle);

        SetWindowLong(notepad.MainWindowHandle, GWL_STYLE, WS_VISIBLE + WS_MAXIMIZE);
        MoveWindow(notepad.MainWindowHandle, 100, 100, 400, 400, true);

        SetActiveWindow(notepad.MainWindowHandle);
        SwitchToThisWindow(notepad.MainWindowHandle, true);  }

, "" ;)

+1

, - . , , GUI .

0

Source: https://habr.com/ru/post/1742244/


All Articles