Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what should i do to show a vfp calculator in my main form 3

Status
Not open for further replies.
Jan 20, 2007
237
US
Hi All,
i have a form and i added a cmdbutton with a caption "calculator, so in the "click event of that button", i added "activate window calculator", to open the vfp calculator, but that does not work for me as the calculator it is not shown. the form where i have the cmdbutton is modeless, is there anything else to have in mind to make it pop up ?
can anyone guide me please ?
Thanks
Ernesto
 
Hmm. It works for me (with both a modal and modeless form).

Is it possible that the calculator is hidden behind the form? That would happen if the form's AlwaysOnTop was set to .T., for example. Or if ShowWindow is set to 2.

If you still cannot get it to work, another option would be to ShellExecute() the Windows calculator.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ernesto,
Please upload your form. As by default the calculater should show on activate window calculator. So if it does not, my bet is there is something wrong in your form.
Regards,
Koen
 
Ernesto, try running ACTIVATE WINDOW CALCULATOR from the VFP command window. That will tell you if there is something wrong with your form, or if it is a problem with the calculator itself.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If you talk about your EXE, the caculator window is in screen, so _screen needs to be visible, or the activation of the caclulator window will not be seen.

But indeed it's not only existing int the IDE, just like calendar and puzzle, these windows are also part of the runtime _screen (and to state the obvious, also the _screen, also the system menu, just not every tool and window of the IDE bound to system menu items.

In the end, that means if you want to provide such things to end-users, you also have to make the _screen your main form. You may use Windows API SetParent to pull these windows into your main window or the desktop, but from the top of my head I only remember there are two SYS() functions converting VFP whandle to Windows hWND handle and vice versa, but non giving you the whandle or hwnd from a window you only know by name and not by object reference. Anyway, these windows are also winforms with a hwnd and you'll surely get at them via Windows API functions traversing all sibling child windows of the _screen.hwnd.

To lazy to come up with code, but see
Once you know the hwnd you can make the desktop its parent window:

Code:
Declare long SetParent in Win32api long, long
Setparent(calculatorhwnd,0)

It's just very unfortunate how small the window is, that you don't have it easy to move it around.

Bye, Olaf.

Olaf Doschke Software Engineering
 
so why not simply start the windows calculator?

Yes, I suggested that as well. The Windows Calculator is much more sophisticated than the one that comes with VFP. On the other hand, the VFP version has the benefit of being accessible programmatically. For example, you can have it return the result of a calculation to your program.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Guys,
Thanks guys,
i added this
Run /N c:\windows\system32\calc.exe and then when i click the cmdbutton i added the Windows calculator show up
great thanks a lot again
 
Mike said:
On the other hand, the VFP version has the benefit of being accessible programmatically. For example, you can have it return the result of a calculation to your program.

Interesting, didn't know that. Thanks!
 
There is

_CALCMEM System Variable
Specify the numeric value that Microsoft Visual FoxPro stores in the Calculator's memory.

_CALCVALUE System Variable
Specify the numeric value that the Calculator displays initially.

Nevertheless, that doesn't give you a hint on when to read it and take it as user input.

I think most legacy software showing it only does this as a service so the user has something to calculate. But then you have to deal with people not even knowing Windows Accessories.

The calendar window has a more decent feature than that, you don't just have _DIARYDATE as the currently picked date or as means of setting the date and thus year/month displayed, but the user can enter a note that's stored in foxuser. And there's a con, with that, too, I don't want to let end users have a foxuser.dbf, it breaks too often.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Ernesto, it's good that you now have a workaround. But it's a pity we weren't able to solve the original problem. Did you try any of our suggestions, such as executing [tt]ACTIVATE WINDOW calculator[/tt] from the command window?

Also, would you care to let us know why you want to invoke a calculator from within your app? I'm not saying there is anything wrong with that, but I am curious to know what your goal is.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Ernesto,

ernesto said:
Run /N c:\windows\system32\calc.exe

Actually [tt]Run/N calc.exe[/tt] is sufficient.

You are saved by the VFP and system and hardware vendors in several ways.

1. The system might not be in C:\Windows, most people and even companies use preinstalled Windows and that's unlikely to differ.

2. Unlike what you might think System32 is not the folder for 32bit versions of system components, but that's ok. System32 is a folder you can always specify, in old legacy software like your's might be, it might even run on old 32bit only hardware, which only had System32 and not SysWow64. And in 64bit systems you then run the 64bit calc.exe. It works, as it's a separate process anyway.

3. I assume, but cannot test without explicitly setting up a VM with Windows installed differently. When you specify a wrong path the OS still will look for calc.exe in its system folder(s). So both the unspecific calc.exe and the very specific but possible non-existant c:\windows\system32\calc.exe will lead to start a calc.exe where Windows finds it.

And, by the way, on win10 calc.exe actually not the final exe running anyway, it starts the calculator in C:\Program Files\WindowsApps, but again, that's just meaning it's clean enough you start calc.exe, the system finds it.

If you really want to be specific you would use ShellExec or even CreateProcess. Then you also have feedback, whether the starting succeeds.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Mike,
executing ACTIVATE WINDOW calculator from the command window?
Yes i did from the command window and the vfp pop correctly, then build and exe file and pressing the cmdbutton that ha the code in the click event as executing ACTIVATE WINDOW calculator , then does not show the vfp calculator,i look for it but i don't see the vfp calculator anywhere, it is probably loaded but it is not visible.

however if add in the cmdbutton click event the " Run/N calc.exe" , it brings the calculator right away, well it is part of the OS so i guess it does not matter whatever is wrong in the form, that does not allow the vfp calculator to be shown.

so then what exactly the form properties should be to allow the "ACTIVATE WINDOW calculator" to be shown when running the exe file ?
Thanks
Ernesto
 
As said it the calculator only becomes visible in the screen. If you include a config.fpw that has SCREEN=OFF you won't see the calculator window.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf,
i have in the config file SCREEN=OFF , as i don't want the vfp window to be behind my form, in other words i don't want the form to be inside the vfp default screen
now is there anyway to have SCREEN=OFF to allow th vfp calculator to be shown and the form no to be inside the VFP screen ? i need to learn what i am doing wrong
 
Ernesto, the fact that you have _SCREEN = OFF is the reason that you couldn't see the calculator. ACTIVATE WINDOW CALCULATOR will open the calculator inside the main VFP windows, which is _SCREEN. Since this is invisible, the calculator will not appear.

One solution might be be to open the calculator within another user-defined window. Something like this:

Code:
DEFINE WINDOW MyCalc FROM 1, 1 TO 30, 30
ACTIVATE WINDOW MyCalc
ACTIVATE WINDOW Calculator IN WINDOW MyCalc

I haven't tried that myself, but it might work. You would have to experiment with different sizes (the FROM and TO clauses, above).

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Olaf,
actually in windows 10 the calc.exe exist in c:\windows\system32 and c:\windows\syswow64, so i just simple put the path as c:\windows\system32 in just in case but even if i do not specify the path, still will pop up
Thanks a lot
 
Also, keep in mind that RUN /N CALC is not simply another way of doing ACTIVATE WINDOW CALCULATOR. The results are different. One opens the Windows calculator, the other opens the VFP calculator. Which one is better depends on what you want to achieve.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ernesto, you overlook that windows might not be in C:\Windows. Why specify any path if RUN /N calc.exe works?

And regarding Win10: do RUN /N calc.exe and then open up task manager - details tab. You'll not find a calc.exe process, as it only runs shortly to start the real calculator app in C:\Program Files\WindowsApps

And yes, that means you don't need special handling for Windows 10, you can start calc.exe, but if you want to ensure the maximum compatibility with any target system you don't specify C:\Windows or windorüsystem32 or windorüsyswow64 at all, just RUN calc.exe and let the system find what it finally runs.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Ok Mike and Olaf,

i understand the explanation about the windows calculator, correct no need to specify the location of the calc.exe
now Mike i am playing with the coordinates for the define window so i can make that window to be able to be located somewhere in the main form, correct ? so we should put the code below
i still need to make in config screen=on or off ?

DEFINE WINDOW MyCalc FROM 1, 1 TO 30, 30 && i know i need to adjust row and columns
ACTIVATE WINDOW MyCalc
ACTIVATE WINDOW Calculator IN WINDOW MyCalc

in the load event of the form or in in cmdbutton click event ? so when my main form opens then the 'Mycalc window' will be shown in the main form ? so it is always there when the form is loaded correct ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top