home *** CD-ROM | disk | FTP | other *** search
- #include <owl\owlpch.h>
- #include <owl\applicat.h>
- #include <owl\dc.h>
- #include <owl\dialog.h>
- #include <owl\framewin.h>
- #include <cstring.h>
- #include <ctype.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- #include <astsbpar.h> //Link necessary header
-
- const char AppName[] = "Parser";
- const int ID_PARSFUNC = 500;
- const int ID_VARX = 600;
- const int ID_VARY = 700;
- const int ID_BDEC = 800;
- const int ID_BBIN = 825;
-
- const int ID_DISPLAY = 400;
- const int ID_GETRESULTBTN = 61;
- const int ID_PARSICON = 101;
-
- class TPars : public TDialog {
- public:
- TBrush BlueBrush;
-
- TPars();
- void ParsResult();
- void ClickedDEC();
- void ClickedBIN();
-
- protected:
- void SetupWindow() {
- TDialog::SetupWindow();
-
- CheckDlgButton(ID_BDEC,TRUE);
- ::SetWindowText(GetParent(),"Demo for Borland C++ 5.x");
- }
- void EvPaint();
- HBRUSH EvCtlColor(HDC, HWND hWndChild, UINT ctlType);
-
- void SolveParsVariables();
- void SolveParsBase();
-
- DECLARE_RESPONSE_TABLE(TPars);
- };
-
- DEFINE_RESPONSE_TABLE1(TPars, TDialog)
- EV_WM_PAINT,
- EV_WM_CTLCOLOR,
- EV_BN_CLICKED(ID_GETRESULTBTN,ParsResult),
- EV_BN_CLICKED(ID_BDEC,ClickedDEC),
- EV_BN_CLICKED(ID_BBIN,ClickedBIN),
- END_RESPONSE_TABLE;
-
- TPars::TPars()
- : TWindow((TWindow*)0),
- TDialog(0, AppName),
- BlueBrush(TColor(0, 0, 255))
- {
- }
-
- //--------------------- BEGIN: HOW TO USE --------------------------------------
- void
- TPars::ClickedDEC()
- {
- ::EnableWindow(GetDlgItem(ID_VARX),TRUE);
- ::EnableWindow(GetDlgItem(ID_VARY),TRUE);
- }
-
- void
- TPars::ClickedBIN()
- {
- ::EnableWindow(GetDlgItem(ID_VARX),false);
- ::EnableWindow(GetDlgItem(ID_VARY),false);
- }
-
- void
- TPars::ParsResult()
- {
- if (IsDlgButtonChecked(ID_BDEC)==TRUE) {
- SolveParsVariables();
- }
- if (IsDlgButtonChecked(ID_BBIN)==TRUE) {
- SolveParsBase();
- }
- }
-
- void
- TPars::SolveParsVariables()
- {
- char* functempstr;
- char* xtempstr;
- char* ytempstr;
- char errText[150];
- char tempstr[150];
- long double xyval[2];
- int tempi;
- char *ptr;
- bool err=false;
-
- //Get the function f(x,y)
- tempi=::GetWindowTextLength(GetDlgItem(ID_PARSFUNC));
- functempstr=new char [tempi+1];
- ::GetWindowText(GetDlgItem(ID_PARSFUNC),functempstr,tempi+1);
-
- //Get the value for the variable x as a string
- tempi=::GetWindowTextLength(GetDlgItem(ID_VARX));
- xtempstr=new char [tempi+1];
- ::GetWindowText(GetDlgItem(ID_VARX),xtempstr,tempi+1);
-
- //Get the value for the variable y as a string
- tempi=::GetWindowTextLength(GetDlgItem(ID_VARY));
- ytempstr=new char [tempi+1];
- ::GetWindowText(GetDlgItem(ID_VARY),ytempstr,tempi+1);
-
- //Convert the strings of the variables to long double
- xyval[0]=chartold(xtempstr,&ptr);
- if (strlen(ptr))
- {
- ::MessageBox(HWindow,
- "The string of the variable x cannot be converted to long double.",
- "Error",
- MB_ICONERROR);
- err=true;
- }
- xyval[1]=chartold(ytempstr,&ptr);
- if (strlen(ptr))
- {
- ::MessageBox(HWindow,
- "The string of the variable y cannot be converted to long double.",
- "Error",
- MB_ICONERROR);
- err=true;
- }
-
- if (err==false)
- if (strlen(functempstr)>0)
- {
-
- //Create an sbParser object and receive its HANDLE
- HANDLE hParser;
- hParser= CreateNewParser(functempstr,2,"xy");
-
- long double Result;
-
- if (GetIsError(hParser))
- {
- //An error has occurred
- ::MessageBox(HWindow,
- ldtochar(errText,GetGlobalError(hParser)),"Errornumber in Function",
- MB_ICONERROR);
-
- Result= 0;
- err= true;
- }
- else
- {
- //Compute the result
- Result= GetResultExt(hParser,xyval);
-
- if (GetIsError(hParser))
- {
- //An error has occurred
- ::MessageBox(HWindow,
- ldtochar(errText,GetGlobalError(hParser)),
- "Errornumber in Calculation",MB_ICONERROR);
-
- Result= 0;
- err= true;
- }
- else
- {
- //Convert the long double to a string
- ldtochar(tempstr,Result,10,true);
-
- ::SetWindowText(GetDlgItem(ID_DISPLAY),tempstr);
- }
-
- }
-
- //Delete of the sbParser object
- DeleteParser(hParser);
- }
- else
- {
- ::MessageBox(HWindow,"There is no function to compute.","Error",
- MB_ICONERROR);
- }
-
- if (err)
- {
- ::SetWindowText(GetDlgItem(ID_DISPLAY),"Error");
- }
-
- delete[] functempstr;
- delete[] xtempstr;
- delete[] ytempstr;
- }
-
- void
- TPars::SolveParsBase()
- {
- char* functempstr;
- char errText[150];
- char tempstr[150];
- int tempi;
- bool err=false;
-
- //Get the function f(x,y)
- tempi=::GetWindowTextLength(GetDlgItem(ID_PARSFUNC));
- functempstr=new char [tempi+1];
- ::GetWindowText(GetDlgItem(ID_PARSFUNC),functempstr,tempi+1);
-
- if (strlen(functempstr)>0)
- {
-
- //Create an sbParser object and receive its HANDLE
- HANDLE hParser;
- hParser= CreateNewParser(functempstr,2);
-
- long double Result;
-
- if (GetIsError(hParser))
- {
- //An error has occurred
- ::MessageBox(HWindow,
- ldtochar(errText,GetGlobalError(hParser)),"Errornumber in Function",
- MB_ICONERROR);
-
- Result= 0;
- }
- else
- {
- //Compute the result
- Result= GetResult(hParser);
-
- if (GetIsError(hParser))
- {
- //An error has occurred
- ::MessageBox(HWindow,
- ldtochar(errText,GetGlobalError(hParser)),
- "Errornumber in Calculation",MB_ICONERROR);
-
- Result= 0;
- err= true;
- }
- else
- {
- //Convert the long double to a string for base binary
- ConvertToBase(tempstr,Result,10,2);
-
- ::SetWindowText(GetDlgItem(ID_DISPLAY),tempstr);
- }
-
- }
-
- //Delete of the sbParser object
- DeleteParser(hParser);
- }
- else
- {
- ::MessageBox(HWindow,"There is no function to compute.","Error",
- MB_ICONERROR);
- }
-
- if (err)
- {
- ::SetWindowText(GetDlgItem(ID_DISPLAY),"Error");
- }
-
- delete[] functempstr;
- }
- //--------------------- END: HOW TO USE ----------------------------------------
-
- HBRUSH
- TPars::EvCtlColor(HDC hDC, HWND hWndChild, UINT ctlType)
- {
- TBrush redBrush(TColor(255, 0, 0));
-
- switch (ctlType) {
- case CTLCOLOR_BTN:
- SetBkMode(hDC, TRANSPARENT);
- return (HBRUSH)GetStockObject(NULL_BRUSH);
-
- case CTLCOLOR_STATIC:
- SetTextColor(hDC, TColor::LtYellow);
- SetBkMode(hDC, TRANSPARENT);
- return (HBRUSH)redBrush;
-
- case CTLCOLOR_DLG:
- SetBkMode(hDC, TRANSPARENT);
- return (HBRUSH)BlueBrush;
-
- default:
- return TDialog::EvCtlColor(hDC, hWndChild, ctlType);
- }
- }
-
- void
- TPars::EvPaint()
- {
- TBrush redBrush(TColor(255, 0, 0));
- TPaintDC dc(*this);
-
- dc.SelectObject(redBrush);
- dc.SelectStockObject(NULL_PEN);
-
- TRect clientRect = GetClientRect();
- clientRect.bottom = clientRect.right;
- clientRect.Offset(-clientRect.right/4, -clientRect.right/4);
- dc.Ellipse(clientRect);
- }
-
- //------------------------------------------------------------------------------
-
- class TParsApp : public TApplication {
- public:
- //--------------------- BEGIN: HOW TO USE II -----------------------------
- TParsApp(const char far* name) : TApplication(name) {
- //Loading of the csbparse.DLL
- InitSTDsbParserDLL();
- }
- ~TParsApp() {
- //Unloading of the csbparse.DLL
- DeinitSTDsbParserDLL();
- }
- //--------------------- END: HOW TO USE II -------------------------------
-
- void InitMainWindow();
- };
-
- void
- TParsApp::InitMainWindow()
- {
- TWindow* parsWin = new TPars;
- parsWin->Attr.AccelTable = AppName;
-
- MainWindow = new TFrameWindow(0, Name, parsWin, TRUE);
- MainWindow->SetIcon(this, ID_PARSICON);
- MainWindow->SetIconSm(this, ID_PARSICON);
- MainWindow->Attr.Style &= ~(WS_MAXIMIZEBOX | WS_THICKFRAME);
- }
-
- int
- OwlMain(int /*argc*/, char* /*argv*/ [])
- {
- return TParsApp(AppName).Run();
- }
-