?
=?iso-8859-1?q?Carlos_M._P=E9rez?=
This email is regarding a March 15 article in CodeProject
(http://www.codeproject.com/netcf/UseSystemimagelist.asp).
I'm developing a kiosk application for Windows CE, using OpenNETCF.
Basically, the application has to launch other programs and be able to
switch to them and close them. Using OpenNETCF classes for processes I
can launch applications, but I can't manage them because I get the
handle for the process, NOT the window handle. And that's the one I
need for switching to and from applications.
In that article I've noticed an interesting way of launching
applications:
private void button1_Click(object sender, System.EventArgs e)
{
string FullPath=@"\windows\explorer.exe";
ShellExecuteInfo sei=new ShellExecuteInfo();
GCHandle hfile = GCHandle.Alloc((FullPath + '\0').ToCharArray(),
GCHandleType.Pinned);
sei.lpFile = (IntPtr)((int)hfile.AddrOfPinnedObject() + 4);
//windowstyle
sei.nShow = 1;
GCHandle hverb = new GCHandle();
hverb = GCHandle.Alloc(("Open"+'\0').ToCharArray(),
GCHandleType.Pinned);
sei.lpVerb = (IntPtr)((int)hverb.AddrOfPinnedObject() + 4);
bool ret=ShellExecuteEx(sei);
}
sealed class ShellExecuteInfo
{
public UInt32 cbSize = 60;
public UInt32 fMask = 0x00000040;
public IntPtr hwnd = IntPtr.Zero;
public IntPtr lpVerb = IntPtr.Zero;
public IntPtr lpFile = IntPtr.Zero;
public IntPtr lpParameters = IntPtr.Zero;
public IntPtr lpDirectory = IntPtr.Zero;
public int nShow = 0;
public IntPtr hInstApp = IntPtr.Zero;
public IntPtr lpIDList = IntPtr.Zero;
public IntPtr lpClass = IntPtr.Zero;
public IntPtr hkeyClass = IntPtr.Zero;
public UInt32 dwHotKey = 0;
public IntPtr hIcon = IntPtr.Zero;
public IntPtr hProcess = IntPtr.Zero;
}
The ShellExecuteInfo class contains an IntPtr variable called hWnd,
but of course it's initialized to IntPtr.Zero and not used by the
routine that launches the applications.
How could I retrieve the value of hWnd, just as the original author
retrieves the Verb and File? If this method of launching applications
could provide me
with the handle to the window just launched, it would be fine: I could
then use that handle to switch to the application, or kill it.
Thanks in advance.
Regards,
Carlos M Perez
(http://www.codeproject.com/netcf/UseSystemimagelist.asp).
I'm developing a kiosk application for Windows CE, using OpenNETCF.
Basically, the application has to launch other programs and be able to
switch to them and close them. Using OpenNETCF classes for processes I
can launch applications, but I can't manage them because I get the
handle for the process, NOT the window handle. And that's the one I
need for switching to and from applications.
In that article I've noticed an interesting way of launching
applications:
private void button1_Click(object sender, System.EventArgs e)
{
string FullPath=@"\windows\explorer.exe";
ShellExecuteInfo sei=new ShellExecuteInfo();
GCHandle hfile = GCHandle.Alloc((FullPath + '\0').ToCharArray(),
GCHandleType.Pinned);
sei.lpFile = (IntPtr)((int)hfile.AddrOfPinnedObject() + 4);
//windowstyle
sei.nShow = 1;
GCHandle hverb = new GCHandle();
hverb = GCHandle.Alloc(("Open"+'\0').ToCharArray(),
GCHandleType.Pinned);
sei.lpVerb = (IntPtr)((int)hverb.AddrOfPinnedObject() + 4);
bool ret=ShellExecuteEx(sei);
}
sealed class ShellExecuteInfo
{
public UInt32 cbSize = 60;
public UInt32 fMask = 0x00000040;
public IntPtr hwnd = IntPtr.Zero;
public IntPtr lpVerb = IntPtr.Zero;
public IntPtr lpFile = IntPtr.Zero;
public IntPtr lpParameters = IntPtr.Zero;
public IntPtr lpDirectory = IntPtr.Zero;
public int nShow = 0;
public IntPtr hInstApp = IntPtr.Zero;
public IntPtr lpIDList = IntPtr.Zero;
public IntPtr lpClass = IntPtr.Zero;
public IntPtr hkeyClass = IntPtr.Zero;
public UInt32 dwHotKey = 0;
public IntPtr hIcon = IntPtr.Zero;
public IntPtr hProcess = IntPtr.Zero;
}
The ShellExecuteInfo class contains an IntPtr variable called hWnd,
but of course it's initialized to IntPtr.Zero and not used by the
routine that launches the applications.
How could I retrieve the value of hWnd, just as the original author
retrieves the Verb and File? If this method of launching applications
could provide me
with the handle to the window just launched, it would be fine: I could
then use that handle to switch to the application, or kill it.
Thanks in advance.
Regards,
Carlos M Perez