I'm creating a C# program and I need to control another application. I found this
example, but it doesn't really work for me (or at least I can't make it work).
1) The application is already running (so I can't use Application application = Application.Launch("foo.exe");
2) It has a textbox and I need to read what's written in it.
3) Then I want to press one of its buttons (This can be done with that: Button button = window.Get<Button>("save"); button.Click();
I also searched Google, but I didn't find anything working.
Can you help me? Thanks in advance.
The documentation doesn't mention it, but Application.Attach() allows you to access a program that is already running. From there, I would expect everything would work as documented.
Related
I have a console application I am now creating a GUI for it.
My GUI is simply a text block that prints text to screen, a Textbox where a user can enter text and a button for the user to submit their text.
I have done a very terrible job at this using the MainWindow.xaml.cs file that was created for me when I opened up VS. I have a DLL of my classes in my console app and all my GUI related code is in my button code on the GUI.
I mean it works but I figure it is very unorthodox. What I have now realized is that part of thew task involves me to upload all Put/Take related code, this is where I am confused, what is this?? I cannot find anything online about it. Now apologize in advance if I need to be more specific or add more information, due to my lack of knowledge I am very unsure what I need to my question, however, I mainly want an explanation of the purpose of the Put/Take commands?
Let me know if I should add more info to help you answer and what would be most useful.
I was under the impression from the wording of the task that Put/Take were a universal programming thing... they are not and it was specific to my task and another class they wanted me to implement
I've seen it in many code samples, tutorials and other people's code that I've worked with. I've never really understood (or even learned) why people use Console.Write(exception.Message);.
The only reason I can think of is to log the exception for later investigation. So, I thought I'd give it a try, since I have some spare time on my hands, and have tried to find some specific info regarding my questions, but couldn't find it.
If I use Console.Write(exception.Message); in an asp.net webpage, where exactly does this go? Where is the "Console" in a web app/site?
And, how do you "see" what you've previously written to the Console?
In Visual studio, for winforms and WPF application it prints to Output window
For ASP.Net use System.Diagnostics.Debug.WriteLine() to print to output window
To open the Output window, on the View menu, click Output.
You may want to see: Where does Console.WriteLine go in ASP.NET?
I just wanted to know, if there is someway to make a program (or part of a program) intangable with c#. I want to make it so that people can see the program is there, but if they were to click, it would click whatever is underneath it. I would also like to know if you can do that backwords. Is there someway to make an item that is invisable, clickable?
Thank you for your help!
To your vague question, I offer a vague response:
Sounds like your option one is possible. You would need to send the click event (message) that you receive to the appropriate window (the one underneath yours). I suspect that you would have to DllImport some stuff to do this from c#.
Your option two, while more difficult, is probably also possible because you can inject code into other running executables. This will be a privileged operation, and you will likely again have to use stuff from non .NET dlls to do it from c#. See Three Ways to Inject Your Code into Another Process on CodeProject.
If you want to display something to a user without it getting in the way of whatever it was they were doing at the time you could pop up your messages in bubble from the task bar perhaps?
The answer to this question covers this. Or if you're lazy here's the code project link.
Ok so it sometimes might be necessary to show something on screen and not let it be clickable (like On-Screen-Display for video playback to show volume increase, etc..)
Here's an example of how to this in C# - from codeproject: http://www.codeproject.com/KB/cs/OSDwindow.aspx
This uses the Win32 API ShowWindow(hWnd, SW_SHOWNOACTIVATE) to present the window without losing focus (can't be selected).
And here's the MSDN page for this call ShowWindow
To display a window that is invisible but clickable you can use a window with no border (FormBorderStyle=None) and set transparency to 1%.
Hope that helps!
I want to create a program or use a program that will read the memory values out of another application. Does anyone know of an application/library that will do this?
The target app is this. I would like to read the exchange rate values from it.
I'm an experienced c# programmer, but have never worked with the Win32/user32 api which is what I'm assuming I'll have to deal with to pull this off.
Any help that gets me going in the right direction is greatly appreciated.
Update:
I managed to use Spy++ to get the window handle, so I'm sure I can get the values some how.
Have you looked into AutoIT or AutoHotKey?
Both of these open source options have well documented abilities to read text from application windows (and send keystrokes or mouseclicks to them).
AutoIT is very easy to use and well documented.
An example of reading text from a window would be:
$text = WinGetText("title of window", "")
MsgBox(0, "Text read was:", $text)
This can be compiled into an executable.
Typically an application creates controls in a dialog in a consistent manor, same ID, same order etc, so finding a control programatically is fairly simple. Using Spy++ find the control's ID and then you can search the windows created by the application for the desired control. Not being familiar with the app in question I cannot give specifics, but if Spy++ shows the value you desire, it is likely not difficult to obtain the value in your code.
What type of control is the value displayed in? You'll may be able to use GetDlgItemText to obtain the value once you have the parent window handle and control ID? To get the parent window try using EnumWindows.
It might be easier to scrape their data by automating a screenshot and then ocr process. If that's your goal.
Potentially relevant links:
get-a-screenshot-of-a-specific-application
ocr-with-the-tesseract-interface
May be this article helps - http://msdn.microsoft.com/en-us/magazine/cc163617.aspx, but I think it's not universal and for your task is better to get access directly to Forex API/Web-Service or try to catch needed data on network.
It is possible to screen-scrap things created with native windows controls; if that is the case, you should be able to see the controls using Spy++. But some times controls are implemented "by hand", and there is no way to screen-scrap them (e.g. some Java graphic toolkits play directly with the graphics, so everything day do is meaningless from the outside, or even some Office menus are implemented without using the menu control).
The Windows accessibility API is a possible way to screen-scrap the values; check if "Narrator", the screen reader that comes with windows, is able to read aloud your target application.
I wanted to create a program that would allow me to open instances of a already exsiting program (i just have the exe) as windows inside (i belive its called mdi)
Is that something i could do? can anyone point me to an example?
Thanks
Maybe this is the answer you are looking for here. It can be done...look in the sample on that link given.
Hope this helps,
Best regards,
Tom.
When Windows starts a program its parent is the Desktop Window.
If you could somehow manipulate that, it may work.
However, I doubt it is possible, as why would I want to allow you to run my application in your window? Especially MDI? Besides that - running in a child window isn't quite the same as running in the "main" window.
Having said that there is an application out there (can't think of it's name OH) that does place individual applications in tabs. Pretty nifty if you're not on Windows 7. The folks over at the Business of Software forum might be able to help you find it.
Well, after starting the app and storing its PID, you could start monitor the windows that get created, either thru a CBTHook or by just using a timer and the GetWindows to find when a top level window gets created by the PID in question.
Then you can use SetParent to make that window a child to your MDIChild (I doubt you can make it your MDIChild directly).
That should get you going. What you'll run into after that I really don't know. I guess you must correlate any movement of either your app or the external app so that thir windows appears to be stuck together...
Maybo you could strip away the caption from the external app (Get/SetWindowsLong). That could make it look better...