Go to ShellExecute
Translator: Xu Jingzhou (Original: nishant S)
Q: How to open an application?
ShellExecute (this-> m_hwnd, "open", "calc.exe", "", "", sw_show );
Or
ShellExecute (this-> m_hwnd, "open", "notepad.exe ",
"C: // mylog. log", "", sw_show );
As you can see, I haven't passed the full path of the programs.
Q: How do I open a file related to the same system program?
ShellExecute (this-> m_hwnd, "open ",
"C: // abc.txt", "", "", sw_show );
Q: How to open a webpage?
ShellExecute (this-> m_hwnd, "open ",
"Http://www.google.com", "", "", sw_show );
Q: How to activate related programs and send emails?
ShellExecute (this-> m_hwnd, "open ",
"Mailto: nishinapp@yahoo.com", "", "", sw_show );
Q: How do I print documents with a system printer?
ShellExecute (this-> m_hWnd, "print ",
"C: // abc.txt", "", "", SW_HIDE );
Q: How can I use the system search function to find a specified file?
ShellExecute (m_hWnd, "find", "d: // nish ",
NULL, NULL, SW_SHOW );
Q: How do I start a program until it finishes running?
SHELLEXECUTEINFO ShExecInfo = {0 };
ShExecInfo. cbSize = sizeof (SHELLEXECUTEINFO );
ShExecInfo. fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo. hwnd = NULL;
ShExecInfo. lpVerb = NULL;
ShExecInfo. lpFile = "c: // MyProgram.exe ";
ShExecInfo. lpParameters = "";
ShExecInfo. lpDirectory = NULL;
ShExecInfo. nShow = SW_SHOW;
ShExecInfo. hInstApp = NULL;
ShellExecuteEx (& ShExecInfo );
WaitForSingleObject (ShExecInfo. hProcess, INFINITE );
Or:
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo; // This is an [in] parameter
ZeroMemory (& StartupInfo, sizeof (StartupInfo ));
StartupInfo. cb = sizeof StartupInfo; // Only compulsory field
If (CreateProcess ("c: // winnt // notepad.exe", NULL,
NULL, NULL, FALSE, 0, NULL,
NULL, & StartupInfo, & ProcessInfo ))
{
WaitForSingleObject (ProcessInfo. hProcess, INFINITE );
CloseHandle (ProcessInfo. hThread );
CloseHandle (ProcessInfo. hProcess );
}
Else
{
MessageBox ("The process cocould not be started ...");
}
Q: How do I display attributes of a file or folder?
SHELLEXECUTEINFO ShExecInfo = {0 };
ShExecInfo. cbSize = sizeof (SHELLEXECUTEINFO );
ShExecInfo. fMask = SEE_MASK_INVOKEIDLIST;
ShExecInfo. hwnd = NULL;
ShExecInfo. lpVerb = "properties ";
ShExecInfo. lpFile = "c: //"; // can be a file as well
ShExecInfo. lpParameters = "";
ShExecInfo. lpDirectory = NULL;
ShExecInfo. nShow = SW_SHOW;
ShExecInfo. hInstApp = NULL;
ShellExecuteEx (& ShExecInfo );