Download documentation

Day 4

In this part we will finish creating the calculator. Let us modify the dialog box a bit first. We need to add the 'Save' button to save the current state and the 'Help' button. Let us take the appendexpr function. It adds the current state to the data array. On exit, we will also save the current state and variables, but they will be written at the very beginning as zero state. The last parameter will point to the type of saving.

func appendexpr( uint last )

{
uint cur i

if last
{
cur = *data
data.expand( 8 )
}
getwintext( exprwnd, data[ cur ] )
fornum i, 7
{
getwintext( GetDlgItem( dlg, $IDC_VA + i ), data[ cur + i + 1 ] )
}
combo_add( exprwnd, data[ cur ] )
}

We will also need the function to convert data to the GT text format and save data to a file.

func saveexpr

{
uint i k
str filename stemp = "<|data>\l"

for i, i < *data, i += 8
{
stemp += "<_ = \"\( data[i] )\""
fornum k = 0, 7
{
stemp += " \("".appendch( 'A' + k ))=\( data[ i + k + 1 ])"
}
stemp += ">\l"
}
stemp += "</data>"
stemp.write( getmodulepath( filename, "calculator.dat"))
}

We add calling the corresponding functions when the 'Save' and 'Help' buttons are clicked to the main handler.

case $IDC_SAVE : appendexpr( 1 )

case $IDC_HELP : helpcontents()
case $IDCANCEL
{
appendexpr( 0 )
saveexpr()
EndDialog( wnd, 1 )
return 1
}

All there is left to do is read calculator.dat and define the name of the CHM file at the beginning of the rpogram.

gtapp += data.read( getmodulepath( stemp, "calculator.dat"))

helpfile( "calculator.chm" )

See also

    Calculator


Copyright © 2004-2005 Gentee, Inc. All rights reserved.