• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

get the window pointer

 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
genady
Asked:
genady
  • 7
  • 4
1 Solution
 
AlexFMCommented:
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
 
AlexFMCommented:
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
 
genadyAuthor Commented:
    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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
genadyAuthor Commented:
    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
 
genadyAuthor Commented:
    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
 
genadyAuthor Commented:
    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
 
genadyAuthor Commented:
    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
 
AlexFMCommented:
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
 
AlexFMCommented:
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
 
genadyAuthor Commented:
   Thanks for the suggestion,
I'll try it.
Regads,
0
 
genadyAuthor Commented:
Thanks a lot

Regards,
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now