How to use a window object through its Handle in other process
Hi All,
Is it possible to use a window object (like calling it's API) through it's Handle in a process other than the process which has created the window ?
I am using a third party grid in my application. I need to capture the position of a cell when that cell is activated through mouse or keyboard and send the cell position to other application. The Grid retrieves the value of the current cell through one of it's function using position of cursor. I have written a hook to catch the mouse and keyboard actions. In that hook I am able to get the position of cursor and the handle of the window. Can I use this handle to create an object of grid and call it's function which returns cell position ?
Please help me solving this issue.
Tons of thanks in advance...
Ajay
[836 byte] By [
ajaysinha] at [2007-11-20 11:44:40]

# 1 Re: How to use a window object through its Handle in other process
Is it possible to use a window object (like calling it's API) through it's Handle in a process other than the process which has created the window ?
Yes. But you are limited to messages that deal with DWORD as WPARAM, LPARAM and return values. Each process in Win32 runs in it's own address space. So, a pointer in one process doesn't mean anything in another. Which means, if you are sending a message to a window in another process whose WPARAM is a pointer to text or pointer to structure of some sort, when the window in the other process receives this, it holds no meaning and it might point to forbidden memory location.
So, as long as you are sending messages that use pure numbers as WPARAM and LPARAM and return values, you are good.
Can I use this handle to create an object of grid
Why are you creating another object ? I thought that the window already exists in another process and you are hooking to that window in your hooking process.
# 2 Re: How to use a window object through its Handle in other process
Thanks for your response.
Let me make the picture of my problem more clear. The grid object of my application gets the current cell through one of it's member function say 'GetCurrentCell'. I can't modify my application or better to say i can use only exe of my application. I am installing the hook in some other application and there I need to know the current cell of grid. Hook is able to catch mouse messages and can give the current point and handle of window where it was clicked i.e. when I click on Grid of my application the hook is able to retrieve the clicked point and handle of Grid window (Grid Class is inherited from CWnd Class). Now how can I call 'GetCurrentCell' function of Grid object to get the current cell.