Using Windows calculator

Hi there,

To use the calculator from Windows, I use the following line:

ShellExecute(0,nil,pchar('C:\WINDOWS\CALC.EXE'),nil,nil,sw_shownormal);

This is working fine...

Now I have the following question: Before I execute this calculator I want to check if there is already an instance active. And if there is already a calculator active then I would like to set the focus on that one. In other words: not opening a new instance anymore. If minimized then (of course) I would like to maximize before setting the focus on the calculator.

Please provide me with a complete example.

Thank you very much!

RoosieDB
roosiedbAsked:
Who is Participating?
 
CesarioCommented:
Hi RoosieDb,

procedure TForm1.Button1Click(Sender: TObject);
VAR
  hCalc : THandle;
begin
  // In Germany is the Caption of Calculator Window is "Rechner" so
  // you have to change it to Calculator
  HCalc := FindWindow ( NIL,'Rechner');
  IF HCalc <> 0 Then
  Begin
    Windows.SetForegroundWindow (hCalc);
    Windows.ShowWindow (hCalc,sw_normal);
  End
  Else ShellExecute(Handle,'OPEN','C:\Windows\CALC.EXE',nil,nil,sw_shownormal);
end;


Good Luck

Cesario
0
 
intheCommented:
or use classname instead of caption as this should be same for all languages:

HCalc := FindWindow( SciCalc,nil);

0
 
CesarioCommented:
inthe, did you recieved any mail Notifications form ExEx last 3 days?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
intheCommented:
hi Cesario,
was just wondering same thing myself.
well i guess Crazyone answered us :)
0
 
roosiedbAuthor Commented:
Hi Cesario,

Your solution is working fine, however, I would like to implement your example in my application without changing it everytime when my users are using different languages.

So, if you can send me a solution to solve that issue I would be very happy. But it's not required, because this is already working for me.

Your colleague wrote something like HCalc := FindWindow(SciCalc,nil), but this is not working (error message).

Thank you anyway.
RoosieDB
0
 
CesarioCommented:
Hi RossieDB,

I will try to find a solution today....

Best Regrads

Cesario
0
 
roosiedbAuthor Commented:
Hi Cesario,

I would be very grateful...
:-)

In other words: Danke sehr !!

RoosieDB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.