Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get the handle to the window 1

Status
Not open for further replies.

tokool

Programmer
Nov 6, 2001
40
0
0
US
I am using ShellExecuteEx() to create a process.
How can get the handle to the window that it opened.
Atleast, is there a way to get the thread ID, so that i
can call the EnumThreadWindows proc.
I have to use ShellExecute, not CreateProcess, as i do not
have the name of the .exe, i only have the file(eg: "t.txt")
 
The API giude from defines the return of ShellExecute as "If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application. ", so the ShellExecuteEx is probably similar.
 
Yees, but i need to get a handle to the Window the application has opened.
How can i get the window handle from the application handle or the DDE handle.
 
Enumerate through the top-level windows, calling GetWindowThreadProcessId for each hWnd. When the ProcessId form this call matches the ProcessId returned from ShellExecuteEx then you've found the window you are looking for.
 
This won't work. GetWindowThreadProcessId returns a pid and that you can't compare with the hinst ShellExecute will return. Next try please.
 
Please read carefully before being patronising. I advised the use of shellexecuteex, which uses and fills in a SHELLEXECUTEINFO structure. One of the members of that structure is the process handle.
 
Use FindWindowEx(...), It will return a hwnd to the window you ask it to search for. If you are using the MFC, you can then use the following to create a CWnd Object

CWnd Var;
Var.Attach(hWndReturnedFromFindWindowEx);

There may be a better way but this is how I do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top