How can I get the CWnd pointer from HANDLE hProcess
-
Hi, After using ShellExecuteEx and getting
HANDLE hProcess
of theSHELLEXECUTEINFO
Structure, I need to get the CWnd pointer of the program window I opened. I want to use it in SetWindowPos to move and set its size. How can I get CWnd *? Thanks, caykahve -
Hi, After using ShellExecuteEx and getting
HANDLE hProcess
of theSHELLEXECUTEINFO
Structure, I need to get the CWnd pointer of the program window I opened. I want to use it in SetWindowPos to move and set its size. How can I get CWnd *? Thanks, caykahveYou don't actually need a
CWnd*
.CWnd
will just wrap the handle and convert the calls you make toCWnd
methods in calls to the corresponding API function using the handle stored in itsm_hWnd
member. For example, here is the implementation forCWnd::MoveWindow()
void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
{
ASSERT(::IsWindow(m_hWnd));
::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
}So, you can always make the call to the API function yourself. That being said, you can obtain a
CWnd*
for a given handle, usingCWnd::FromHandle()
but take note that in your case it will be a pointer to a temporary object, so you can't store it for later use. Again, if all you want to do is to use someCWnd
methods, you can use the corresponding API function directly on the window handle. ForCWnd::SetWindowPos
, the corresponding API is just::SetWindowPos
. Look in the documentation to see what parameters it expects. -- jlr http://jlamas.blogspot.com/[^] -
Hi, After using ShellExecuteEx and getting
HANDLE hProcess
of theSHELLEXECUTEINFO
Structure, I need to get the CWnd pointer of the program window I opened. I want to use it in SetWindowPos to move and set its size. How can I get CWnd *? Thanks, caykahvecaykahve wrote: , I need to get the CWnd pointer of the program window I opened. There is no direct Method for getting Window Handle from the process ID, but this link may help:- Is it possible to get info between HWND and Process handle?[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
caykahve wrote: , I need to get the CWnd pointer of the program window I opened. There is no direct Method for getting Window Handle from the process ID, but this link may help:- Is it possible to get info between HWND and Process handle?[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
You don't actually need a
CWnd*
.CWnd
will just wrap the handle and convert the calls you make toCWnd
methods in calls to the corresponding API function using the handle stored in itsm_hWnd
member. For example, here is the implementation forCWnd::MoveWindow()
void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
{
ASSERT(::IsWindow(m_hWnd));
::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
}So, you can always make the call to the API function yourself. That being said, you can obtain a
CWnd*
for a given handle, usingCWnd::FromHandle()
but take note that in your case it will be a pointer to a temporary object, so you can't store it for later use. Again, if all you want to do is to use someCWnd
methods, you can use the corresponding API function directly on the window handle. ForCWnd::SetWindowPos
, the corresponding API is just::SetWindowPos
. Look in the documentation to see what parameters it expects. -- jlr http://jlamas.blogspot.com/[^]Holy handles, Batman! After reading Alok's response I now realize that you were talking about a process handle and I took it as a window handle. It's embarrasing considering how clear it is in the thread title itself :) No cookies but more coffe for me. Sorry, -- jlr http://jlamas.blogspot.com/[^]
-
Holy handles, Batman! After reading Alok's response I now realize that you were talking about a process handle and I took it as a window handle. It's embarrasing considering how clear it is in the thread title itself :) No cookies but more coffe for me. Sorry, -- jlr http://jlamas.blogspot.com/[^]
Jose Lamas Rios wrote: No cookies but more coffe for me. Sir, Then please pass that Cookie to me, I am Hungry at this moment :).
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV