?
Solved

get the window pointer

Posted on 2003-03-11
11
Medium Priority
?
206 Views
Last Modified: 2010-04-01
 Hi guys,
I need to get pointer to the application I'm start. I'm using this line of code to lunch the application and then I do need the pointer.
    ShellExecute(hWnd, "open", givenPath2Start, givenParameters, NULL, SW_SHOWNORMAL);
 Does some one can give an idea how I can get the pointer to the window?

Regards,
0
Comment
Question by:genady
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 8111500
1) Replace ShellExecute to ShellExecuteEx, this gives you created process handle

2) Use WaitForInputIdle to wait for window creating

3) Use FindWindow to get window handle.

You cannot work with CWnd pointer with window from other application, only window handle.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8111523
Additional information:
If you know window title or class, you can use FinfWindow.
Other way is using EnumWindows to enumerate all top-level windows, use GetWindowThreadProcessId function to fing the window belongs to created process.
0
 

Author Comment

by:genady
ID: 8112680
    Hi Alex,
it seems Ok, but if I try to use EnumWindows and through the GetWndThreadProcessId the value of ShExecInfo.hProcess is not the same as I'm trying to get by using these lines:
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);

By the chance any idea?

Regards,
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:genady
ID: 8112796
    Hi Alex,
it seems Ok, but if I try to use EnumWindows and through the GetWndThreadProcessId the value of ShExecInfo.hProcess is not the same as I'm trying to get by using these lines:
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);

By the chance any idea?

Regards,
0
 

Author Comment

by:genady
ID: 8113368
    Hi Alex,
it seems Ok, but if I try to use EnumWindows and through the GetWndThreadProcessId the value of ShExecInfo.hProcess is not the same as I'm trying to get by using these lines:
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);

By the chance any idea?

Regards,
0
 

Author Comment

by:genady
ID: 8113805
    Hi Alex,
it seems Ok, but if I try to use EnumWindows and through the GetWndThreadProcessId the value of ShExecInfo.hProcess is not the same as I'm trying to get by using these lines:
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);

By the chance any idea?

Regards,
0
 

Author Comment

by:genady
ID: 8114059
    Hi Alex,
it seems Ok, but if I try to use EnumWindows and through the GetWndThreadProcessId the value of ShExecInfo.hProcess is not the same as I'm trying to get by using these lines:
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);

By the chance any idea?

Regards,
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8117278
I didn't understand exaclty what you mean. My idea is to get process ID from ShExecInfo.hProcess (filled by ShellExecuteEx) you already did this. Now run EnumWindows and for each window handle call:
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);

Compare dwProcessId with process ID from ShExecInfo.hProcess. If they are equal - window belongs to the process you just created.

And don't forget WaitForInputIdle before this.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 8117736
OK, I got it. GetWindowThreadProcessId gives process ID and not handle. I am not sure OpenProcess will return the same handle as ShExecInfo.hProcess. This way works for CreateProcess which gives you both process handle and ID. Can you create process using this function and not ShellExecuteEx?
0
 

Author Comment

by:genady
ID: 8119268
   Thanks for the suggestion,
I'll try it.
Regads,
0
 

Author Comment

by:genady
ID: 8122880
Thanks a lot

Regards,
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question