Launching a console app then getting the handle of the window 
Author Message
 Launching a console app then getting the handle of the window

I want to write a program that launches an application with the main window
hidden but be able to show the window upon the user's request.

I have had success with GUI applicatins using CreateProcess(...) to launch
the application and EnumThreadWindows(...) to get the window handle but this
approach doesn't work for console programs.

I have come up with a solution but I want to get some feedback to find out
if there is a better way.
New Solution:
1) use ShellExecute(...) to launch the application
2) call EnumWindows(...)
3) in my EnumWindowsProc use GetWindowLong(...) to get the instance handle
of the current window and compare it with the one returned by
ShellExecute(...) to find the correct window handle.

My application takes the path of the app to launch as an argument so the
title of the new window may differ from time to time ruling out the use of
FindWindowEx(...) except as a replacement for EnumWindows(...) as a way of
enumerating the top level windows of  the class "ConsoleWindowClass".

Any suggestions are appreciated
Daniel



Mon, 21 Feb 2005 00:25:26 GMT  
 Launching a console app then getting the handle of the window
Can you call CreateProcess() like:

STARTUPINFO rStartupInfo = {0};
rStartupInfo.dwFlags = STARTF_USESHOWWINDOW;
rStartupInfo.wShowWindow = SW_HIDE;
CreateProcess(..., &rStartupInfo, ...);

or maybe:

CreateProcess(..., CREATE_NO_WINDOW, ...);


Quote:
> I want to write a program that launches an application with the main
window
> hidden but be able to show the window upon the user's request.

> I have had success with GUI applicatins using CreateProcess(...) to launch
> the application and EnumThreadWindows(...) to get the window handle but
this
> approach doesn't work for console programs.

> I have come up with a solution but I want to get some feedback to find out
> if there is a better way.
> New Solution:
> 1) use ShellExecute(...) to launch the application
> 2) call EnumWindows(...)
> 3) in my EnumWindowsProc use GetWindowLong(...) to get the instance handle
> of the current window and compare it with the one returned by
> ShellExecute(...) to find the correct window handle.

> My application takes the path of the app to launch as an argument so the
> title of the new window may differ from time to time ruling out the use of
> FindWindowEx(...) except as a replacement for EnumWindows(...) as a way of
> enumerating the top level windows of  the class "ConsoleWindowClass".

> Any suggestions are appreciated
> Daniel



Mon, 21 Feb 2005 04:29:37 GMT  
 Launching a console app then getting the handle of the window

Quote:

> Any suggestions are appreciated

How about:

1) Use ShellExecuteEx with SEE_MASK_NOCLOSEPROCESS to get the handle of
the new process

2) WaitForInputIdle to let the new process initialise

3) EnumWindows and check the process of each window with
GetWindowThreadProcessId

- Jim



Mon, 21 Feb 2005 08:16:08 GMT  
 Launching a console app then getting the handle of the window
That's just the solution I was looking for.

Thanks.


Quote:

> > Any suggestions are appreciated

> How about:

> 1) Use ShellExecuteEx with SEE_MASK_NOCLOSEPROCESS to get the handle of
> the new process

> 2) WaitForInputIdle to let the new process initialise

> 3) EnumWindows and check the process of each window with
> GetWindowThreadProcessId

> - Jim



Thu, 24 Feb 2005 16:51:18 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting console-based app output into a Windows view

2. Launching console aps from gui apps

3. problem launching dialog from console app

4. launching console app from mfc

5. Launch Console App Invisible

6. launching a console app from within a C# application

7. Console apps vs Windows Apps

8. Running a console app from a windows app

9. Need help converting a console app to windows app with a DLL

10. Getting window handle without matching window caption text

11. Getting a handle to a child window / Resizing a child window

12. Getting a handle to a window from the window instance

 

 
Powered by phpBB® Forum Software