How to get calculator amount on text box - c#

I have a application in which i want to open a calculator on a button click and once the operation are performed on calculator and calculator is closed, I want that value back to my text box.
How can I achieve this functionality.
private void btnDollarTransferHelp_Click(object sender, EventArgs e)
{
System.Diagnostics.Process myProcess = System.Diagnostics.Process.Start("calc.exe");
}
I am using C# 4.0 and its a window based application.
Regards and Thanks

You may use the Microsoft Script Control to implement the calculator functionality in your C# app. The control has a simple Eval() method to evaluate expressions that may range from simple "2+2" to VBScript commands. More information here:
http://msdn.microsoft.com/en-us/library/aa227637(v=vs.60).aspx

It is indeed simpler to implement a calculator in your app: reading the content of another's process window is not trivial! And being notified when the calculator is "about to close" is even harder.
It involves, for sure, widows API (FindMessage/SendMessage) (see for example https://stackoverflow.com/a/360247/863564), probably P/Invoke, probably even hooking calc.exe (the technique used by Spy++ -- you need it to capture the WM_CLOSE message - see here what happens when you are closing a window)
(You need to capture WM_CLOSE, because it is the latest sensible moment to grab the result from the control on the window)
So, the alternative: a great one is scriptcs, but it may be well too much! A quick search revealed
some
great
projects
Either way, have fun!

you could use an existing library e.g. http://nclac.codeplex.com to provide calculation within your application.

Related

Hiding and showing a program started by Systems.Diagnostics.Process

The following code is how I initiate the program:
System.Diagnostics.Process fooProgram;
fooProgram = System.Diagnostics.Process.Start("foo.exe");
Now I know that you can set the StartInfo parameters to have the program run hidden but is there some way to hide it and bring it back during processing as I only want to show certain screens to the user and then I want it to automatically hide itself when the information has been shown. I was hoping for something as simple as fooProgram.Show() and fooProgram.Hide() but it appears that it is not quite that simple.
Simply sending it behind the other program and bringing it back to focus would be enough as well, however this also doesn't seem to be in the list of available actions.
The program being launched is a .NET 4 form.
I don't think you can do this in .NET - you'll need to use interop.
Check out these functions:
FindWindow
ShowWindow
SetForegroundWindow
SendMessage
So you'll use FindWindow() to get the window handle and then you'll execute those other functions on that handle. In terms of exposing those functions to C# check out this awesome interop website: pinvoke.net
Also, instead of HWND use IntPtr.

spy keyboard (how to get keyboard digets via C# win forms app)

I want to build a win app using C#...
I want this app to accept letter from the keyboard... and I want that to be done either the text is written via this program or another... its will be much better if I can choose programs I want to spy on...
in another words... I want my program to get every thing presses on the keyboard and everything is being written on firefox,opera,internet explorer witch are running at same time with my program...
You need a global keyboard hook, which will allow your application to listen in on keyboard input events system-wide. You implement this by P/Invoking the SetWindowsHookEx function and specifying the WH_KEYBOARD_LL flag for the idHook parameter. The entire process can get slightly complicated.
But it turns out that you're in luck. Stephen Toub has already written the code for you here on his blog: Low-Level Keyboard Hook in C#. Just drop this into your project and you're in the spy business.
I believe what you are looking for is a keylogger...
if so you can find information on:
http://www.axino.net/tutorial/2009/02/keylogger-in-c-introduction
There's a fairly comprehensive article on this over at Code Project: http://www.codeproject.com/KB/system/KeyLogger.aspx
While that article is based around C++ etc it covers a lot of the technical details you need to know.
There is an example C# project here: http://www.codeproject.com/KB/system/simple_key_log.aspx.

how to Make a program intangable with c#?

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!

How can you read values from an open application in Windows?

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.

Windows Terminal - Windows Form to embed cmd

I'm looking for a way to embed a cmd "Shell" into a Form. I want to build a C# based application that acts as a Terminal, better than the Powershell window (no tabs) or cmd (no nothing). Just start these interpreters in the backend.
I guess MS never thought of doing this. Any ideas what From elements I could use?
Thanks,
i/o
That's not a trivial task you're undertaking. I know of one project (Console2) which basically polls the screen buffer of the underlying console window and displays in its own. You certainly will have trouble coping with interactive applications like Far and the like as they (a) rely on getting keyboard events and (b) on manipulating their screen buffer. Both are icky things if you want a suitable wrapper around the console window functionality. Mouse input is possible as well (unless Quick Edit mode is enabled) which could give you further headaches.
I doubt you can use a ready-made control for this. Basically you need to display a grid of cells each of which has a foreground and background color. You could probably use a RichTextBox for this but I'd guess it's far from ideal.
Also I don't think no one at MS ever thought of this. It's just that there's a limited budget for new features and every one of them needs to be specified, implemented, tested, tested more for regressions with millions of applications out there, etc. It's just a freaking expensive thing (if you don't want to misuse your customers as testers, which they aren't).
It would propably be the easiest to extend the Textbox class and add logic so that it behaves like a console (respond to the KeyPressed/KeyUp/KeyDown events or similar). You can also add events for those things that your console needs to respond to. For example, add a CommandEntered event.
Basing your new console on a TextBox gives you the editing and display features of the textbox "for free", so you do not need to re-implement that.
You could use a richtext box, and set the background to black and foreground to white. RTB instead of text box to handle larger amounts of data.
You would have to write an awful lot of code to simulate the terminal though.

Categories