I need to watch an app written in c++ and know when it moves so my c# windows form app can move with it.
I can poll the c++开发者_开发技巧 app's position with a timer but want a better solution.
How can I watch the windows messages for the one app to see if it is moved?
Can it be done?
Or will I need to find a C++ dll to do it or have one written?
You can use SetWindowsHook and the WH_CBT hook which will notify you went the window moves.
See How to set a Windows hook in Visual C#. or p/Invoke.net
If you don't want to poll the C++ app from the C# app, it would probably be best to push the data from the C++ app to the C#, that way you get rid of the unnecessary polling (which I am assuming is why you don't want to poll the C++ via C#).
To do this you could use WM_COPYDATA to be able to send the data from the C++ application to the C# application.
精彩评论