Home > Net >  Consult: winform form embedded forms of third-party applications
Consult: winform form embedded forms of third-party applications

Time:11-27

, good afternoon, as shown in the topic, I certainly can do some window when fiddling with embedded in my winform inside, such as the following:
There is a button and winform to add a panel controls, the code is as follows:
 
using System;
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Diagnostics;
Using System. Drawing;
Using System. Linq;
Using System. The Runtime. InteropServices;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;

The namespace WindowsFormsApp5
{
Public partial class Form1: Form
{
[DllImport (" User32. DLL, "EntryPoint=" SetParent ")]
Private static extern IntPtr SetParent (IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport (" user32. DLL, "EntryPoint=" ShowWindow ")]
Public static extern int ShowWindow (IntPtr HWND, int nCmdShow);


Public _click ()
{
InitializeComponent ();
}

Private void button1_Click (object sender, EventArgs e)
{
The Process of p=new Process ();
P. tartInfo. FileName="CMD";
P. tartInfo. WindowStyle=System. Diagnostics. ProcessWindowStyle. Minimized;
P. tart ();
System. Threading. Thread. Sleep (500);
SetParent (p. ainWindowHandle, panel1. Handle);
ShowWindow (p. ainWindowHandle, 3);
}

}
}



After clicking on the button can indeed for display and operation, but I have following questions, and hope to run: as I said hope
1, open the CMD in the first place in the System, according to the table before he comes to my winform, inside can put System. Threading. Thread. Sleep here (500) of 500 to 2000, this will see more clearly, I hope it's a specified program is original in my winform, instead of running in the System first, then put into the winform;
2, a program execution if changing video path, so the picture is jammed, confused problems, here is the lack of any statement, or something wrong?
3, if I am in winform CMD of executing a program, this program will come out in desktop, rather than in my winform, solving how

CodePudding user response:

If you don't try to hook, intercept WM_CREATE message handler, form created not shown, get window handle immediately,
  •  Tags:  
  • C#
  • Related