Creating a Process with ShellExecuteEx

< BACK  NEXT >
[oR]

On Windows CE, CreateProcess has limited functionality since most of the parameters are not supported. In particular, a STARTUPINFO structure cannot be passed to the function, so you do not have much control on how the process is created. However, you can use the shell function ShellExecuteEx to start a process, as long as your Windows CE platform supports the standard shell. The function can be used to open documents. For example, you may specify that "mydocument.pwd" should be started, and ShellExecuteEx will automatically launch Pocket Word and open the document. Further, different verbs can be applied to the document, such as "open", "print", and so on so that different operations can be performed on the document. Finally, you can specify how the application will be displayed using any of the constants supported by the ShowWindow function.

The ShellExecuteEx is passed a pointer to a SHELLEXECUTEINFO structure which is initialized to contain the required options for launching the application. In Listing 5.2 the user is prompted for an application or document to open, and the SHELLEXECUTEINFO structure is initialized and passed to ShellExecuteEx.

Listing 5.2 Creates a process with ShellExecuteEx
 void Listing5_2(HWND hWnd) {   SHELLEXECUTEINFO sei;   TCHAR szApplication[MAX_PATH];   if(!GetTextResponse(_T("Enter Application to Run:"),         szApplication, MAX_PATH))     return;   memset(&sei, 0, sizeof(sei));   sei.cbSize = sizeof(sei);   sei.hwnd = hWnd;   sei.lpVerb = _T("open");   sei.lpFile = szApplication;   sei.lpParameters = NULL;   sei.nShow = SW_SHOWNORMAL;   if(ShellExecuteEx(&sei) == 0)     cout   _T("Error calling ShellExecuteEx:")            GetLastError() endl; }  

Many of the members in the SHELLEXECUTEINFO structure are unused in Windows CE. Further, an instance handle to the new application should be returned, but this is not the case on all platforms. Table 5.2 lists the relevant members.

Table 5.2. SHELLEXECUTEINFO Relevant structure members
Structure Member Purpose
DWORD cbSize Size of the structure in bytes.
HWND hwnd Handle of a window to act as a parent for any dialogs shown by ShellExecuteEx.
LPCSTR lpVerb Verb to use, for example, "open", "print", "edit".
LPCSTR lpFile Executable file or document name.
LPCSTR lpParameters Parameters to be passed to an application.
int nShow How to display the application. Constants such as SW_HIDE and SW_SHOWNORMAL from the ShowWindow function can be used.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net