# Thread: Graphing Calculator..

1. ## Graphing Calculator..

hey..i was wondering how hard it would be to write a graphing calculator. like, what kind of understanding would it take to make such a thing? and how would dealing with variables (such as: Y1 = 3x-2) work? is anyone aware of a tutorial dealing with the knowledge needed? i did a search on google but i'm unsure what to search for and the one i did didn't come up with anything..

thanks

2. You're probably not going to find a tutorial on "How to make a graphing calculator program". If there were tutorials for every kind of program, we wouldn't need programmers, now would we?

You'd need to be pretty good at parsing strings (dealing with variables...). You'd need to know the math itself, obviously, and you'd also need to know some basic graphics.

3. You would need to convert the equation from infix to postfix. You would then need to solve the postfix expression for incremental values of the independent variable. Once you have a sufficient number of graph points, then you can plot them on your graph window.

4. >> You're probably not going to find a tutorial on "How to make a graphing calculator program".
hmm...
is anyone aware of a tutorial dealing with the knowledge needed?
lol i wouldn't like that kind of tutorial, i'd like a tutorial that will drill into my brain the individual steps of the different functions needed so that i can combine them and make the final product.
i'm also quite glad there isn't such a tutorial as it would make the task much more dull and typical.

pretty good at parsing strings.. i'd say i'm not bad. i like math i've written a hangman program..? lol its fun but i'm guessing by dealing with graphics you mean something less bitmap related..?

infix? postfix? mm..i'll look these up. what should i use for making the graph window?

5. what should i use for making the graph window?
You could always use the GDI draw functions. If you already know how to use a graphics API like OpenGL, then you could use that as well.

If you are not already experienced with using the Windows API, then using GDI to create a graph may be a little too ambitous for you. On the other hand, attempting overly abitious projects can lead to a massive growth in your programming expertise.

At any rate, good luck to you.

6. I've made a few programs using thw Win API.. i'll look up the GDI draw functions.

but i agree, overambition usually generates much learning. hence the reason i'm here. lol but i've never written anything in OpenGL...or DirectX. i've check out some tutorials on OpenGL but thats about as far as that went. lol

7. mm...k so its really sad that i can't even get the window made but i keep getting error code 1813 which according to MSDN is
ERROR_RESOURCE_TYPE_NOT_FOUND
1813 The specified resource type cannot be found in the image file.
i have no clue why..i've tried having the defaults for the icons, having no menu, yeaihavenoclue...here's my WinMain
Code:
```int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
LONG errorcode;
char error[20] = {0};

g_hInst = hInstance;

wc.cbSize         = sizeof(WNDCLASSEX);
wc.style          = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc    = WndProc;
wc.cbClsExtra     = 0;
wc.cbWndExtra     = 0;
wc.hInstance      = hInstance;
wc.hIcon          = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(ID_GRAPHICO));
wc.hIconSm        = (HICON)LoadImage (GetModuleHandle(NULL), MAKEINTRESOURCE(ID_GRAPHICO), IMAGE_ICON, 16, 16, 0);
wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName  = g_szClassName;
wc.hbrBackground  = (HBRUSH)(COLOR_BTNFACE+1);

if (!RegisterClassEx(&wc))
{
MessageBox(NULL, "There was a problem registering the window class.\nProgram creation has failed.",
"Error!", MB_OK | MB_ICONERROR);
errorcode = GetLastError();
_itoa(errorcode, error, 10);
MessageBox(NULL, error, "Error code", MB_OK);
return (0);
}

hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "Graphing Calculator - Shibby Inc. ©",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 325, 475, HWND_DESKTOP, NULL, hInstance, NULL);

if (hwnd == NULL)
{
MessageBox(NULL, "There was a problem creating the window.\nProgram creation has failed.",
"Error!", MB_OK | MB_ICONERROR);
errorcode = GetLastError();
_itoa(errorcode, error, 10);
MessageBox(NULL, error, "Error code", MB_OK);
return (0);
}

ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);

// The Great and Mighty Message Loop
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}```
? any ideas ?

..i even get the error when using the code from winprog.net so i'm thinking its my compiler... ? I'm using Dev-C++ 4.9.9.2, Windows XP Pro SP2, and i haven't changed anything since the last time i compiled something.
I also have Dev-C++ installed to my flash drive and i have Visual C++ 2005 Express Edition Beta 2 installed on my pc and i get the same error with all of the above, "There was a problem creating the window. Program creation has failed."

8. First of all, you should zero out your WNDCLASSEX structure before you fill it. If you are still having a problem with CreateWindow() returning NULL, then make sure your resource IDs are valid. Consider using some defaults instead:
Code:
```    wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor        = LoadCursor(NULL, IDC_ARROW);```

9. i have used those defaults.
i have no clue why..i've tried having the defaults for the icons, having no menu,...

there was still problem 1813 creating the window. >:O arg.

10. To avoid excessively coding and re-coding a window I just made one file that was a blank window. I use that as a template when I make other programs using windows similar to that, otherwise I rewrite the whole thing. If you want here it is attached:

11. hmm....a good idea. lol

12. Just a tip:

You have this:

Code:
```
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC		 hdc ;
PAINTSTRUCT ps ;
RECT		rect ;

switch (message)
{
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}```
If you had this:

Code:
```
HDC		 hdc ;
PAINTSTRUCT ps ;
RECT		rect ;

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}```
It wouldn't be as hard on the memory.

The reason for this is because if the way you have it, it would have to declare all three of those vars every time the window calls that function. Which would be a lot of times.

13. It wouldn't be as hard on the memory.

The reason for this is because if the way you have it, it would have to declare all three of those vars every time the window calls that function. Which would be a lot of times.
I'm not sure what you mean by "hard on the memory" and I doubt that making those variables global is worthwhile . Even if there is some slight performance boost (it might translate to a few less assembly instructions, I guess), you now have three global variables that stay in memory as long as the application is running. And besides that, they retain their values each time the function is called. If someone needs that, they can always use static variables.

In any case, it just seems like bad style to me. If you don't need variables outside of a function, don't declare them outside of a function.

Popular pages Recent additions