Singular vfp old and new calculators
this is a textbox joined with the native vfp calculator.
this last is fired with this command
its possible only in vfp screen,command window or screen forms or forms level 1 (showWindow=0,1).but the calculator position is uncontrollable.
to do that i used a new window defined with
this becomes an object and then can manipulated easily with OOP.
with this trick can show the calculator at any pre defined position.
the vfp calculator have some properties as _CalcCem,_CalcValue
used here as well.
The calculator result must be selected(issue =) to be stored in _calcvalue.
NB: this dont work on top level forms (as vfp calculator, defined windows...).
Below five codes for vfp calculators.I added windows calculator embed on vfp form.
I updated with adding a Google web calculator on a form and a windows calc hosted on a top level form.
This page was last updated on : lundi 23 février 2015; 00:08:04
*!*1) begin code
publi yform
yform=newObject("asup")
yform.show
read events
return
DEFINE CLASS asup AS form
DataSession = 2
Top = 22
Left = 250
Height = 117
Width = 346
ShowWindow = 0 &&0,1 only to see native vfp calculator
BorderStyle = 2
Caption = "yCalculator"
MaxButton = .F.
xx = .F.
yy = .F.
ADD OBJECT text1 AS textbox WITH ;
FontSize = 14, ;
Alignment = 3, ;
Value = 0.0000, ;
Height = 36, ;
InputMask = "9999999999.9999", ;
Left = 48, ;
Top = 55, ;
Width = 190, ;
ForeColor = RGB(255,255,255), ;
BackColor = RGB(0,0,255), ;
TABINDEX=3,;
Name = "Text1"
ADD OBJECT image1 AS image WITH ;
Picture = "sscalc.bmp", ;
Stretch = 2, ;
Height = 32, ;
Left = 240, ;
MousePointer = 15, ;
Top = 57, ;
Width = 32, ;
Name = "Image1"
ADD OBJECT label1 AS label WITH ;
WordWrap = .T., ;
Caption = ['Make any calculations in vfp Calculator and mandatory issue "=" to see the result in textbox'], ;
Height = 33, ;
Left = 12, ;
Top = 3, ;
Width = 265, ;
TABINDEX=1,;
ForeColor = RGB(0,0,255), ;
Name = "Label1"
ADD OBJECT command1 AS commandbutton WITH ;
Top = 5, ;
Left = 312, ;
Height = 25, ;
Width = 25, ;
FontBold = .T., ;
FontSize = 12, ;
Caption = "?", ;
MousePointer = 15, ;
BackColor = RGB(0,255,0), ;
tabindex=2,;
Name = "Command1"
PROCEDURE ycalc
lparameters x,y &&x,y positions in pixels
if pcount()<2
x=0
y=0
endi
THISFORM.xx=x
thisform.yy=y
if !vartype(myw)="O"
define window yb from 1,4 to 20,40 name myw
endi
with myw
.left=x
.top=y
.width=144
.height=168
endwith
STORE 0 TO _CALCVALUE
STORE 0 TO _CALCEM
activate window calculator top in yb
move window calculator to -3,0 &&to hide titlebar and to position the calculator
activate window yb top
ENDPROC
PROCEDURE my
LPARAMETERS nButton, nShift, nXCoord, nYCoord
if vartype(myw)="O"
this.text1.value=_CALCVALUE &&must issue "=" of the calcultor mandatory to see here the result (or result selected)
endi
deactivate window yb
ENDPROC
PROCEDURE Moved
deactivate window yb
ENDPROC
PROCEDURE text1.gotfocus
set curs on
endproc
PROCEDURE text1.lostfocus
set curs off
endproc
PROCEDURE Init
if this.showWindow=2
messagebox("Sorry this works only for showWindow=0,1",16)
return .f.
endi
set talk off
set deci to 4
set fixed on
local img
text to img noshow
FFD8FFE000104A46494600010101004800480000FFDB0043000503040404030504040405050506070C08070707070F0B0B090C110F1212110F111113161C1713141A1511111821181A1D1D1F1F1F13172224221E241C1E1F1EFFDB0043010505050706070E08080E1E1411141E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1EFFC00011080020002003012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00E8F4FD58ADB2DA49A3DBB0F29563B8124A24CED1C95FBA79FA0C7EB3C5AB0579AD25D1E06E02C570B24A24CF19257EE9E73F85615B47E3CFB3A410DEE99FD82D731C8F3330F35176FF00AA09B7AF5E77761D30736C8F1B790D6A9269DFD8C753F3BED865FDE88F1FF1EFE5EDEBFED6EF7C579CF0557FE7EBDEFF00F00EB589A7FF003ED6DFD32F0D5A4133599D22DB6EF08B3EE97CCC6D3924676FDEC7B62A2BCD7226B59EC06847CC30ECFB4EF933BB9DC76FDDC62AB01E37F24DAF99A61D14EA7E70BCF34F9C23C7FC7BF97B719FF6B3F85695F0F179D3272D7518D285A80631327DCCE4363EF64E31FE4D65569D5A2E3EFB777E470636AF338722B7A7538E820D05A2F35BC5B7A90AEA50B4BA48DBB0DD15201DDB778070DF28383565B4FD18892F8F8A2FD6D46B40369BB4796D798ECFB7763D501C723B115460D67C306F2063E19865F10FDA5238AF0459536FB0626F371B3A6475DC318A8A4D7348FF0084CFCA3E0EB56D4FED015752D9FF002CFF00E7A7998DB8DBEF9ED5EB1A1A82CF4662D75FF095DF9B58F5B1FF0012C2A3CBFB6367A3EDDD8E3EE671D3B115AB7BA768C229AF3FB6E46BD30FFA8FB29E46784F33A704F4AC69355F0B26A7F685F0E5A3EBC6F3C9FB698C8223DC0094301B4FCBDC907DB156EF7C43E1B161240BA591A9F9AC8F3B122255E73267763DFA63BD63F519E3F5A6D2E4D5F37E8659AE1E585F67CF67CDDB5EDF71FFD9
endtext
this.image1.pictureVal=strconv(img,16)
publi myw
define window yb from 1,4 to 20,40 name myw
for i=1 to this.controlcount
bindevent(this.controls(i),"mousedown",this,"my")
endfor
bindevent(this,"mousedown",this,"my")
ENDPROC
PROCEDURE Destroy
try
release window yb
myw=null
catch
endtry
clea events
ENDPROC
PROCEDURE image1.MouseDown
LPARAMETERS nButton, nShift, nXCoord, nYCoord
thisform.ycalc(thisform.left+sysmetric(3)+this.left,thisform.top+sysmetric(9)+sysmetric(4)+this.top+this.height)
ENDPROC
PROCEDURE command1.Click
local mymess
text to mymess noshow
this is a textbox joined with the native vfp calculator.
this last is fired with this command <activate window calculator>
its possible only in vfp screen,command window or screen forms
or forms level 1 (showWindow=0,1).but the calculator position is
uncontrollable.
to do that i used a new window defined with <define window...name >
and embed in the window calculator.
this becomes an object and then can manipulated easily with OOP.
with this trick can show the calculator at any pre defined position.
the vfp calculator have some properties as _CalcCem,_CalcValue
used here as well.
The calculator result must be selected(issue =) to be stored in _calcvalue.
NB: this dont work on top level forms (as vfp calculator,defined windows...).
*!*--Author Yousfi Benameur El Bayadh Algeria
*!*--Time stamp mercredi 15 juin 2011; 16:46:50
*!*--Subject : A new use of native vfp calculator in join with textbox result.
*!*--Version Vfp9Sp2
endtext
messagebox(mymess,0+32,"VFP calculator in Rescue")
ENDPROC
ENDDEFINE
*!* end code
*2)This is another calculator with two methods (vfp native calc and using evaluate vfp function)
*--Author Yousfi Benameur El Bayadh Algeria
*--Time stamp mardi 9 juin 2009; 19:54:38
*--Subject :CALCULATIONS (even scientific) with vfp
*Begin code
yform=Createobject("ycalculator")
yform.Show
Read Events
Return
Define Class ycalculator As Form
Top = 22
Left = 208
Height = 250
Width = 600
maxbutton=.f.
borderstyle=2
Caption = "Calculations with VFP"
Name = "Form1"
Add Object text1 As TextBox With ;
FontSize = 14, ;
Height = 48, ;
Left = 131, ;
Top = 22, ;
Width = 350, ;
Name = "Text1"
Add Object YHELP As CommandButton With ;
Top = 21, ;
Left = 510, ;
backcolor=Rgb(0,255,0),;
fontbold=.T.,;
fontsize=14,;
fontcolor=255,;
Height = 49, ;
Width = 49, ;
Caption = "?", ;
Name = "yhelp"
Add Object command6 As CommandButton With ;
Top = 21, ;
Left = 59, ;
Height = 49, ;
Width = 49, ;
Caption = "Calc", ;
Name = "Command6"
Add Object command1 As CommandButton With ;
Top = 156, ;
Left = 60, ;
Height = 37, ;
Width = 61, ;
Caption = "Eval", ;
Name = "Command1"
Add Object text2 As TextBox With ;
Height = 49, ;
Left = 144, ;
Top = 146, ;
Width = 390, ;
selectOnEntry=.T.,;
Name = "Text2"
Add Object label1 As Label With ;
BackStyle = 0, ;
Caption = "Type any calculation formula in the textbox and click Eval", ;
Height = 25, ;
Left = 150, ;
Top = 204, ;
Width = 312, ;
Name = "Label1"
Add Object label2 As Label With ;
BackStyle = 0, ;
Caption = "Right clic to paste the result calculation (_calcMem) of vfp calc in text1", ;
Height = 25, ;
Left = 132, ;
Top = 72, ;
Width = 312, ;
Name = "Label2"
Add Object command2 As CommandButton With ;
Top = 120, ;
Left = 60, ;
Height = 27, ;
Width = 84, ;
Caption = "Re initialize", ;
Name = "Command2"
Procedure Init
Thisform.SetAll("mousepointer",15,"commandbutton")
Procedure text1.RightClick
This.Value=_Calcvalue
Endproc
Procedure command6.Click
Activate Window calculator
Endproc
Procedure command1.Click
Try
Thisform.text2.Value=Evaluate(Thisform.text2.Value)
Catch
Thisform.command2.Click
Endtry
Endproc
Procedure text2.Init
This.Value=[(1245*45+sqrt(1456.25)+12*78+;
14578/45+120*cos(pi()/3)+log(10))]
Endproc
Procedure command2.Click
Thisform.text2.Value="PUT a VALID formula"
Thisform.text2.SetFocus
Endproc
Procedure YHELP.Click
Local m.myvar
TEXT to m.myvar noshow
This form show two methods to make calulations from vfp.
The first uses the vfp native calculator.click to brose the calculator
and make any calculaions.
The second ues the vfp capabilities to evaluate any valid input formula
and the browse its result .
this can uses as scientific calculator and performs all ntive vfp calculations
functions.
ENDTEXT
Messagebox(m.myvar,0+32+4096,"Help")
Procedure Destroy
try
DEACTIVATE WINDOW calculator &&if yet present
RELEASE WINDOW calculator
catch
endtry
Clea Events
Endproc
Enddefine
*
*-- End code
I make the calc on the form and hide the titlebar ans the menu.The code can in win8.1 4 possibilities of calc window (std,scienific,developper,and statistics).
*Begin code
Publi yform
yform=Newobject("ycalc")
yform.Show
Read Events
Return
*
Define Class ycalc As Form
BorderStyle = 0
Top = 55
Left = 77
Height = 269
Width = 420
ShowWindow = 2
Caption = "Window calculator on VFP form"
MaxButton = .F.
KeyPreview = .T.
hcalc = 0
Name = "Form1"
Procedure yposition
* positioning calculator on form(hidding titlebar+menu to -50 px on top)
#Define SWP_SHOWWINDOW 64
= SetWindowPos(Thisform.hcalc, 1,1,-50,Thisform.Width-2, Thisform.Height-2, SWP_SHOWWINDOW)
sleep(500) &&important
*start with scientific calculator (ALT+2) keystroke (ALT+1=standard ALT+3=developper ALT+4 statistics)....WIN8.1
#Define VK_MENU 0x12
#Define WM_KEYUP 0x0101
#Define KEYEVENTF_KEYUP 2
= SetForegroundWindow(Thisform.hcalc)
=Bringwindowtotop(Thisform.hcalc)
= keybd_event(VK_MENU, 0, 0, 0)
= keybd_event(VkKeyScan(Asc(_Screen.xcalc)), 0, 0, 0)
= keybd_event(VkKeyScan(Asc(_Screen.xcalc)), 0, KEYEVENTF_KEYUP, 0)
= keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
sleep(500)
*get the calc window dimensiosn
cRect = Thisform.GetWinRect(Thisform.hcalc)
Local m.w,m.g,m.x,m.y
x= Thisform. buf2dword(Substr(cRect, 1,4))
Y= Thisform. buf2dword(Substr(cRect, 5,4))
w= Abs( Thisform.buf2dword(Substr(cRect, 9,4))-x)
h= Abs(Thisform.buf2dword(Substr(cRect, 13,4))-Y)-50
With Thisform &&adapt the form to the calc dimensions
.Width=m.w
.Height=m.h
Endwith
Endproc
Procedure GetWinRect
Lparameters hWindow
Local cBuffer
cBuffer = Replicate(Chr(0), 16)
= GetWindowRect(hWindow, @cBuffer)
Return cBuffer
Endproc
Procedure buf2dword
Lparameters lcBuffer
Return Asc(Substr(lcBuffer, 1,1)) + ;
BitLShift(Asc(Substr(lcBuffer, 2,1)), 8) +;
BitLShift(Asc(Substr(lcBuffer, 3,1)), 16) +;
BitLShift(Asc(Substr(lcBuffer, 4,1)), 24)
Endproc
Procedure KeyPress
Lparameters nKeyCode, nShiftAltCtrl
If nKeyCode=27 &¬ detected -click on borders to give focus to form and press esc to exit
Thisform.Release
Endi
Endproc
Procedure Load
Declare Integer Sleep In kernel32 Integer
Declare Integer FindWindow In user32;
STRING lpClassName, String lpWindowName
Declare Integer SetParent In user32;
INTEGER hWndChild, Integer hWndNewParent
Declare Integer SetWindowPos In user32;
INTEGER HWnd,;
INTEGER hWndInsertAfter,;
INTEGER x,;
INTEGER Y,;
INTEGER cx,;
INTEGER cy,;
INTEGER wFlags
Declare keybd_event In user32;
SHORT bVk, SHORT bScan, Integer dwFlags,;
INTEGER dwExtraInfo
Declare SHORT VkKeyScan In user32 Integer ch
Declare Integer SetForegroundWindow In user32;
INTEGER hWindow
Declare Integer BringWindowToTop In user32 Integer
Declare Integer GetWindowRect In user32;
INTEGER HWnd, String lpRect
_Screen.AddProperty("xcalc","2")
Local m.x
m.x=Inputbox("Start windows calc as standard(1)-Scientific(2)-Developper(3)-Statistics(4)","","2")
If !Inlist(m.x,"1","2","3","4")
m.x="2"
Endi
_Screen.xcalc=m.x
Endproc
Procedure Init
#Define SW_SHOWNORMAL 1
Local hcalc
i=0 && to prevent pb with localized calc title(if calc running but dont found)-frenc:calculatrice-en=calculator
Do While .T.
hcalc = FindWindow(Null, "Calculatrice" ) &&change to "Calculator" if English locale
If hcalc = 0
Run/N Calc.Exe
Else
Exit
Endif
i=i+1
If i>10
Exit
Endi
Enddo
* Change the parent window for the calculator.
= SetParent(hcalc, Thisform.HWnd) &&Handle to the previous owner
Thisform.hcalc=m.hcalc
Thisform.yposition()
Endproc
Procedure Destroy
Clea Dlls
Clea Events
Endproc
Enddefine
*
*-End code
*4)*A nice scientific calculatore from Google on the Web (internet connected)
*you can switch between a large calc and a small calc in the texxbox.
*i prevent to link to another links as help (can see it on the navigator)
*Begin code
Publi yform
yform=Newobject("google_calc")
yform.Show
Read Events
Return
*
Define Class google_calc As Form
BorderStyle = 0
Height = 359
Width = 533
ShowWindow = 2
AutoCenter = .T.
Caption = "Google calculator"
MaxButton = .F.
Name = "Form1"
Add Object olecontrol1 As OleControl With ;
oleclass="shell.explorer.2",;
Top = 0, ;
Left = 0, ;
Height = 361, ;
Width = 541, ;
Anchor = 15, ;
Name = "Olecontrol1"
Procedure Init
Thisform.olecontrol1.Navigate("http://www.dematte.at/CalcSS3/")
Endproc
Procedure Destroy
Clea Events
Endproc
Procedure olecontrol1.BeforeNavigate2
*** Événement de contrôle ActiveX ***
Lparameters pdisp, url, Flags, targetframename, postdata, headers, Cancel
Nodefault
Cancel=.T.
Retu
Endproc
Procedure olecontrol1.Init
This.silent=.T.
Endproc
Enddefine
*
*End code
can reproduce this with the image background,clickable shapes on buttons,a textbox..,bindevent.....to do.
*5)*this is windows calculator attached to a form as child window
*the form is parent of the calc
*The calc title is localized and depens of language set on computer.("calculatrice" in french,"calculator" in english...)
*must set this title before running the code
*Update on 03/14/15 12:46:15 AM
*Begin code
#Define GWL_STYLE -16
#Define WS_CAPTION 0x00C00000
#Define SW_SHOWNORMAL 1
#Define WS_SYSMENU 0x80000
Public yform,hwindow
yform= Createobject("ycalc")
yform.Visible = .T.
Define Class ycalc As Form
AutoCenter=.T.
ShowWindow=2
Width=600
Height=500
BackColor=Rgb(145,147,205)
Caption="A child Windows Calculatrice"
Add Object cmdShow As CommandButton With;
Caption="Show calculatrice", Height=24, Width=200,;
Top=5, Left=10,MousePointer=15,BackColor=Rgb(0,255,0)
Procedure Load
Declare Integer GetWindowLong In User32 Integer HWnd, Integer nIndex
Declare Integer SetWindowLong In user32 Integer HWnd,;
INTEGER nIndex, Integer dwNewLong
Declare Long SetWindowPos In "user32" Long HWnd, Long hWndInsertAfter, Long x, Long Y, Long cx, Long cy, Long wFlags
Declare Integer ShowWindow In user32;
INTEGER HWnd,;
INTEGER nCmdShow
Declare Integer SetForegroundWindow In user32;
INTEGER hWindow
Declare Integer IsWindow In user32 Integer hWindow
Declare Integer FindWindow In user32;
STRING lpClassName, String lpWindowName
Declare Integer WinExec In kernel32;
STRING lpCmdLine, Integer nCmdShow
Declare Integer SetParent In user32;
INTEGER hWndChild,;
INTEGER hWndNewParent
* Declare Integer SetMenu In user32;
INTEGER HWnd,;
INTEGER hMenu
*setmenu(hwindow,0) &&removes the main calc menubar
Endproc
Procedure cmdShow.Click
Do Case
Case This.Caption="Show calculatrice"
This.Caption="Hide calculatrice"
Thisform.yshow
Case This.Caption="Hide calculatrice"
This.Caption="Show calculatrice"
Thisform.yhide
Endcase
Endproc
Procedure yshow
hwindow = FindWindow(Null, "Calculatrice")
If IsWindow(hwindow)=0
= WinExec("calc.exe", SW_SHOWNORMAL)
DoEvents
hwindow = FindWindow(Null, "Calculatrice")
Endif
If IsWindow(hwindow) <> 0
= SetForegroundWindow(hwindow)
= SetParent(hwindow,Thisform.HWnd)
*Cut the titlebar
Local lnStyle, lnNewStyle
* Get the current style of the window
lnStyle = GetWindowLong(hwindow, GWL_STYLE)
* Remove the border of the window
lnNewStyle = Bitxor(lnStyle, WS_CAPTION)-0xCF0000-WS_SYSMENU
* Set the new style for the window
=SetWindowLong(hwindow, GWL_STYLE, lnNewStyle)
x=Thisform.cmdShow.Left+Thisform.cmdShow.Width/5
Y=Thisform.cmdShow.Top+Thisform.cmdShow.Height
=SetWindowPos(hwindow,1,x,Y,0,0,64)
Endif
Endproc
Procedure yhide
Try
If IsWindow(hwindow) <> 0
x=-5000 &&push out of form area only
=SetWindowPos(hwindow,1,x,0,0,0,64)
DoEvents
Endif
Catch
Endtry
Endproc
Procedure Click
Thisform.yhide()
Thisform.cmdShow.Caption="Show calculatrice"
Endproc
Procedure RightClick
Thisform.yhide()
Thisform.cmdShow.Caption="Show calculatrice"
Endproc
Procedure MouseDown
Lparameters nButton, nShift, nXCoord, nYCoord
Thisform.yhide()
Thisform.cmdShow.Caption="Show calculatrice"
Endproc
Procedure Destroy
hwindow=Null
Clea Events
Endproc
Enddefine
*End code