Sometimes, we need to open another application in an app. I have done such a thing in the past few days, summarizing some things, I hope to share and communicate with everyone. Among them, there may be something wrong or walk the way, please ask everyone to give me an opinion! In addition, I have been learning multi-thread and multi-process, I look forward to finding some common progress!
Gossip less, or answer the topic. To start other applications in the app, 3 functions can be used, let me talk about them one by one (I open the ZEECALLS.EXE application under the D: / Program files / Zeecalls / directory):
1, WINEXEC
This function is the simplest, only two parameters, the prototype is as follows:
UINT WINEXEC (LPCSTR LPCMDLINE, / / Address of Command Line Uint Ucmdshow // WINDOW STYLE for New Application);
The method is as follows:
Winexec (_T ("D: // Program files // zeecalls // zeecalls.exe"), sw_showmaximized;
This sentence will open ZEECALLS.EXE in a maximized manner, you need to note that in the VC, '/' needs to be written in '//'.
2, Shellexecute
Shellexecute is flexible than Winexex, so the parameter is more, the prototype is as follows:
Hinstance shellexecute (hwnd hwnd, // parent window handle lpctstr lpoperts, // open mode lpctstr lpfile, // File name LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTIRECTORY, // File path INT NSHOWCMD);
Similarly, we can also open this function to open the files we need:
Shellexecute (NULL, _T ("Open"), _ T ("Zeecalls.exe"), NULL, _T ("D: // Program Files // Zeecalls //"), SW_SHOWNORMAL);
This sentence is to open ZEECALLS.EXE in normal display.
3, CREATEPROCESS
The above ways have realized the purpose of opening other applications in their own applications, however, we did not get enough information about new processes, and did not use too much means to control new processes. Details attribute, so if we want to achieve these purposes, we need to use the CreateProcess function, first take a look at the prototype of this function:
BOOL CREATEPROCESS (LPCTSTR LPAPPLICATIONNAME, // executing program LPTSTSTR LPCOMMANDLINE, / / Parameter row // The following two parameters describe the security properties of the created process and threads, if null uses the default security attribute LPSecurity_attributes lpprocessattributes, // process security attributes LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes BOOL bInheritHandles, // inheritance flag DWORD dwCreationFlags, // create a sign LPVOID lpEnvironment, // environment variable LPCTSTR lpCurrentDirectory, // run the initial directory of the process lPSTARTUPINFO lpStartupInfo, // for Setting various attributes when creating a sub-process LPPROCESS_INFORMATION LPPROCESSINFORMATION // Used to receive information after the process is created); in the above parameters, two comparison data structures: StartupInfo and Process_information. The definitions of these two structures are as follows:
TYPEDEF STRUCT _STARTUPINFO {/// si DWORD CB; // Structure length LPTSTSTSTSTSTRLESKTOP; / / Retain LPTSTR LPTITLE; // If the program process is the title DWRD DWX; // Window Size DWORD Dwy; // Window Coordinate DWORD DWXSIZE; // Window Width DWORD DWYSIZE; // Window Height DWORD DWXCOUNTCHARS; // Console window word symbol width DWORD DWYCOUNTCHARS; // Console window word symbol Height DWORD DWFILLATRIBUTE; // Console; Window Fill Mode DWORD DWFLAGS; // Create Tag Word WshowWindow; // Window Display Tag, like showWindow's tag word cbreserved2; // Reserved parameter lpbyte lpreserved2; // Reserved Parameters Handle HSTDINPUT; // Standard Enter Handle Handle HSTDOUTPUT; / / Standard output handle handle hstderror; // standard error handle} StartupInfo, * lpstartupinfo;
TYPEDEF STRUCT _PROCESS_INFORMATION {// pi Handle HProcess; // Procedure Handle Handle HThread; // Process Main Thread Handle DWord dword DWordID; // The ID DWORD DWTHREADID; // The main thread ID} process_information;
As an example, let's take a look at how to use createProcess to open the same file:
Process_information pi; startupinfo si; memset (& Si, 0, SIZEOF (Si)); Si.cb = SizeOf (Si); Si.WShowWindow = SW_SHOW; si.dwflags = startf_useshowwindow;
Bool Fret = CreateProcess ("D: // Program Files // zeecalls // zeecalls.exe", NULL, NULL, FALSE, NULL, NULL, NULL, NULL, & SI, & PI), can be seen, by several Different methods can be implemented in the application to open other applications, and the above methods may be a bit more troubles, so we need to choose our best to achieve our own goals according to different purposes!
Finally, I hope that everyone can give me more advice, because I am also a beginner, there are many places not very clear, some methods may be bent, this is needed to give me help!