Board index » Visual Studio » How to make a child process application active

How to make a child process application active

Visual Studio197
In application A, I create a local COM server. And in COM server process, I

create a new process application B. The result is that application B is not

active application. I tried to set the parameter STARTINFO, but it did not

work. When I attached to the COM server process for debugging, the

application B become acitve application after creation. So I guess if some

work is done for COM server process by attaching to it. Any clue is

appreciated.


-
 

Re:How to make a child process application active

"RobinZhou" wrote:

Quote
In application A, I create a local COM server. And in COM

server process, I

create a new process application B. The result is that

application B is not

active application. I tried to set the parameter

STARTINFO, but it did not

work. When I attached to the COM server process for

debugging, the

application B become acitve application after creation. So

I guess if some

work is done for COM server process by attaching to it.

Any clue is

appreciated.





Is application A foreground application? If yes, then you

could try to call AllowSetForegroundWindow for process B

from it. Then process B would bring itself to foreground.

Read more about foreground and background windows here:



"Window Features"

msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp">msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp



See "Foreground and Background Windows" section.





HTH

Alex





-

Re:How to make a child process application active





"Alex Blekhman" wrote:



Quote
"RobinZhou" wrote:

>In application A, I create a local COM server. And in COM

>server process, I

>create a new process application B. The result is that

>application B is not

>active application. I tried to set the parameter

>STARTINFO, but it did not

>work. When I attached to the COM server process for

>debugging, the

>application B become acitve application after creation. So

>I guess if some

>work is done for COM server process by attaching to it.

>Any clue is

>appreciated.





Is application A foreground application? If yes, then you

could try to call AllowSetForegroundWindow for process B

from it. Then process B would bring itself to foreground.

Read more about foreground and background windows here:



"Window Features"

msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp">msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp



See "Foreground and Background Windows" section.





HTH

Alex







Thanks for your reply. I tried AllowSetForegroundWindow , but it still did

not work.

BTW, the application B is C# application.

-

Re:How to make a child process application active

RobinZhou wrote:

Quote
>>In application A, I create a local COM server. And in COM

>>server process, I

>>create a new process application B. The result is that

>>application B is not

>>active application. I tried to set the parameter

>>STARTINFO, but it did not

>>work. When I attached to the COM server process for

>>debugging, the

>>application B become acitve application after creation. So

>>I guess if some

>>work is done for COM server process by attaching to it.

>>Any clue is

>>appreciated.

>

>Is application A foreground application? If yes, then you

>could try to call AllowSetForegroundWindow for process B

>from it. Then process B would bring itself to foreground.

>Read more about foreground and background windows here:

>

>"Window Features"

>msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp">msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp

>

>See "Foreground and Background Windows" section.

>

Thanks for your reply. I tried AllowSetForegroundWindow , but it still did

not work.

BTW, the application B is C# application.



AllowSetForegroundWindow itsef is not enough. Process A

should call AllowSetForegroundWindow with process ID of B

process. Then process B should call SetForegroundWindow.

-

Re:How to make a child process application active

"Alex Blekhman" wrote:



Quote
RobinZhou wrote:

>>>In application A, I create a local COM server. And in COM

>>>server process, I

>>>create a new process application B. The result is that

>>>application B is not

>>>active application. I tried to set the parameter

>>>STARTINFO, but it did not

>>>work. When I attached to the COM server process for

>>>debugging, the

>>>application B become acitve application after creation. So

>>>I guess if some

>>>work is done for COM server process by attaching to it.

>>>Any clue is

>>>appreciated.

>>

>>Is application A foreground application? If yes, then you

>>could try to call AllowSetForegroundWindow for process B

>>from it. Then process B would bring itself to foreground.

>>Read more about foreground and background windows here:

>>

>>"Window Features"

>>msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp">msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp

>>

>>See "Foreground and Background Windows" section.

>>

>Thanks for your reply. I tried AllowSetForegroundWindow , but it still did

>not work.

>BTW, the application B is C# application.



AllowSetForegroundWindow itsef is not enough. Process A

should call AllowSetForegroundWindow with process ID of B

process. Then process B should call SetForegroundWindow.





You mean I should use Enumwindow to enumerate windows in the COM server

process and set the window of application B as foreground window? it is a

hacking way, right? You know generally create a new process in one proces,

and the new process application is active. So I want to find the reason and

get a normal solution.

-

Re:How to make a child process application active

RobinZhou wrote:

Quote
You mean I should use Enumwindow to enumerate windows in the COM server

process and set the window of application B as foreground window? it is a

hacking way, right? You know generally create a new process in one proces,

and the new process application is active. So I want to find the reason and

get a normal solution.



No, you should call AllowSetForegroundWindow in A process

with ID of B process. Then in B process (not COM server

process) call .NET equivalent of SetForegroundWindow to

bring main window of B process to foreground.



Process A just gives up its right to be foreground in favor

of process B. But process B still needs to do the work to

bring itself to foreground. However, if process A wasn't

foreground in first place, then it doesn't have the right to

be foreground, therefore it can't transfer this right to

other processes, as well. Read more about it in the MSDN

article by the link I posted earlier.

-

Re:How to make a child process application active





"Alex Blekhman" wrote:



Quote
RobinZhou wrote:

>You mean I should use Enumwindow to enumerate windows in the COM server

>process and set the window of application B as foreground window? it is a

>hacking way, right? You know generally create a new process in one proces,

>and the new process application is active. So I want to find the reason and

>get a normal solution.



No, you should call AllowSetForegroundWindow in A process

with ID of B process. Then in B process (not COM server

process) call .NET equivalent of SetForegroundWindow to

bring main window of B process to foreground.



Process A just gives up its right to be foreground in favor

of process B. But process B still needs to do the work to

bring itself to foreground. However, if process A wasn't

foreground in first place, then it doesn't have the right to

be foreground, therefore it can't transfer this right to

other processes, as well. Read more about it in the MSDN

article by the link I posted earlier.



Thanks for your patient respondence. Application B is not developed by me.

If I create a process for application B in application A directly not via

the local COM server process, application B is active. So I guess if it is

because of the local COM server is not a foreground process? Can we do some

work about it?

-

Re:How to make a child process application active

RobinZhou wrote:

Quote
>

>Process A just gives up its right to be foreground in favor

>of process B. But process B still needs to do the work to

>bring itself to foreground. However, if process A wasn't

>foreground in first place, then it doesn't have the right to

>be foreground, therefore it can't transfer this right to

>other processes, as well. Read more about it in the MSDN

>article by the link I posted earlier.

>

Thanks for your patient respondence. Application B is not developed by me.

If I create a process for application B in application A directly not via

the local COM server process, application B is active. So I guess if it is

because of the local COM server is not a foreground process? Can we do some

work about it?



Hm.. I don't know how to make COM server to become

foreground process, since COM server usually doesn't have

any GUI at all. Probably you could call AttachThreadInput

from process A (after AllowSetForegroundWindow) to attach to

main window's thread of process B and then try to call

SetForegroundWindow. However, it looks like hack and I'm not

sure it will work reliably.

-

Re:How to make a child process application active





"Alex Blekhman" wrote:



Quote
RobinZhou wrote:

>>

>>Process A just gives up its right to be foreground in favor

>>of process B. But process B still needs to do the work to

>>bring itself to foreground. However, if process A wasn't

>>foreground in first place, then it doesn't have the right to

>>be foreground, therefore it can't transfer this right to

>>other processes, as well. Read more about it in the MSDN

>>article by the link I posted earlier.

>>

>Thanks for your patient respondence. Application B is not developed by me.

>If I create a process for application B in application A directly not via

>the local COM server process, application B is active. So I guess if it is

>because of the local COM server is not a foreground process? Can we do some

>work about it?



Hm.. I don't know how to make COM server to become

foreground process, since COM server usually doesn't have

any GUI at all. Probably you could call AttachThreadInput

from process A (after AllowSetForegroundWindow) to attach to

main window's thread of process B and then try to call

SetForegroundWindow. However, it looks like hack and I'm not

sure it will work reliably.



I will try to set the priority class as PROCESS_MODE_BACKGROUND_END

by SetPriorityClass(). But it is very weird that web MSDN has this priority

class but local MSDN does not have.

msdn.microsoft.com/wn3/aspx/postui.aspx&guid=&sloc=en-us&dg=microsoft.public.vc.language&base=msdn.microsoft.com/newsgroups/default.aspx&bclr=ececec&fclr=000000&sxml=msdn.microsoft.com/newsgroups/site.xml&stgxml=msdn.microsoft.com/newsgroups/settings.xml&sdgloc=en-US&tt=2">msdn.microsoft.com/wn3/aspx/postui.aspx&guid=&sloc=en-us&dg=microsoft.public.vc.language&base=msdn.microsoft.com/newsgroups/default.aspx&bclr=ececec&fclr=000000&sxml=msdn.microsoft.com/newsgroups/site.xml&stgxml=msdn.microsoft.com/newsgroups/settings.xml&sdgloc=en-US&tt=2

-

Re:How to make a child process application active





"RobinZhou" wrote:



Quote




"Alex Blekhman" wrote:



>RobinZhou wrote:

>>>

>>>Process A just gives up its right to be foreground in favor

>>>of process B. But process B still needs to do the work to

>>>bring itself to foreground. However, if process A wasn't

>>>foreground in first place, then it doesn't have the right to

>>>be foreground, therefore it can't transfer this right to

>>>other processes, as well. Read more about it in the MSDN

>>>article by the link I posted earlier.

>>>

>>Thanks for your patient respondence. Application B is not developed by me.

>>If I create a process for application B in application A directly not via

>>the local COM server process, application B is active. So I guess if it is

>>because of the local COM server is not a foreground process? Can we do some

>>work about it?

>

>Hm.. I don't know how to make COM server to become

>foreground process, since COM server usually doesn't have

>any GUI at all. Probably you could call AttachThreadInput

>from process A (after AllowSetForegroundWindow) to attach to

>main window's thread of process B and then try to call

>SetForegroundWindow. However, it looks like hack and I'm not

>sure it will work reliably.

>

I will try to set the priority class as PROCESS_MODE_BACKGROUND_END

by SetPriorityClass(). But it is very weird that web MSDN has this priority

class but local MSDN does not have.

msdn.microsoft.com/wn3/aspx/postui.aspx&guid=&sloc=en-us&dg=microsoft.public.vc.language&base=msdn.microsoft.com/newsgroups/default.aspx&bclr=ececec&fclr=000000&sxml=msdn.microsoft.com/newsgroups/site.xml&stgxml=msdn.microsoft.com/newsgroups/settings.xml&sdgloc=en-US&tt=2">msdn.microsoft.com/wn3/aspx/postui.aspx&guid=&sloc=en-us&dg=microsoft.public.vc.language&base=msdn.microsoft.com/newsgroups/default.aspx&bclr=ececec&fclr=000000&sxml=msdn.microsoft.com/newsgroups/site.xml&stgxml=msdn.microsoft.com/newsgroups/settings.xml&sdgloc=en-US&tt=2

Sorry wrong web link. Update it.

windowssdk.msdn.microsoft.com/en-us/library/ms686219(VS.80).aspx">windowssdk.msdn.microsoft.com/en-us/library/ms686219(VS.80).aspx

-

Re:How to make a child process application active

RobinZhou wrote:

Quote
>Hm.. I don't know how to make COM server to become

>foreground process, since COM server usually doesn't have

>any GUI at all. Probably you could call AttachThreadInput

>from process A (after AllowSetForegroundWindow) to attach to

>main window's thread of process B and then try to call

>SetForegroundWindow. However, it looks like hack and I'm not

>sure it will work reliably.

>

I will try to set the priority class as PROCESS_MODE_BACKGROUND_END

by SetPriorityClass(). But it is very weird that web MSDN has this priority

class but local MSDN does not have.



No, PROCESS_MODE_BACKGROUND_END is not related to GUI at

all. It just changes amount of CPU cycles granted to the

process.



This constant is relatively new, that's why your local MSDN

doesn't mention it.

-

Re:How to make a child process application active





"Alex Blekhman" wrote:



Quote
RobinZhou wrote:

>>Hm.. I don't know how to make COM server to become

>>foreground process, since COM server usually doesn't have

>>any GUI at all. Probably you could call AttachThreadInput

>>from process A (after AllowSetForegroundWindow) to attach to

>>main window's thread of process B and then try to call

>>SetForegroundWindow. However, it looks like hack and I'm not

>>sure it will work reliably.

>>

>I will try to set the priority class as PROCESS_MODE_BACKGROUND_END

>by SetPriorityClass(). But it is very weird that web MSDN has this priority

>class but local MSDN does not have.



No, PROCESS_MODE_BACKGROUND_END is not related to GUI at

all. It just changes amount of CPU cycles granted to the

process.



This constant is relatively new, that's why your local MSDN

doesn't mention it.

Yup, you are right. if I just pop up a message box before creating the application B, it become active. So can I create a window and set it invisible before creating the application B and destroy the window after the process is created? Anyway, I need a way to solve this problem. It maks me crazy.

-

Re:How to make a child process application active

I think you should pass ID of process B (and may be main

window's handle, too) to process A. Then from process A to

make process B as foreground.





HTH

Alex

-

Re:How to make a child process application active





"Alex Blekhman" wrote:



Quote
I think you should pass ID of process B (and may be main

window's handle, too) to process A. Then from process A to

make process B as foreground.





HTH

Alex



Yup, maybe this is a way to solve this problem. But it is not method that I

want. communication between Process A and Process B is setup just by the

local COM server. So Process A cannot and should not communicate with process

B directly.

There is a weird thing that it works well on my machine with window 2003. I

don't know why. Is there any system info setting about it?

-

Re:How to make a child process application active

"RobinZhou" wrote:

Quote
>I think you should pass ID of process B (and may be main

>window's handle, too) to process A. Then from process A

>to

>make process B as foreground.

>

Yup, maybe this is a way to solve this problem. But it is

not method that I

want. communication between Process A and Process B is

setup just by the

local COM server. So Process A cannot and should not

communicate with process

B directly.

There is a weird thing that it works well on my machine

with window 2003. I

don't know why. Is there any system info setting about it?





Process A doesn't need to communicate with B. It's enough

that COM server process will pass B's process ID back to A.

Also, you can try to create process B in suspended state,

then from process A, after it gave to B foreground rights,

resume process B. I never tried it myself, though.



I don't know why it works on Window 2003. Probably it has

different implementation of windows manager.





HTH

Alex





-