BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Running app on another desktop

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Daniel
Guest





PostPosted: Sun Mar 06, 2005 11:59 pm    Post subject: Running app on another desktop Reply with quote



I am attempting to spawn an application on another desktop (with the new
desktop visible, thereby hiding the default desktop).

For reference, the launching of the application is performed in a worker
thread, where this thread waits for the launched application to close
before it terminates, closing the desktop etc.

I can see my launched program running in Task Manager but the new desktop
is not made visible.

I'm currently using all access options until I can sort out where I am
going wrong.

I'd appreciate someone pointing me where I am going wrong. TIA.

Here is the code:

// temporary until I get this to work
#define DESKTOP_ALL ( DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW |
DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL |
DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS |
DESKTOP_SWITCHDESKTOP )

// temporary until I get this to work
#define WINSTA_ALL ( WINSTA_ACCESSCLIPBOARD | WINSTA_ACCESSGLOBALATOMS |
WINSTA_CREATEDESKTOP | WINSTA_ENUMDESKTOPS |
WINSTA_ENUMERATE |
WINSTA_EXITWINDOWS | WINSTA_READATTRIBUTES |
WINSTA_READSCREEN |
WINSTA_WRITEATTRIBUTES )



void __fastcall TSecondaryDesktopThread::Execute()
{

HWINSTA AWindowStation = ::CreateWindowStation("NewStation", NULL,
WINSTA_ALL, NULL);
::SetProcessWindowStation(AWindowStation);

HDESK ADesktop = ::CreateDesktop("NewDesktop", NULL, NULL, 0,
DESKTOP_ALL, NULL);

::SetThreadDesktop(ADesktop);
::SwitchDesktop(ADesktop);

AnsiString AppExe = "SecondDesktopApp.exe";
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwStatus;

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));

si.lpTitle = "NewDesktop";
si.lpDesktop = "NewStation\NewDesktop";

::CreateProcess(NULL, AppExe.c_str(), NULL, NULL, false,
NORMAL_PRIORITY_CLASS,
NULL, NULL, &si, &pi);

do
{
::GetExitCodeProcess(pi.hProcess, &dwStatus);
::Sleep(1);
} while( dwStatus == STILL_ACTIVE );


::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);

::CloseDesktop(ADesktop);
::CloseWindowStation(AWindowStation);
}


Daniel

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Back to top
Daniel
Guest





PostPosted: Mon Mar 07, 2005 12:15 am    Post subject: Re: Running app on another desktop Reply with quote



I have since read on another site that applications are only visible on
"WinSta0". After removing the code that creates another Windows Station,
my application is now visible. But I now have another problem.

In this launched application, I am trying to capture WM_QUERYENDSESSION
and WM_ENDSESSION via WndProc() to prevent the user from logging off. The
code works perfectly when running under the default desktop but the
messages are never received when running under the newly created desktop..

Any ideas how I can get this to work.

TIA.

Daniel.



On Mon, 07 Mar 2005 10:59:58 +1100, Daniel <d.jimenez (AT) comvision (DOT) net.au>
wrote:

Quote:
I am attempting to spawn an application on another desktop (with the new
desktop visible, thereby hiding the default desktop).

For reference, the launching of the application is performed in a worker
thread, where this thread waits for the launched application to close
before it terminates, closing the desktop etc.

I can see my launched program running in Task Manager but the new
desktop is not made visible.

I'm currently using all access options until I can sort out where I am
going wrong.

I'd appreciate someone pointing me where I am going wrong. TIA.

Here is the code:

[snip]


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Mar 07, 2005 6:24 am    Post subject: Re: Running app on another desktop Reply with quote




"Daniel" <d.jimenez (AT) comvision (DOT) net.au> wrote


Quote:
Here is the code:

At no point in that code are you doing any error checking at all. Nor do
you restore the previous desktop and workstation when your spawned process
is finished. Also, use WaitForSingleObject() instead of a sleeping loop to
wait for the spawned application to terminate.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Mar 07, 2005 6:24 am    Post subject: Re: Running app on another desktop Reply with quote


"Daniel" <d.jimenez (AT) comvision (DOT) net.au> wrote


Quote:
In this launched application, I am trying to capture WM_QUERYENDSESSION
and WM_ENDSESSION via WndProc() to prevent the user from logging off.
The code works perfectly when running under the default desktop but the
messages are never received when running under the newly created desktop.

Try having the spawned process call SetConsoleCtrlHandler() to receive
CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT notifications.


Gambit



Back to top
Daniel
Guest





PostPosted: Mon Mar 07, 2005 9:16 pm    Post subject: Re: Running app on another desktop Reply with quote

Hi Gambit,

I decided to strip the code to the bare bones for simplicity of code on
the post, I removed the WaitForSingleObject, as well as any error
checking, the restoring of the previous desktop is done in another
location.

Thanks

daniel.


On Sun, 6 Mar 2005 22:24:05 -0800, Remy Lebeau (TeamB)
<no.spam (AT) no (DOT) spam.com> wrote:

Quote:

"Daniel" <d.jimenez (AT) comvision (DOT) net.au> wrote in message
news:opsm8p981moyenhq (AT) development-ws2 (DOT) comvision.intranet...

Here is the code:

At no point in that code are you doing any error checking at all. Nordo
you restore the previous desktop and workstation when your spawned
process
is finished. Also, use WaitForSingleObject() instead of a sleeping loop
to
wait for the spawned application to terminate.


Gambit





--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Back to top
Daniel
Guest





PostPosted: Tue Mar 08, 2005 4:15 am    Post subject: Re: Running app on another desktop Reply with quote

Quote:
Try having the spawned process call SetConsoleCtrlHandler() to receive
CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT notifications.


Gambit

Thank you for your reply.


I understand that I can trap the CTRL_LOGOFF_EVENT and/or the
CTRL_SHUTDOWN_EVENT, but is it possible at this stage to stop the log off
and/or the shutdown from taking place? as I may have misunderstood the
HandlerRoutine I read at
http://msdn.microsoft.com/library/en-us/dllproc/base/handlerroutine.asp,
as it appears that all you can do is clean up prior to the event taking
place, that is the log off or shutdown.

They say:

"The CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT signals give the process
an opportunity to clean up before termination. A HandlerRoutine can
perform any necessary cleanup, then take one of the following actions:

(1) Call the ExitProcess function to terminate the process.
(2) Return FALSE. If none of the registered handler functions returns
TRUE, the default handler terminates the process.

Once more thank you for the help

danieL.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.