×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

get the handle to the window

get the handle to the window

get the handle to the window

(OP)
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")

RE: get the handle to the window

The API giude from www.allapi.net 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.

RE: get the handle to the window

(OP)
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.

RE: get the handle to the window

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.

RE: get the handle to the window

This won't work. GetWindowThreadProcessId returns a pid and that you can't compare with the hinst ShellExecute will return. Next try please.

RE: get the handle to the window

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.

RE: get the handle to the window

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close