Handle to an external window from MATLAB
Show older comments
Hello there,
I am opening an external exe file from MATLAB using the command !program.exe &
Issue 1: Everytime I open this program (in Windows mode 1280*720 and my screen size is 1366*768), it opens at different locations of the screen which makes it difficult for me to do certain processing automatically.
Requirement: Is there a method to solve issue 1
Actually, I want to access the screen size, contents and play around with the new external window (program.exe). I believe getting a handle to this could solve my problem. Any thoughts?
Answers (1)
Walter Roberson
on 5 Oct 2015
0 votes
12 Comments
Madhu Kodappully
on 5 Oct 2015
Walter Roberson
on 5 Oct 2015
Madhu Kodappully
on 5 Oct 2015
Madhu Kodappully
on 5 Oct 2015
Edited: Walter Roberson
on 5 Oct 2015
Walter Roberson
on 5 Oct 2015
My thought is "Don't use MS Windows". I am googling this stuff as I go along.
MATLAB is not designed as an operating-system level interface. There are lot of things you cannot do directly in MATLAB and need to call into C/C++ or use an ActiveX control for.
You are trying to read the content of a window in a process that does not belong to you. That is a a security violation if done without the cooperation of the other program. A quick glance around suggests that you need to use the MS Windows specific WM_GETTEXT. There appears to be an example at http://stackoverflow.com/questions/7740379/c-sharp-how-to-use-wm-gettext-getwindowtext-api
Madhu Kodappully
on 6 Oct 2015
Walter Roberson
on 6 Oct 2015
activex controls including dynamic data exchange depend upon the recipient program having been programmed to expect such things and act upon them.
The Unix way of handling this kind of thing would be for the parent process to open a pair of pipes before forking the process, which would be inherited as file descriptors by the child process. Then they each read from one of the pipes and writes to the other.
The alternative Unix way of handling this kind of thing would be through TCP/IP: a program that wanted to be able to receive queries from other programs would establish itself as a TCP server, and any process that wanted to talk to it would be a TCP client.
Madhu Kodappully
on 7 Oct 2015
Edited: Image Analyst
on 9 Oct 2015
Walter Roberson
on 7 Oct 2015
It is a security violation to allow one program to take an image snapshot of another without the cooperation of the other program. Therefore when MATLAB asks for the screen contents, the operating system can (and should) return either nonsense or only the contents of the MATLAB windows and the desktop icons.
Security too often only appears to be a priority with Microsoft when it comes to preventing people from playing DVDs, so you might be able to do better in practice, but you would be better spending your time on arranging for the programs to cooperate.
Question: is the external program a web browser? If it is then there are tools available from MATLAB to run a browser within a context that can be examined.
Madhu Kodappully
on 7 Oct 2015
Walter Roberson
on 9 Oct 2015
If you save the images with the timer and then run them through the comparison one by one, then do you get a match? If Yes but not when you are running the comparison within the timer callback then that suggests that you have a problem in the callback.
Madhu Kodappully
on 9 Oct 2015
Edited: Madhu Kodappully
on 9 Oct 2015
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!