Custom Shell that behaves as a desktop

  • Thread starter Thread starter Olie
  • Start date Start date
O

Olie

I tried posting this in a csharp forum but simply got bemusment as to
why I would want to do that. I thought the embedded forum might recieve
it better although not directly related to embedded.

I want to create a shell in c# that acts as a desktop but with my own
controls and buttons. I have no problem in creatting the shell and
getting it to stay behind all the other windows most of the time (I use
SetPosition to do this). The problem is that I can not force it to be
on the bottom all the time. On the odd ocassion it comes to the front
and makes it look like all the other windows have closed.

Does anyone know a method to force a window to always be on the bottom
or hijake the windows desktop so I can make my program behave as the
desktop?

Olie
 
Olie,
I'm not that proficient in C# but there is a way to do that via Win32 API
(so worst case you can think about writing an interop) - look for MSDN
documentation for CreateDesktop and SetProcessWindowStation calls. Again -
I'm not sure if there is a C# wrapper for that.
Thanks,
Oren
 
Thanks for your reply, I had come across CreateDesktop but not
CreateWindowStation. I have no problem with using Win API function in
C# so this was easy. Also read up on Window Stations which is a
fascinatting topic. I have been having a play with trying to create a
new desktop, switching to it for 10sec and then switching back. I am
struggling though because the new desktop is always created with the
standard desktop. I can not find any way to set my program to act as
the desktop.

I have pasted my code below, maybe you could tell me where I am going
wrong.

protected void CreatePearlExpertDesktop()
{
IntPtr WinStationHandle;
IntPtr DesktopHandle;

WinStationHandle =
Win32API.CreateWindowStation("PearlExpert", 0, 0, IntPtr.Zero);
if (WinStationHandle == IntPtr.Zero) throw new
Win32Exception(Marshal.GetLastWin32Error());

DesktopHandle =
Win32API.CreateDesktop("PearlExpertDesktop",IntPtr.Zero,IntPtr.Zero,0,Win32API.AccessRights,IntPtr.Zero);
if (DesktopHandle == IntPtr.Zero) throw new
Win32Exception(Marshal.GetLastWin32Error());

Win32API.SwitchDesktop(DesktopHandle);
Thread.Sleep(10000);


Win32API.SwitchDesktop(Win32API.OpenDesktop("default",0,true,Win32API.AccessRights));

Win32API.CloseDesktop(DesktopHandle);
Win32API.CloseWindowStation(WinStationHandle);

}
 
Olie,
From MSDN doc: CreateDesktop creates a new desktop on the window station
associated with the calling process. The calling process must have an
associated window station, either assigned by the system at process creation
time or set by SetProcessWindowStation.
You've created the window station but you didn't assign it to the calling
process - try to do that by calling SetProcessWindowStation.
Thanks,
Oren
 
Back
Top