C # Embed other programs into your program

Source: Internet
Author: User

Write a XXX chat robot ah What may be used in this technology.
such as the QQ form embedded in their own WinForm
In fact, it is simple to call two API functions.

1[DllImport ("User32.dll", EntryPoint ="SetParent")]2 Private Static externIntPtr SetParent (IntPtr hwndchild, IntPtr hwndnewparent);3  4[DllImport ("user32.dll", EntryPoint ="ShowWindow")]5  Public Static extern intShowWindow (INTPTR hwnd,intnCmdShow);

Call:

1Process p =NewProcess ();2p.StartInfo.FileName ="Cmd.exe";3P.startinfo.windowstyle = System.Diagnostics.ProcessWindowStyle.Minimized;//Set Program Style4 P.start ();5SetParent (P.mainwindowhandle, This. Handle);//Change the parent window handle of p to this program handle6ShowWindow (P.mainwindowhandle,3);//the first parameter window handle, and the second parameter specifies how the window is displayed

Parameter two API prototype:
sw_forceminimize: Minimizes the window in WindowNT5.0, even if the owning window's thread is suspended. This parameter is used only when minimizing windows from other threads.
sw_hide: Hides the window and activates other windows.
sw_maximize: Maximizes the specified window.
sw_minimize: Minimizes the specified window and activates the Next top-level window in the Z-order.
Sw_restore: Activates and displays the window. If the window is minimized or maximized, the system restores the window to its original size and position. When you restore the minimized window,ApplicationThis flag should be specified.
sw_show: Activates and displays the window in its original position at the original size.
Sw_showdefault: The display state is set according to the SW_FLAG flag specified in the STARTUPINFO structure, and the STARTUPINFO structure is passed to the CreateProcess function by the program that initiated the application.
sw_showmaximized: Activates the window and maximizes it.
sw_showminimized: Activates the window and minimizes it.
sw_showminnoactive: The window is minimized and the activation window remains active.
sw_showna: Displays the window in its original state. The activation window still remains active.
sw_shownoactivate: Displays the window with the last size and status of the window. The activation window still remains active.
Sw_shownormal: Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and size. This flag should be specified when the application displays the window for the first time.

Excerpt from: http://www.msdn5.com/thread-388-1-1.html

C # Embed other programs into your program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.