Click here to Skip to main content
15,895,538 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello friends!

I need to execute existing EXE file within a window form. but Exe will not show outside of the window. if i minimize the exe, it will minimize in a same window.. is this possible? please help me......
Posted
Updated 1-Apr-11 2:33am
v3

C#
// import needed functions from user32 lib
[DllImport("user32.dll")] 
public static extern int SetParent(IntPtr hWndChild , IntPtr hWndNewParent);
[DllImport("user32.dll")]
public static extern int SendMessage (IntPtr hWnd , int Msg , int wParam , int lParam);


// variables used to call teh functions
const int WM_SYSCOMMAND = 274;
const int SC_MAXIMIZE = 61488;

// defining the process and initilize it's attributes
Process p=new Process();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false; 

//starting notepad and put it within the form           
p = Process.Start("NOTEPAD.EXE");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, this.Handle);            
SendMessage(p.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
 
Share this answer
 
v2
Comments
satish49 7-Dec-13 1:24am    
I have to open skype window in a main window it is not coming i tried for notepad it is displaying in the mainwindow (within the window )where has skype it was opening on the another window .can any body help me
Member 12337813 15-Nov-16 3:58am    
How can i hidden those children process in parent app
No.

It isn't possible, without changing the EXE itself.
 
Share this answer
 
Comments
johannesnestler 1-Apr-11 8:54am    
Hmm, are you shure? I can think of some "tricks" like: Get the MainWindowHandle of the exe. Use SendMessage to resize (and maximize or minimize) or move the window to create the "integrated" effect. But I never tried it.. Do you think this won't work?
OriginalGriff 1-Apr-11 9:00am    
Not well - the OP clearly wants to treat the exe as if it were a MDI child, hence the minimise in the same window reference.
I could be wrong, I've been so before!
johannesnestler 1-Apr-11 9:08am    
I read the OPs desire like you did. but something is in the backyard of my mind... And it was something to Tab other process windows (like a browser). Damn, if I could just remember... Allow me to state it like this (you are well known here): If OriginalGriff has no idea - it's maybe possible - but not easy for shure! :-)
Sergey Alexandrovich Kryukov 1-Apr-11 16:28pm    
This is basically true, my 5.

John, by saing "whithout changing the .EXE" you leave for some remote possibility. It means, there are exclusions: the cases where the EXE files to be run is already built to the requirements you might impose. So, for some special applications, it is *remotely* possible. (Yes, I understand my note is trivial.)

Another possibility is if the EXE is .NET assembly. There is a remote possibility to use it as a library (through Reflection) and run in the caller's process. Also, a limited sub-set of applications will comply.

Main point is: its't pretty hard to achieve smoothly and hardly can make sense. The fact is that is a pretty popular CodeProject Question rather indicate poor understanding of programming my most Inquirers.

--SA
OriginalGriff 2-Apr-11 3:25am    
Hi SA! Out of interest, have you seen this post: http://www.codeproject.com/Messages/3841469/A-big-thank-you-to-SAKryukov.aspx
I think you are definitely in for MVP next Jan! Well done! I have never seen Chris post anything like that before - you have seriously impressed him!
Flash opens out the form ...
Full screen
I have it close by ... alt f4
How do I open a Flash file in Form ?
Flash extension is
It Executive
Like a flash game
 
Share this answer
 
v2
C#
public partial class Flash_Quran : Form
    {
        [DllImport("USER32.DLL")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        [DllImport("USER32.dll")]
        private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

        public Flash_Quran()
        {
            InitializeComponent();
        }

        private void Flash_Quran_Load(object sender, EventArgs e)
        {
            Process process = Process.Start("QuranFull.exe");
            process.WaitForInputIdle();
            SetParent(process.MainWindowHandle, this.panel1.Handle);
            MoveWindow(process.MainWindowHandle, 0, 0, this.Width - 90, this.Height, true);
        }
    }

this code use
 
Share this answer
 
Сбой метода WaitForInputIdle. Это может быть связано с отсутствием у процесса графического интерфейса.
 
Share this answer
 
Comments
CHill60 29-Sep-14 13:44pm    
This is an English language site and this is not a solution

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