How to control MFC application from another program? - winforms

I have a binary application on windows (train timetable software) which contains a lot of interresting data which I need for my project (nothing illegal, just some weird optimization algorithm). But the application has no api and the data files have undocumented binary form.
So my idea is to control the application from my own code. I would like to send keystrokes to it to fill a form, run query and save result to a file (there are buttons and menu items for this in the app). And repeat many times.
Is there a library for this? Or an example? I have a general idea how to do it, but I am lazy and I do not want to invent the wheel.
Also, the same data is available on the web. Is there some solution for the same task with ASP (Win forms) web applications? I could probably handle parsing the results but I do not know how to fill the values of webforms controls.
Thanks in advance.

You can use simple Win32 APIs to do this.
FindWindowEx and then once you have the window handle you can send any message (such as WM_KEYDOWN) to it by using SendMessage.
A good tool which helps with this process is Spy++ because it allows you to see the window hierarchy more easily and also which messages are being used internally for the application you are monitoring.
As for web form controls, you will probably have to do more work than this because typically the web will be one canvas control that things are drawn custom onto depending on the browser. Perhaps doing this via some kind of proxy is a better approach where you actually filter the HTML pages.

Related

Silverlight OOB User Menu Control

Well ... at the risk of sounding like I really don't know anything about programming, I have a question about controls in Silverlight 5.
I have an OOB App that I am working with, but I need to add the User Menus (File, Edit, etc.) that are normally seen at the top of all apps. There used to be a control in VS (the Menu control) that was easily configurable. What is the control used to create the User Menus in Silverlight 5? The Context Menu is not what I am asking about. That is the right mouse click menu ... so that's not the answer ...
Please, understand my problem. It's been since Silverlight 2 since I worked in Silverlight. I appreciate any information you kind folks would be willing to provide.
There is no such thing available directly from Microsoft (meaning it's neither built-in or present in the Silverlight Toolkit).
You will have to use third-party controls such as DevExpress or Telerik.
EDIT: Some more advice in response to your comment.
Another possibility is to create UIs from scratch. There are two forms of UIs that I found inspiring lately, both of which don't use any ribbons or drop-down menues at all. The first is to use "Windows 8"-like dashboards instead of traditional menues, the other is the Windows Azure Management Portal (a web application).
I don't use traditional UI frameworks for menues myself, but mostly because I don't like those approaches and I'm picky with how user interfaces should work and look like.
But obviously you have to make a serious time investment to go new ways. And it will heavily depend on your application what approach makes sense.
Here's one simple approach that could work in a number of cases, I used it for a database application (I call it the Windows-Phone-7/8 approach):
The screen is divided into the "page" area and information bars. The information bars contain no menues, just who's logged on, a back-button, a home-button, and context-sensitive buttons depending on what's in the view. So basically it behaves like a web browser and you navigate through the app by clicking on "links" (buttons that take you elsewhere).
There's only one page area, so no windows and no popups. I've gone to the extreme of making even dialog windows to be pages.
Now you need menues. You do that with "dashboards", ie. pages that present some overview stuff and buttons that lead to the other areas of your application.
Although you could have action buttons like save or delete on the page itself, I put them in the bottom bar (but they are still dependent on the page your on) - that is exactly how it works in Windows Phone 7/8.
One last advice: The real effort is usually not in the menus anyway. Beside your application logic itself, it's a lot of little things like login screen, error handling and how to present error messages (look at the windows azure management portal for how they did that really nicely) and gracefully failing on session timeout. There's also a lot of nuisance on how you manage your data (ria-services, etc.).
So as long as you don't need fancy data grid grouping, rich-text edit or excel-like pivot controls, a toolkit might not help you as much as you'd hope - because they give you only the controls, not the entire UI.

How to stream a WPF window content to another computer

Does anyone know how a WPF window's view area can be streamed to remote computers? e.g. Can someone use a web browser and point to an address whereby this address shows the content of this WPF application?
This is somewhat like maybe desktop sharing but just over a small estate, which is the window's viewable area.
Well you didn't really explain what exactly you trying to accomplish which makes it hard to understand.
"Streaming" the content of window comes in a few flavors and has limited uses.
Typically its way more efficient to share data not how it presented. That said here are some common ones.
For example Cicso's WebEx allows you to share your desktop or a single application in the context of a conference call.
Citrix XenApp allows you to deliver an applicaiton to a client that's installed on the server (thin client).
You could also use Windows Media Encoder (which has an SDK) to capture an encode the contents of an application. However this is usually done as part of a demonstation and not in a "live context"

Is there a way to find out what winform/wpf components a program uses?

I'm a complete novice in gui-programming and I'm looking for an easy way to visualize a data structure I have. I own another program that does a similar job and the component it uses seems like it would fulfill my purposes as well. So instead of testing out different components myself (Which would undoubtedly force me to learn a lot), I'm wondering if there's a fast way out of it.
Is there anyway to find out what specific wpf/winform component a program is using without asking author/having source code access?
Edit:
Looks like this, the area it's in is scrollable horizontally/vertically. The objects on it are selectable, moveable and have actions associated with their right-click menu. I want to visualize an undirected graph and have the possibility to interact with the nodes graphically.
Here's the control I'm talking about:
First step, I'd look at the assemblies the app references. If it references a dll from a component vendor (a simple search can figure this out), you can visit the vendor's website and check out their offerings.
If it is a custom control embedded within the application, and its a WPF app, I'd use Snoop.
(Image ganked from http://snoopwpf.codeplex.com/). Snoop can sniff out the visual tree of a WPF application at runtime and show you all the controls that make it up.
This is no standard control but some propritary one. You can have a look in the program folder of that program which dll's they use, chances are that you can use this dll in your own app. Note that the license of this application may forbid using the code!

Is it possible to build a WinForm app (or another type of .NET app) which allows me to interact with other windows outside the applicaiton itself?

I'm learning Chinese at the moment and I have gotten my hand on a Chinese dictionary definition.
Now I would like to make an interface.
All I really want the application to do is when I point my mouse pointer over any text on the screen (in any window), it would identify the text I am pointing at and then display a small form over it, which would the chinese transaction.
Is that possible to do? Can WinForms apps interact with windows outside of it's own application?
In C# you can get text under mouse cursor by P/Invoking
GetCursorPos
GetClassName
SendMessage
WM_GETTEXT
WM_GETTEXTLENGTH
WindowFromPoint
Like mentioned here
here is another example in C++
A WinForms application can interact with the Windows of other applications. Window handles exist in a global namespace so if you can get the handle of another application's window you can send it messages. You will have to use pinvoke to do some of this, have a look at WindowFromPoint
However, there is no standardized way to display text in a window; there are dozens of APIs for displaying text. So when you point at text with a mouse, you can only get the pixels, but not necessarily the text.
Some window classes will allow you to send class-specific messages query for the text at a specific location, but many will not. Your best bet is probably to use the same methods that screen readers for the blind use http://en.wikipedia.org/wiki/Screen_reader

Creating media visualization in Silverlight

I'd like to create to some custom visualization effects to a sound wave in Silverlight. As of Silverlight 3 there's the MediaElement class which does a great job in playing sounds/videos.
To visualize however I would need some kind of event callback with some information on the currently played segment of the sound. Does the framework have some support for achieving this?
I wanted the same so I've created exactly that.
You can see a live demo at http://prefix.teddywino.com/post/SilverlightMediaKitLiveDemo.aspx
The library and demo source code are available at http://salusemediakit.codeplex.com/
The demo shows the added feature to alter the raw audio data to create effects.
Currently works only with MP3s and is still under development
Sadly this is not possible in Silverlight unless you go the whole way and create your own MediaStreamSource to decode the audio (e.g. from MP3) yourself.
Can you get away with cheating? A lot of web players show a fake graphic equaliser which just has bars going up and down randomly during playback. I seem to remember that MySpace and SoundClick used to do this (may still do).
If you implement a custom MediaStreamSource, you could potentially inspect/analyze the data being generated by it, but you will immediately run in to UI threading issues if you try and update the UI directly from the custom MediaStreamSource, or vice versa.
One way to get this to work might be to implement a custom MediaStreamSource that writes (or duplicates?) extra audio data to a thread-safe buffer where your UI could access it.

Resources