Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

interacting with windows calculator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pipo - 10 Mar 2008 16:47 GMT
Hi all,

I am trying to interact with the windows calculator.
I want to open the calculator for the user so the user can work with it.
When the user is done (or during) working with calculator I need the
(displayed)value of the calcultor back in my textbox.

I have no problem starting calculator or even put values in calculator.
I just cant get the value out of the Edit class of the calculator.

Any tips or idea's for me?

Here is my code (so far)

//Opening the calculator
Process p =Process.Start("calc.exe");
//Calculator Handle
hwndCalc = p.MainWindowHandle.ToInt32();
//Get the Handle of the Edit class (textbox of the calculator)
IntPtr pntr = FindWindowEx(p.MainWindowHandle, IntPtr.Zero, "Edit", null);
//Setting a value to the calculator
SendMessage(pntr, WM_SETTEXT, 0, "1234567");

//Buffer voor the text to be read out
StringBuilder Buff = new StringBuilder(256);
//Buffer stays empty...why???
GetWindowText(pntr.ToInt32(), Buff, Buff.Capacity);
//Dont know what to fill in for nIDDlgItem...:(
//Spy++ gives me everytime a different handle. The const 414 isnt correct
either (Buff stays empty)
//When filling in the Edit class handle then also Buff stays empty.
GetDlgItemTextA(hwndCalc, ????, Buff, Buff.Capacity);

Thank you in advance
Lasse Vågsæther Karlsen - 11 Mar 2008 18:03 GMT
> Hi all,
>
[quoted text clipped - 30 lines]
>
> Thank you in advance

Why do you need to do this? I'm sorry if the question is blunt, but
unless you give us a *really* good reason for why you need to do that,
then I can't help you better.

If all you need is a simple calculator, there are probably plenty of
examples out there for you.

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

Pipo - 11 Mar 2008 21:26 GMT
Why I need it?
Because I dont want to use extra code or some other calculator while there
is a good one in windows.
My users know this calculator and are using that one extensively.
So, I(read my users) want us the one there already is and is familair.
Ooohhh and also...because the specifications require it.

So, I am not asking for code or some other calculator tool, I want to use
the windows calculator.
Is this a *really* good reason for you all(??) :s

I hope now you can address the topic I was posting for in the first place.

Thank you for that Lasse.

BTW. I solved this topic already.
Need only help with finding multiple calculatos handles.

When I call FindWindow("SciCalc", null) I always get the same handle back.
How can I enumerate through the (open) calculator forms?
I dont want to use EnumWindows and check for the handles (bit overdone I
think)

More looking for a FindWindowNext or so ;)

Does anyone know a function for this?

You maybe Lasse?

>> Hi all,
>>
[quoted text clipped - 38 lines]
> If all you need is a simple calculator, there are probably plenty of
> examples out there for you.
Family Tree Mike - 11 Mar 2008 22:22 GMT
If you launch the calculator with Process.Start, then
Process.MainWindowHandle should do what you want.  If you are hoping to get
the handle to numerous user launched calculators, then it is more difficult.

Lasse's question was resonable, in my opinion.  There are many things that
can go on when working with a program with no exposed API.

> Why I need it?
> Because I dont want to use extra code or some other calculator while there
[quoted text clipped - 67 lines]
> > If all you need is a simple calculator, there are probably plenty of
> > examples out there for you.
Lasse Vågsæther Karlsen - 12 Mar 2008 23:10 GMT
> Why I need it?
> Because I dont want to use extra code or some other calculator while
[quoted text clipped - 67 lines]
>> If all you need is a simple calculator, there are probably plenty of
>> examples out there for you.

The reason I was asking was that I was hoping I could jolt you out your
current path. Seems I can't do that.

Unfortunately I can't help you either, but let me just point out that
there are so many things that can go wrong with your current "solution"
that whatever it is that your users want, I can assure you that they do
not want something that will break so easily as this solution will.

What if...
- the user closes the calculator before you've gotten the answer?
- opens up another calculator and expects it to behave the same way (ie.
stay in touch with your software)
- upgrades to Vista and the whole thing breaks because the calculator
isn't built the same way? what if xp sp3 changes the calculator?
- wants to use a different type of calculator that they downloaded off
the internet... I mean, it's an external program right? Surely you can
do that *too*?
- what if the user is in the wrong mode (scientific/normal), does it
behave the same? I assume yes
- what if you're running in vista with low access rights, is this
application cross-talk even allowed without a UAC popping up?
- what if it takes longer to start the calculator on some systems than
you expect it to, are you prepared to handle that?
- what if the user is running your program in citrix presentation mode,
how do you intend to talk to a program that is running on a different
machine altogether?

Now, your request for help on just finding the right window without
using EnumWindows is a good request, and I bet someone has the answer,
but if you get a few more of these "I know this will work if I can just
get past this small hurdle..." things happening down this path, I would
seriously reconsider this way of doing it.

Hope you prove me wrong :)
Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.