equation analyzer

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
i am working on a project using c and gui called equation analyzer i want to make the user enter the limits of x called xmin and xmax but it doesnt feel them this is the code
#include "wingui.h"<br/>
#include "math.h"<br/>
#include <mmsystem.h><br/>
#include "stdlib.h"<br/>
#include <string.h><br/>
#define WM_GETTEXT<br/>
//#include <wingui.h><br/>
//#include <math.h><br/>
#define bool int<br/>
#define false 0<br/>
#define true 1<br/>
float* x;<br/>
float* y;<br/>
float z;<br/>
float xmax;<br/>
float xmin;<br/>
char eqn[200];<br/>
char text[128];<br/>
HWND hFirstEdit;<br/>
HWND hSecondEdit;<br/>
HWND hThirdEdit;<br/>
HWND hFourthEdit;<br/>
HWND hFifthEdit;<br/>
float l,h;<br/>
float k;<br/>
float ymax,ymin;<br/>
float xoff,yoff;<br/>
float xe= 185;<br/>
float ye= 515; //(screenHight -500)<br/>
float px= 900 //(limits i=1100-185)<br/>
;float py= 450 //(limits j=500-50)<br/>
;int xs;<br/>
int ys;<br/>
int xp;<br/>
int yp;<br/>
int xp1;<br/>
int yp1;<br/>
int step= 0.1;<br/>
<br/>
<br/>
<br/>
LRESULT WINAPI WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<br/>
{ int screenWidth = 1300, screenHeight = 1015;<br/>
static char screenText[128] = "0";<br/>
static char oldscreenText[128]= "0";<br/>
switch(message)<br/>
{<br/>
case WM_CREATE:<br/>
{ <br/>
double M,N,h,k,l;<br/>
char text[128];<br/>
char input[1000];<br/>
int screenWidth = GetSystemMetrics(SM_CXSCREEN);<br/>
int screenHeight = GetSystemMetrics(SM_CYSCREEN);<br/>
<br/>
SetWindowLong(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);<br/>
SetWindowPos(hWnd, HWND_TOP, 0, 0,<br/>
screenWidth, screenHeight, SWP_SHOWWINDOW);<br/>
SetWindowText(hWnd, "Equation Analyzer");<br/>
SetWindowLong(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);<br/>
SetWindowPos(hWnd, HWND_TOP, 0, 0,<br/>
screenWidth, screenHeight, SWP_SHOWWINDOW);<br/>
<br/>
<br/>
HWND hControl;<br/>
HWND hFirstEdit;<br/>
HWND hSecondEdit;<br/>
HWND hThirdEdit;<br/>
HWND hFourthEdit;<br/>
HWND hFifthEdit;<br/>
hControl = CreateWindow("Button","" ,WS_CHILD|WS_VISIBLE,5,690,110,20,hWnd, (HMENU)(UINT_PTR)1,NULL,NULL);<br/>
SetWindowText(hControl,"Draw curve");<br/>

<br/>
hControl = CreateWindow("Button","" ,WS_CHILD|WS_VISIBLE,130,690,110,20,hWnd, (HMENU)(UINT_PTR)1,NULL,NULL);<br/>
SetWindowText(hControl,"Draw equation");<br/>
<br/>
hControl = CreateWindow("Button","" ,WS_CHILD|WS_VISIBLE,260,690,110,20,hWnd, (HMENU)(UINT_PTR)1,NULL,NULL);<br/>
SetWindowText(hControl,"Integration");<br/>

<br/>
hControl = CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,10,550,900,60,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
SetWindowText(hControl,"");<br/>
<br/>
hControl = CreateWindow("STATIC","",WS_CHILD|WS_VISIBLE,5,620,30,20,hWnd,(HMENU)(UINT_PTR)3,NULL,NULL);<br/>
SetWindowText(hControl,"Y = ");<br/>
hFirstEdit = CreateWindow("EDIT","0",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,35,620,900,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
GetWindowText(hFirstEdit,text,128);<br/>
h= atof(text);<br/>
<br/>
hControl = CreateWindow("STATIC","",WS_CHILD|WS_VISIBLE,5,650,40,20,hWnd,(HMENU)(UINT_PTR)3,NULL,NULL);<br/>
SetWindowText(hControl,"from");<br/>
hControl = CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,50,650,40,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
hSecondEdit = CreateWindow("EDIT","0",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,50,650,40,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
<br/>
<br/>
<br/>
hControl = CreateWindow("STATIC","",WS_CHILD|WS_VISIBLE,100,650,30,20,hWnd,(HMENU)(UINT_PTR)3,NULL,NULL);<br/>
SetWindowText(hControl,"to");<br/>
hControl = CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,125,650,50,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
hThirdEdit = CreateWindow("EDIT","0",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,125,650,50,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
<br/>
<br/>
<br/>
hControl = CreateWindow("STATIC","",WS_CHILD|WS_VISIBLE,200,650,75,20,hWnd,(HMENU)(UINT_PTR)3,NULL,NULL);<br/>
SetWindowText(hControl,"Resolution");<br/>
hControl = CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER|ES_MULTILINE,290,650,40,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
hFourthEdit = CreateWindow("EDIT","0",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,290,650,40,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
GetWindowText(hSecondEdit,text,128);<br/>
M= atof(text);<br/>
<br/>
hControl = CreateWindow("STATIC","",WS_CHILD|WS_VISIBLE,350,650,30,20,hWnd,(HMENU)(UINT_PTR)3,NULL,NULL);<br/>
SetWindowText(hControl,"X = ");<br/>
hControl = CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER|ES_MULTILINE,400,650,50,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
hFifthEdit = CreateWindow("EDIT","0",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,400,650,50,20,hWnd,(HMENU)(UINT_PTR)2,NULL,NULL);<br/>
GetWindowText(hSecondEdit,text,128);<br/>
N= atof(text);<br/>
<br/>
<br/>
}<br/>
break;<br/>
<br/>
case WM_PAINT:<br/>
{<br/>
<br/>
int n=-10;<br/>
int m=20;<br/>
int i;<br/>
int j;<br/>
HDC hDC = GetDC(hWnd);<br/>
PatBlt(hDC, 30, 20, 1200, 520, BLACKNESS);<br/>
HFONT hFont = WGCreateFont("Calibri", 15, FS_BOLD, 0);<br/>
HFONT hFont1 = WGCreateFont("Calibri", 15, FS_BOLD, 900);<br/>
HPEN hPen = WGCreatePen(RGB(250,0,0), 0.3, PS_SOLID);<br/>
HPEN hPen1 = WGCreatePen(RGB(0,250,0), 2, PS_SOLID);<br/>
HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);<br/>
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(200, 200, 200));<br/>
WGPrintf(hDC, 560, 520,"xLable");<br/>
WGPrintf(hDC, 60, 30,"x 1E+006");<br/>
WGPrintf(hDC, 1180, 510,"x1");<br/>
HFONT hOldFont1 = (HFONT)SelectObject(hDC, hFont1);<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(200, 200, 200));<br/>
WGPrintf(hDC, 80, 300,"y Lable");<br/>
SelectObject(hDC, hOldFont1);<br/>
for(i= 185; i<=1100; i+=25)<br/>
{<br/>
MoveToEx(hDC, i, 50, NULL);<br/>
LineTo(hDC, i, 500);<br/>
//d=235;<br/>
if(i<=635)<br/>
{<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(50, 0, 200));<br/>
//WGPrintf(hDC, (2*(i-185)+175), 500, "%0.1f", n);<br/>
n+= ((xmax- xmin)/18);<br/>
}<br/>
}<br/>
for(j= 50; j<=500; j+=25)<br/>
{<br/>
MoveToEx(hDC, 185, j, NULL);<br/>
LineTo(hDC, 1085, j);<br/>
<br/>
if(j!=0)<br/>
{<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(150, 0, 200));<br/>
//WGPrintf(hDC, 150, j-8, "%0.1f", m);<br/>
m-=((ymax-ymin)/18);<br/>
}<br/>
}<br/>
SelectObject(hDC, hOldFont);<br/>
SelectObject(hDC, hOldPen);<br/>
DeleteObject(hFont);<br/>
DeleteObject(hPen);<br/>
DeleteObject(hFont1);<br/>
DeleteObject(hPen1);<br/>
ReleaseDC(hWnd, hDC);<br/>
}<br/>
break;<br/>
case WM_CLOSE:<br/>
{<br/>
if(MessageBox(hWnd, "Do you want to exit the program?", "Equation Analyzer",MB_OKCANCEL|MB_ICONEXCLAMATION)==IDCANCEL)<br/>
{<br/>
return 0;<br/>
}<br/>
}<br/>
break;<br/>
<br/>
<br/>
case WM_COMMAND:<br/>
{ HPEN hPen1 = WGCreatePen(RGB(0,250,0), 2, PS_SOLID);<br/>
HDC hDC = GetDC(hWnd);<br/>
WORD controlEvent=HIWORD(wParam);<br/>
WORD controlID=LOWORD(wParam);<br/>
HWND hControl=(HWND)lParam;<br/>

<br/>
switch(controlID)<br/>
{<br/>
<br/>
case 1:<br/>
{<br/>
if(controlEvent==BN_CLICKED)<br/>
{<br/>
case WM_PAINT:<br/>
{ float xmin=l;<br/>
float xmax=k;<br/>
int a;<br/>
float b;
<br/>
z= ((xmax-xmin)/step)+1;<br/>
x = new float[z];<br/>
y = new float[z];<br/>
<br/>
GetWindowText(hSecondEdit,text,128);<br/>
k= atof(text);
<br/>
GetWindowText(hThirdEdit,text,128);<br/>
l= atof(text);
<br/>
for(a= 0; a<z ; a++)<br/>
{<br/>
x[a]= xmin +(a*step);<br/>
y[a]= pow(x[a],2);<br/>
<br/>
}<br/>
ymax= 0;<br/>
ymin= 0;<br/>
for(a= 0; a<z; a++)<br/>
{<br/>
if(y[a]<ymin)<br/>
ymin= y[a];<br/>
if(y[a]>ymax)<br/>
ymax= y[a];<br/>
}<br/>
float n= xmin;<br/>
float m= ymax;<br/>
int i;<br/>
int j;<br/>
float d;<br/>
xs= px/(xmax-xmin);<br/>
ys= py/(ymax-ymin);<br/>
xoff= xe-(xmin*xs);<br/>
yoff= ye-(ymin*ys);<br/>
HDC hDC = GetDC(hWnd);<br/>
PatBlt(hDC, 30, 20, 1200, 520, BLACKNESS);<br/>
HFONT hFont = WGCreateFont("Calibri", 15, FS_BOLD, 0);<br/>
HFONT hFont1 = WGCreateFont("Calibri", 15, FS_BOLD, 900);<br/>
HPEN hPen = WGCreatePen(RGB(250,0,0), 0.3, PS_SOLID);<br/>
HPEN hPen1 = WGCreatePen(RGB(0,250,0), 2, PS_SOLID);<br/>
HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);<br/>
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(200, 200, 200));<br/>
WGPrintf(hDC, 560, 520,"xLable");<br/>
WGPrintf(hDC, 60, 30,"x 1E+006");<br/>
WGPrintf(hDC, 1180, 510,"x1");<br/>
HFONT hOldFont1 = (HFONT)SelectObject(hDC, hFont1);<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(200, 200, 200));<br/>
WGPrintf(hDC, 80, 300,"y Lable");<br/>
SelectObject(hDC, hOldFont1);<br/>
for(a= 0; a<z-1; a++)<br/>
{<br/>
<br/>
HPEN hOldPen1 = (HPEN)SelectObject(hDC, hPen1);<br/>
xp= (x[a]*xs)+ xoff;<br/>
yp= yoff+(y[a]*ys);<br/>
<br/>
if(yp<=(screenHeight-500))<br/>
{<br/>
yp= screenHeight-500;<br/>
}<br/>
if(yp>=(screenHeight-50))<br/>
{<br/>
yp= screenHeight-50;<br/>
}<br/>
yp = screenHeight - yp;<br/>
xp1= (x[a+1]*xs)+ xoff;<br/>
yp1= yoff+(y[a+1]*ys);<br/>
if(yp1<=(screenHeight-500))<br/>
{<br/>
yp1= screenHeight-500;<br/>
}<br/>
if(yp1>=(screenHeight-50))<br/>
{<br/>
yp1= screenHeight-50;<br/>
}<br/>
yp1 = screenHeight - yp1;<br/>
<br/>
MoveToEx(hDC, xp, yp, NULL);<br/>
<br/>
LineTo(hDC, xp1, yp1);<br/>
<br/>
SelectObject(hDC, hOldPen1);<br/>
}<br/>
for(i= 185; i<=1100; i+=25)<br/>
{<br/>
MoveToEx(hDC, i, 50, NULL);<br/>
LineTo(hDC, i, 500);<br/>
//d=235;<br/>
if(i<=635)<br/>
{<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(50, 0, 200));<br/>
WGPrintf(hDC, (2*(i-185)+175), 500, "%0.1f", n);<br/>
n+= ((xmax- xmin)/18);<br/>
}<br/>
}<br/>
for(j= 50; j<=500; j+=25)<br/>
{<br/>
MoveToEx(hDC, 185, j, NULL);<br/>
LineTo(hDC, 1085, j);<br/>
<br/>
if(j!=0)<br/>
{<br/>
SetBkMode(hDC, TRANSPARENT);<br/>
SetTextColor(hDC, RGB(150, 0, 200));<br/>
WGPrintf(hDC, 150, j-8, "%0.1f", m);<br/>
m-=((ymax-ymin)/18);<br/>
}<br/>
}<br/>
SelectObject(hDC, hOldFont);<br/>
SelectObject(hDC, hOldPen);<br/>
DeleteObject(hFont);<br/>
DeleteObject(hPen);<br/>
DeleteObject(hPen1);<br/>
ReleaseDC(hWnd, hDC);<br/>
}<br/>
}<br/>
break;<br/>
<br/>
<br/>
}<br/>
}<br/>
}<br/>
}<br/>
<br/>
<br/>
return WGDefaultWindowProc(hWnd, message, wParam, lParam);<br/>
}<br/>
<br/>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)<br/>
{<br/>
return WGCreateMainWindow(hInstance, nCmdShow, WndProc);<br/>
}

View the full article
 
Back
Top