To start another application in the application, there are 3 functions to use, and I'll talk about them (I'll open the Zeecalls.exe application in the D:\Program files\zeecalls\ directory for example):
1, WinExec
This function is the simplest, with only two parameters, and the prototype is as follows:
UINT WinExec (
LPCSTR lpCmdLine,//Address of command
UINT ucmdshow//window style for new application
);
Use the following methods:
WinExec (_t ("D:\\Program files\\zeecalls\\zeecalls.exe"), sw_showmaximized);
This will be the maximum way to open zeecalls.exe, it should be noted that in VC, '/' need to write with '//'.
2, ShellExecute
ShellExecute is a bit more flexible than winexex, so the parameters need to be a bit more, the prototype is as follows:
HInstance ShellExecute (
HWND hwnd,//parent window Handle
LPCTSTR lpoperation,//Open Mode
LPCTSTR lpfile,//file name to open
LPCTSTR lpparameters, lpctstr lpdirectory,//file path
INT nshowcmd);
Again, we can use this function to open the file we need:
ShellExecute (null,_t ("open"), _t ("Zeecalls.exe"), null,_t ("D:\\Program files\\zeecalls\\"), SW_SHOWNORMAL);
This is to open the Zeecalls.exe in normal display mode.
3, CreateProcess
Several of the above methods implement the purpose of opening other applications in our own applications, but we do not get enough information about the new process or use excessive means to control the details of the new process, so if you want to achieve these goals, We need to use the CreateProcess function, first look at the prototype of this function:
BOOL CreateProcess (
LPCTSTR Lpapplicationname,//Executive program name
LPTSTR lpcommandline,//Parameter row
The following two parameters describe the security properties of the processes and threads that are created and, if NULL, use the default security properties
Lpsecurity_attributes lpprocessattributes,//Process security ATTRIBUTES
Lpsecurity_attributes lpthreadattributes,//thread security ATTRIBUTES
BOOL binherithandles,//Inheritance flag
DWORD dwcreationflags,//Create flag
LPVOID lpenvironment,//environment variables
LPCTSTR Lpcurrentdirectory,//running the process's initial directory
Lpstartupinfo Lpstartupinfo,//For setting various properties when creating a child process
Lpprocess_information lpprocessinformation//For receiving information after a process is created
);
In the above parameters, two more important data structures are used: Startupinfo and process_information. The definitions of these two structures are as follows:
typedef struct _STARTUPINFO {//SI
DWORD CB; Structure length
LPTSTR lpreserved; Keep
LPTSTR lpdesktop; Keep
LPTSTR Lptitle; If the console process is a caption for the display
DWORD DwX; Window Horizontal axis
DWORD Dwy; Window Bundle coordinates
DWORD dwxsize; Window width
DWORD dwysize; Window height
DWORD Dwxcountchars; Console window character symbol width
DWORD Dwycountchars; Console window character symbol height
DWORD Dwfillattribute; Console window fill mode
DWORD dwflags; Create a tag
WORD Wshowwindow; The window displays the tag, as in ShowWindow
WORD CbReserved2; Retention parameters
Lpbyte LpReserved2; Retention parameters
HANDLE hStdInput; Standard input handle
HANDLE Hstdoutput; Standard output handle
HANDLE Hstderror; Standard error handle
} startupinfo, *lpstartupinfo;
typedef struct _PROCESS_INFORMATION {//PI
HANDLE hprocess; Process Handle
HANDLE Hthread; Main thread handle of the process
DWORD Dwprocessid; ID of the process
DWORD dwThreadID; Main thread ID of the process
} process_information;
As an example, let's 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);
You can see that through the several different methods above, you can implement the purpose of opening other applications in the application, some of these methods may be a bit cumbersome, so we need to choose the most suitable for their own way to achieve their goals.
Finally, I hope you can give me more advice, because I am also a beginner, there are many places are not very clear, some methods may be detours, which requires everyone to help me.