Click here to Skip to main content
13,455,913 members (49,116 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 6 Apr 2005


, 6 Apr 2005
Rate this:
Please Sign up or sign in to vote.
An article for drawing a String formula at a static.


This article describes how you can add a static control to show a math function (or deferential or integral of it). This control is a CStatic base. First of all, add 2DStatic.h and 2DStatic.cpp files to your project. Select Resource tab from Workspace window, and select your dialog that you want to add a display static. Select Static Control from Control Toolbox and draw it on dialog (Figure 1). Change its ID from IDC_STATIC to IDC_MyStc.

Figure 1 - Add Static and Button control to your dialog.

Now it's time to add a member variable to your dialog class. Call Class Wizard to do it for you. Figure 2 shows you how to do it. In this case, we add a member variable m_MyStc with type CStatic.

Figure 2 - Add member variable to your dialog class.

OK, open your dialog class header file, add this line on top of your class definition: #include "2DStatic.h".

// 2DFunctionDlg.h : header file

#if !defined(AFX_2DFUNCTIONDLG_H__D5D048D5_079A_
#define AFX_2DFUNCTIONDLG_H__D5D048D5_079A_40BD_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "2DStatic.h"
// C2DFunctionDlg dialog

class C2DFunctionDlg : public CDialog
// Construction
  C2DFunctionDlg(CWnd* pParent = NULL);  // standard constructor

// Dialog Data
  C2DStatic  m_MyStc;    //We change it from CStatic m_MyStc; 
                            //to C2DStatic m_MyStc;

  // ClassWizard generated virtual function overrides
  virtual void DoDataExchange(CDataExchange* pDX);  
           // DDX/DDV support

// Implementation
  HICON m_hIcon;

  // Generated message map functions
  afx_msg void OnPaint();
  afx_msg HCURSOR OnQueryDragIcon();

// Microsoft Visual C++ will insert additional declarations 
// immediately before the previous line.

#endif // !defined(AFX_2DFUNCTIONDLG_H__D5D048D5_079A_40BD_

Now you can draw any function you want, only with two functions SetInitialValue, DrawFunction. E.g.:

DrawFunction(0,"sin(x)");            // Draw y=sin(x)
DrawFunction(1,"tan(x)");            // Draw y=1+tan(x)^2
DrawFunction(2,"3*x^2-2*x-4)");        // Draw y=x^3-x^2-4*x+c

Member Functions

/* Set and Convert the scales */
// to Set the scale of the Static Control 
SetInitialValue(float xMin,float xMax,float yMin,float yMax);
// to change the real pixel to Static Pixel
CPoint GetNewPixel(float x,float y);

/* Math Functions */
double  MathFunc(double x);  // return y=f(x)
double FuncDef(double x);    // return y=deferential of f(x)
double FuncInt(double x);    // return y=Integral of f(x)

/* Displaying Functions */
void ShowMathFunc(CDC* pDC); // Show f(x) in static in desired scale
void ShowFuncDef(CDC* pDC);  // Show def f(x) in static in desired scale
void ShowFuncInt(CDC* pDC);  // Show int f(x) in static in desired scale

// to Draw the Function or Deferential or Integral 
bool DrawFunction(int iKind,CString sFormula);

/* String Processing Functions */
// to simaulaShow int f(x) in static in desired scale
bool SetIndexPra(CString StrFormula);
// to seprate String to two strings include Operators ( sAr[100] ) and
// integers ( Ar[100] ) and iAr ( the number of operators )
bool SimString(CString StrEdit);
// to obtain the value of function with sAr,iAr,Ar 
double StrToInt();
// to obtain Special Funnction like sin,log,… from String 
double Specialfunc(CString SpFunc);
// to find next operator after a found operator
int FindNextOperation(CString strEdit,int iIndex);
// to find operator before special functions
CString FindOpBeforeSpc(CString StrEdit);


I thank Mr. Abbas Riazi and Mr. Mehdi Bonvori for their guidance. This class has 2D draw functions and I tried to make a powerful string processing in it. But I'm sure there are a lot of problems when you use it. I'll be grateful if you give feedback on the problems, to me.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
I live in Iran . I started hardware programming when I was young. I designed and built some ISA cards for attaching to ocsiloscope and signal generator. Now I am working for a engineering company and Manager of some project.

You may also be interested in...

Comments and Discussions

GeneralExcellent! Pin
A. Riazi17-Apr-05 0:44
memberA. Riazi17-Apr-05 0:44 
GeneralGood but ... Pin
M. Bonvari16-Apr-05 6:42
memberM. Bonvari16-Apr-05 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180322.1 | Last Updated 7 Apr 2005
Article Copyright 2005 by asef
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid