Download documentation |
As a warm-up, let us specify the icon for the main dialog box. We add it during the initialization
setwinicon( wnd, "appres/icon" )
Now we need to link the expression calculation module expression.g. We will not dwell on its content. A simpler variant is taken in detail in example 12. We will need only the calculate function calculating the expression passed to it. Let us define the calcexpr subfunction in the main handler. This subfucntion will take the expression from the IDC_EXPR field for entering expressions and calculate it. The result will be written to the IDC_DRES field in the decimal form and to the IDC_HRES field in the hexadecimal form.
subfunc calcexpr
{
lexem result
str expr stemp
uint dres hres
dres = GetDlgItem( wnd, $IDC_DRES )
hres = GetDlgItem( wnd, $IDC_HRES )
getwintext(GetDlgItem( wnd, $IDC_EXPR ), expr)
setwintext( dres, "" )
setwintext( hres, "")
switch ( calculate( expr, result ))
{
case $NUM_LONG
{
setwintext( dres, str( result.lval ))
long2str( stemp, "%I64X", result.lval )
setwintext( hres, stemp )
}
case $NUM_DOUBLE : setwintext( dres, "\( result.dval )")
}
}
All we have to do is call this function each time the expression is changed. If the expression is not correct, the result fields will remain empty. We add calling calcexpr to the main event handler.
case $IDC_EXPR
{
if codedlg == $CBN_EDITCHANGE : calcexpr()
}
We have the program that already allows us to enter mathematical expressions and get results.
See also![]() |
![]() Copyright © 2004-2005 Gentee, Inc. All rights reserved. ![]() |