Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible create new form c# as parent to existing application(example to MS excel)? Modelles form or modal

What I have tried:

Process[] processRunning = Process.GetProcesses();
foreach (Process pr in processRunning)
{
if (pr.ProcessName == "excel.exe")
{
hWnd = pr.MainWindowHandle.ToInt32();
ShowWindow(hWnd, SW_HIDE);
Posted
Updated 29-Oct-19 4:31am
Comments
Maciej Los 29-Oct-19 10:16am    
Why? What's for?

Keep in mind that the SetParent function will "reparent" the target window to make it appear inside your own control, like a Panel or Form,

...BUT, the application will behave exactly like it does on the Desktop. The user is still free to move the application window around inside your form, including clicking the Close, Minimize, and Maximize buttons.

YOU DO NOT HAVE COMPLETE CONTROL OVER THAT APPLICATION AND ITS BEHAVIOR.
 
Share this answer
 
SetParent function (winuser.h) | Microsoft Docs[^]
Never checked it on Excel or other complicated applications, but it should work...
C++
SetParent(pr.MainWindowHandle, [the handle of your window to put Excel into]);

Of course this code (yours) assumes that Excel running, you have to start it if not...
 
Share this answer
 
In addition to the excellent answer by Kornfeld, here is a C# example: Host a process window inside your applications window | Fluxbytes[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900