Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Paint XY (V1.2) - main.cpp

main.cpp

Caricato da: Dany
Scarica il programma completo

  1. /***************************************************
  2. ***********PAINT XY*********************************
  3. ***********AUTORE:  DANY****************************
  4. ***********DATA:  13/06/2012************************
  5. ***********ORE:  14:41******************************
  6. ***********VERSIONE:  1.2***************************/
  7.  
  8. //Dichiarazione Header
  9. #include <windows.h>
  10. #include <Windowsx.h>
  11. #include <commctrl.h>
  12. #include <cmath>
  13. #include <stack>  
  14. #include <fstream>
  15. #include <cstring>
  16. //Dichiarazione librerie:
  17. #include "funzioni.h"
  18. //Dichiarazioni per visual style (grafica win 7)
  19. #pragma comment( lib, "comctl32.lib")
  20. #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  21. //Fine Dichiarazioni...                                                                                            //prima della p--> \
  22. //Namespace:
  23. using namespace std;
  24. //Dichiarazione variabili globali:
  25. //Class Name delle finestre
  26. static char g_szClassName[] = "MainWindow",name[]="CurveWindow",name2[]="FunctionWindow",name3[]="SettingWindow";
  27. static HINSTANCE g_hInst = NULL;
  28. //Timer per la WM_Timer nella mainWindows
  29. const UINT idTimer1 = 1;
  30. UINT nTimerDelay = 1;
  31. //Bitmap
  32. HBITMAP hbmBall, hbmMask,griglia,maskgri;
  33. BITMAP bm;
  34. //Coordinate Punto funzione
  35. int ballX, ballY;
  36. //Variabile che indica se è stato cliccato il tasto disegna nella finestra delle curve
  37. int agg=0;  
  38. //Font dei Caratteri:
  39. RECT rect;
  40. HFONT hfont;
  41. LOGFONT lf;
  42. //Precisione nel disegno delle funzioni
  43. float prec=100;
  44. float preprec;   //Se si clicca annulla nella setting window ripristina il valore precedente di prec.
  45. //Progress Bar in Curve Window
  46. HWND prog;
  47. //Progress Bar in function windows
  48. HWND prog2;
  49. //stringa che in function window contiene la funzione in notazione polacca inversa.
  50. string rpn;
  51. //Variabile che indica se il pulsante disegna in function window è stato premuto.
  52. int funpress=0;
  53. //Stringa che se nella function windows viene digitata una funzione correttamente, ne assume il contenuto.
  54. char funzione[100]="";
  55. //Per ridisegno funzioni in caso di copertura:
  56. string cache[20];  int cachenum=0;
  57.  
  58. //Dichiarazione della WndProc Della MainWindow
  59. LRESULT CALLBACK WndProc(HWND hwnd ,UINT Message, WPARAM wParam, LPARAM lParam);
  60. //Disegna il punto utilizzato nelle rappresentazioni di cruve e funzioni.
  61. void DrawBall(HDC hdc)
  62. {
  63.    HDC hdcMemory;
  64.    hdcMemory = CreateCompatibleDC(hdc);
  65.  
  66.    SelectObject(hdcMemory, hbmMask);
  67.    BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCAND);
  68.  
  69.    SelectObject(hdcMemory, hbmBall);
  70.    BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCPAINT);
  71.  
  72.    DeleteDC(hdcMemory);
  73. }
  74. //Disegna la griglia di sfondo
  75. void DrawGriglia(HDC hdc)
  76. {
  77.      HDC hdcMemory;
  78.      hdcMemory=CreateCompatibleDC(hdc);
  79.          SelectObject(hdcMemory, maskgri);
  80.          BitBlt(hdc, 0, 0, 1000, 1000, hdcMemory, 0, 0, SRCAND);
  81.          SelectObject(hdcMemory, griglia);
  82.      BitBlt(hdc, 0, 0, 1000, 1000, hdcMemory, 0, 0, SRCPAINT);
  83.      DeleteDC(hdcMemory);
  84. }
  85. //Converte le ascisse in coordinate x per la finestra
  86. int conx(double s)
  87. {
  88.         int con;
  89.         con=int(500+(s*50));
  90.         return con;
  91. }
  92. //Converte le ordinate in coordinate y per la finestra
  93. int cony(double s)
  94. {
  95.         int con;
  96.         con=int(500-(s*50));
  97.         return con;
  98. }
  99. //Controlla se il carattere nello stack è una funzione
  100. int chkfun (char a)
  101. {
  102.         if ((a=='s')||(a=='c')||(a=='t')||(a=='a')||(a=='b')||(a=='d')||(a=='h')||(a=='i')||(a=='j')||
  103.                         (a=='L')||(a=='N')||(a=='D')||
  104.                                 (a=='A')||(a=='I')||(a=='P')||(a=='!')||(a=='V')||
  105.                                         (a=='R')||(a=='C')||(a=='Q'))
  106.         {
  107.                 return 1;
  108.         }
  109.         else
  110.                 return 2;
  111. }
  112. //Controlla se (nella Function Window) nella conversione RPN, un carattere è una costante (o una variabile) o un'operatore
  113. int chkchar(char a)    
  114. {  
  115.         if ((('0'<=a)&&(a<='9'))||(a=='x')||(a=='X')||(a=='p')||(a=='e'))       //Il carattere è una cifra, una costante o la variabile x.
  116.         {
  117.                 return 1;
  118.         }
  119.         if ((a=='+')||(a=='-')||(a=='*')||(a=='/')||(a=='^')||(a=='%'))                //Il carattere è un operatore
  120.         {
  121.                 return 2;
  122.         }
  123.         else
  124.                 return 3;
  125. }
  126. //Controlla la precedenza tra 2 operatori
  127. bool precedence(char op1, char op2)
  128. {
  129.         int first=0;
  130.         if ((op1=='+')||(op1=='-'))
  131.         {
  132.                 first=1;
  133.         }
  134.         if ((op1=='*')||(op1=='/')||(op1=='%'))
  135.         {
  136.                 first=2;
  137.         }
  138.         if ((op1=='^')||(chkfun(op1)==1))
  139.         {
  140.                 first=3;
  141.         }
  142.         /*******************/
  143.         int second=0;
  144.         if ((op2=='+')||(op2=='-'))
  145.         {
  146.                 second=1;
  147.         }
  148.         if ((op2=='*')||(op2=='/')||(op2=='%'))
  149.         {
  150.                 second=2;
  151.         }
  152.         if ((op2=='^')||(chkfun(op2)==1))
  153.         {
  154.                 second=3;
  155.         }
  156.         if ((first == second)||( first < second))
  157.                 return false;
  158.         else
  159.                 return true;
  160. }
  161. //Conta le cifre di un numero intero
  162. float numcif (int a)
  163. {
  164.         double aa=a;
  165.        if (a<0)
  166.        {
  167.           aa=-a;
  168.        }
  169.        double b;
  170.            float c;
  171.        b=log10(aa);
  172.        c=ceil(b);
  173.        if (c==b)
  174.        {
  175.           c++;
  176.        }
  177.        if (a==0)
  178.        {
  179.           c=1;
  180.        }
  181.        return c;
  182. }
  183. /*************************************************************************************************************/
  184. //Dichiarazione variabili in WndProc
  185. //Variabili disegno funzione
  186. double i,x,y;
  187. double inc=0.01;           /*   1/standard inc    */
  188. //Variabili Menu:
  189. HMENU file,hfile,info,hinfo,modifica,hmodifica;
  190. int MENU_FILE_EXIT=0;  //Valore ritorno se si clicca su "Esci"
  191. int MENU_FILE_CURV=1;  //Valore ritorno se si clicca su "Disegna curve"
  192. int MENU_FILE_FUNZ=2;  //Valore ritorno se si clicca su "Disegna funzione"
  193. int MENU_FILE_ABOU=3;  //Valore ritorno se si clicca su "Informazioni su "Paint XY"
  194. int MENU_FILE_CLEA=6;  //Valore ritorno se si clicca su "Pulisci"
  195. int MENU_FILE_SETT=7;  //Valore ritorno se si clicca su "Opzioni"
  196. //Variabile che specificano il tipo di curva scelto.
  197. int curva;   //retta=1,parabola=2,ellisse=3,iperbole=4,circonferenza=5,parabola(x)=6
  198. //Variabili di lettura degli edit nella finestra delle curve...
  199. char numa[5],numb[5],numc[5];
  200. //...e di converzione di questi:
  201. double a,b,c;
  202. /*Array necessari per ridisegnare le curve nel caso si riduce a icona la finestra...
  203. Gli array memorizzano i vari coefficienti per ogni curva e vengono letti per ridisegnarle.*/
  204. double ca[20],cb[20],cc[20];
  205. double da[20],db[20],dc[20];
  206. double ea[20],eb[20],ec[20];
  207. double fa[20],fb[20],fc[20];
  208. double ga[20],gb[20],gc[20];
  209. double ha[20],hb[20],hc[20];
  210. //Variabili contatrici
  211. int k=0,l=0,l2=0,l3=0,l4=0,l5=0,l6=0;
  212. /*Variabile che indica se si è già tentato di disegnare la funzione:
  213. Per non rendere troppo pesante l'avvio del programma, il prog inizierà a
  214. ridisegnare le funzioni (se la finestra viene ridotta e riaperta) solo dopo
  215. aver premuto il tasto "disegna" nella CurveWindow.*/
  216. int bo=0;
  217. /*Variabile contatrice di array di string che contengono rpn*/
  218. int lo=0;
  219. /*Variabili posizione mouse*/
  220. HWND lex,ley;
  221. float  cox=0,coy=0;
  222. char coox[4],cooy[4];
  223.  
  224. /*WNDPROC DELLA MAIN*/
  225. LRESULT CALLBACK WndProc(HWND hwnd ,UINT Message, WPARAM wParam, LPARAM lParam)
  226. {  
  227.         InitCommonControls ();   //Applicazione visual style
  228.        
  229.    switch(Message)
  230.    {
  231.       case WM_CREATE:
  232.                   //Nella finestra principale:
  233.                   //Inizializzazione delle immagini BMP
  234.           hbmBall = LoadBitmap(g_hInst, "BALLBMP");
  235.           griglia = LoadBitmap(g_hInst, "gri");
  236.           hbmMask = LoadBitmap(g_hInst, "MASKBMP");
  237.                   maskgri = LoadBitmap(g_hInst, "maskgri");
  238.           if(!hbmBall || !hbmMask)
  239.           {
  240.                                 MessageBox(hwnd, "Load of resources failed.", "Error",MB_OK | MB_ICONEXCLAMATION);
  241.                                 return -1;
  242.           }
  243.           GetObject(hbmBall, sizeof(bm), &bm);
  244.                   //Timer:
  245.           SetTimer(hwnd, idTimer1, nTimerDelay, NULL);
  246.                   //Menu:
  247.                   //Dichiarazione Menu:
  248.                   file=CreateMenu();
  249.                   hfile=CreatePopupMenu();
  250.                   info=CreateMenu();
  251.                   hinfo=CreatePopupMenu();
  252.                   modifica=CreateMenu();
  253.                   hmodifica=CreatePopupMenu();
  254.                   //Creazione Menu:
  255.                   /*File*/
  256.           AppendMenu(file,MF_STRING|MF_POPUP,(UINT_PTR) hfile,TEXT("File"));
  257.                   AppendMenu(hfile,MF_STRING,MENU_FILE_SETT,TEXT("Impostazioni"));
  258.           AppendMenu(hfile,MF_STRING,MENU_FILE_EXIT,TEXT("Esci"));
  259.                   /*Modifica*/
  260.                   AppendMenu(file,MF_STRING|MF_POPUP,(UINT_PTR) hmodifica,TEXT("Grafico"));
  261.           AppendMenu(hmodifica,MF_STRING,MENU_FILE_CURV,TEXT("Disegna Curve"));
  262.                   AppendMenu(hmodifica,MF_STRING,MENU_FILE_FUNZ,TEXT("Disegna Funzione"));
  263.                   AppendMenu(hmodifica,MF_STRING,MENU_FILE_CLEA,TEXT("Pulisci"));
  264.                   /*Info*/
  265.                   AppendMenu(file,MF_STRING|MF_POPUP,(UINT_PTR) hinfo,TEXT("Info"));
  266.                   AppendMenu(hinfo,MF_STRING,MENU_FILE_ABOU,TEXT("Informazioni su Paint XY"));
  267.                   //Rende visibile i menu
  268.                   SetMenu(hwnd,file);  
  269.                   //Piccolo edit che scrive la posizione del mouse nella finestra:
  270.                   lex=CreateWindow("edit","",WS_CHILD|WS_VISIBLE|ES_READONLY|WS_BORDER,5,5,50,20,hwnd,(HMENU)100,0,0);
  271.                   ley=CreateWindow("edit","",WS_CHILD|WS_VISIBLE|ES_READONLY|WS_BORDER,60,5,50,20,hwnd,(HMENU)100,0,0);
  272.                   /****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
  273.                   GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  274.                   hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  275.           CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
  276.                   SendMessage (lex, WM_SETFONT, (WPARAM) hfont, true);
  277.                   SendMessage (ley, WM_SETFONT, (WPARAM) hfont, true);
  278.  
  279.           break;
  280.       case WM_TIMER:
  281.          if(hbmBall && hbmMask)
  282.          {
  283.             HDC hdcWindow;
  284.             hdcWindow = GetDC(hwnd);
  285.                         //Disegno Curve***********************************************************************
  286.                         if (agg>0)   //Se è stato cliccato il tasto 'disegna' nella finestra delle curve
  287.                         {
  288.                                 agg=0;       //reimposta il tasto
  289.                                 i=-10;
  290.                         while(i<=10)
  291.             {
  292.                                 i=i+inc;     //inc è l'incremento, modificabile nella setting window
  293.                                 x=i;
  294.                                 SendMessage(prog, PBM_SETPOS,WPARAM ((i+10)*100/20), 0);   //Setto la progressBar
  295.                                 if (curva==1)  //(retta)
  296.                                 {
  297.                                         a=atof(numa);
  298.                                         b=atof(numb);
  299.                                         c=atof(numc);
  300.                                         if (b!=0)
  301.                                         y=((-c-(a*x))/b);
  302.                                         else           //se la retta è parallela all'asse y
  303.                                         {
  304.                                                 x=c/a;
  305.                                                 y=i;
  306.                                         }
  307.                                         //Converte i numeri in coordinate in pixel:
  308.                                         ballX=conx(x);
  309.                                         ballY=cony(y);
  310.                                         DrawBall(hdcWindow);
  311.                                 }
  312.                                 if (curva==2)  //(parabola con asse parallelo all'asse delle y)
  313.                                 {
  314.                                         a=atof(numa);
  315.                                         b=atof(numb);
  316.                                         c=atof(numc);
  317.                                         y=(a*x*x)+(b*x)+c;
  318.                                         //Converte i numeri in coordinate in pixel:
  319.                                         ballX=conx(x);
  320.                                         ballY=cony(y);
  321.                                         DrawBall(hdcWindow);
  322.                                 }
  323.                                 if (curva==3)  //(Ellisse)
  324.                                 {
  325.                                         a=atof(numa);
  326.                                         b=atof(numb);
  327.                                         y=sqrt(b*b*(a*a-x*x)/(a*a));
  328.                                         //Converte i numeri in coordinate in pixel:
  329.                                         ballX=conx(x);
  330.                                         ballY=cony(y);
  331.                                         DrawBall(hdcWindow);
  332.                                         y=-sqrt(b*b*(a*a-x*x)/(a*a));
  333.                                         //Converte i numeri in coordinate in pixel:
  334.                                         ballX=conx(x);
  335.                                         ballY=cony(y);
  336.                                         DrawBall(hdcWindow);
  337.                                 }
  338.                                 if (curva==4)  //(Iperbole)
  339.                                 {
  340.                                         a=atof(numa);
  341.                                         b=atof(numb);
  342.                                         y=sqrt(b*b*(x*x-a*a)/(a*a));
  343.                                         //Converte i numeri in coordinate in pixel:
  344.                                         ballX=conx(x);
  345.                                         ballY=cony(y);
  346.                                         DrawBall(hdcWindow);
  347.                                         y=-sqrt(b*b*(x*x-a*a)/(a*a));
  348.                                         //Converte i numeri in coordinate in pixel:
  349.                                         ballX=conx(x);
  350.                                         ballY=cony(y);
  351.                                         DrawBall(hdcWindow);
  352.                                 }
  353.                                 if (curva==5)  //(Circonferenza)
  354.                                 {
  355.                                         a=atof(numa);
  356.                                         b=atof(numb);
  357.                                         c=atof(numc);
  358.                                         y=b+sqrt((c*c)-((x-a)*(x-a)));
  359.                                         //Converte i numeri in coordinate in pixel:
  360.                                         ballX=conx(x);
  361.                                         ballY=cony(y);
  362.                                         DrawBall(hdcWindow);
  363.                                         y=-b-sqrt((c*c)-((x-a)*(x-a)))+2*b;
  364.                                         //Converte i numeri in coordinate in pixel:
  365.                                         ballX=conx(x);
  366.                                         ballY=cony(y);
  367.                                         DrawBall(hdcWindow);
  368.                                 }
  369.                                 if (curva==6)  //(Parabola con asse parallelo all'asse delle x)
  370.                                 {
  371.                                         a=atof(numa);
  372.                                         b=atof(numb);
  373.                                         c=atof(numc);
  374.                                         y=(-b+sqrt(b*b-4*a*c+4*a*x))/2;
  375.                                         //Converte i numeri in coordinate in pixel:
  376.                                         ballX=conx(x);
  377.                                         ballY=cony(y);
  378.                                         DrawBall(hdcWindow);
  379.                                         y=-(-b+sqrt(b*b-4*a*c+4*a*x)+2*b)/2;
  380.                                         //Converte i numeri in coordinate in pixel:
  381.                                         ballX=conx(x);
  382.                                         ballY=cony(y);
  383.                                         DrawBall(hdcWindow);
  384.                                 }
  385.             }  
  386.                     }
  387.                     //Disegno Funzioni:***************************************************************************************************************
  388.                         if (funpress>0)                   //Se è stato cliccato il pulsante disegna nella funciton windows:
  389.                         {
  390.                                 funpress=0;                      //riazzero il contatore che indica che è stato premuto il tasto disegna.
  391.                                 /*Apro il file, lo pulisco e scrivo di che funzione si tratta:*/
  392.                                 fstream f;
  393.                                 system ("del Tab.txt");
  394.                                 f.open("Tab.txt",ios::out|ios::app);
  395.                                 f <<"Funzione:"<<endl;
  396.                                 f <<"y="<<funzione<<endl;
  397.                                 f <<"------------------------------------"<<endl;
  398.                                 f <<"X                     Y"<<endl;
  399.                                 /***********************************/
  400.                                 for (i=-10;i<=10;i=i+inc)
  401.                                 {
  402.                                         x=i;
  403.  
  404.                                         SendMessage(prog2, PBM_SETPOS, WPARAM(((i+10)*100/20)+1), 0);   //Setto la progressBar
  405.  
  406.                                         stack <float> numbers;    
  407.                                         string longNumber = "";
  408.                                         float  result=0,prev=0,postv=0;
  409.                                         int chkop=0;
  410.                                         for (unsigned int h = 0; h < rpn.size(); h++)
  411.                                         {
  412.                                                 /*              Il carattere letto e' un numero. Questo numero viene memorizzato
  413.                                                 * nella stringa di appoggio.
  414.                                                 *               Se il prossimo carattere e' un numero,vuol dire che nella
  415.                                                 * stringa c'e un numero lungo perche' nella funzione di conversione
  416.                                                 * dopo ogni numero inserito nella stringa di output veniva messo anche
  417.                                                 * il simbolo di spazio. La prossima cifra del numero sara' aggiunta
  418.                                                 * alla fine della stringa di appoggio all'aumentare dell'indice.
  419.                                                 *               Se il prossimo carattere non e' un numero, la stringa d'appoggio
  420.                                                 * viene convertita in un numero vero e memorizzata nello stack. */
  421.                                                 if(chkchar(rpn[h])==1)
  422.                                                 {
  423.                                                         if (isdigit(rpn[h]))
  424.                                                         {
  425.                                                                 longNumber += rpn[h];
  426.                                                         }
  427.                                                                
  428.                                                         if ((rpn[h]=='x')||(rpn[h]=='X'))                         //sostitusco alla x nell'espressione il valore effettivo della x
  429.                                                         {
  430.                                                                 numbers.push(x);
  431.                                                         }
  432.  
  433.                                                         if (rpn[h]=='e')                         //sostituisco alla e nell'espressione il valore della costante
  434.                                                         {
  435.                                                                
  436.                                                                 numbers.push(2.71828);
  437.                                                         }
  438.  
  439.                                                         if (rpn[h]=='p')                                                 //sostituisco alla ? nell'espressione il valore della costante
  440.                                                         {
  441.                                                                
  442.                                                                 numbers.push(3.14159);
  443.                                                         }
  444.                                                         //Se il carattere successivo non è una cifra e è diverso dalla virgola:
  445.                                                         if((!isdigit(rpn[h + 1]))&& (rpn[h+1]!='.')&&(rpn[h]!='x')&&(rpn[h]!='X')&&(rpn[h]!='e')&&(rpn[h]!='p'))  
  446.                                                         {
  447.                                                                 numbers.push(atof(longNumber.c_str()));
  448.                                                                 longNumber = "";
  449.                                                         }
  450.                                                         if (rpn[h+1]=='.')    //Se il carattere successivo è la virgola:
  451.                                                         {
  452.                                                                 numbers.push(atof(longNumber.c_str()));    //legge la parte precedente a questa (la parte intera )
  453.                                                                 longNumber = "";
  454.                                                                 prev = numbers.top();
  455.                                                                 numbers.pop();
  456.                                                                 int count=2;
  457.                                                                 while (isdigit(rpn[count+h]))      //Legge la parte successiva e la memorizza come numero
  458.                                                                 {
  459.                                                                         longNumber += rpn[h+count];
  460.                                                                         count++;
  461.                                                                 }
  462.                                                                 h=h+count;
  463.                                                                 postv=(atof(longNumber.c_str()));
  464.                                                                 longNumber="";
  465.                                                                 /*somma la parte precedente a quella successiva
  466.                                                                  fratto 10^il numero di cifre che ha es:
  467.                                                                  2.985     prev=2   postv=985
  468.                                                                  985 ha tre cifre quindi 985/10^3=0.985
  469.                                                                  li sommo e ottengo 2.985*/
  470.                                                                 numbers.push(prev+(postv/pow(10,numcif(postv))));      
  471.                                                                 postv=0;prev=0;
  472.                                                         }
  473.                                                 }
  474.                                                
  475.                                                 if (chkchar(rpn[h])==2)    //Il carattere è un operatore:
  476.                                                 {      
  477.                                                         chkop++;                //Controlla se vi è un operatore            
  478.                                                         result = numbers.top();
  479.                                                         numbers.pop();
  480.                                                         if (numbers.empty())       //se c'è un operatore all'inizio, è come se ci fosse lo 0 (es.-6=0-6)
  481.                                                         {                                                       //pertanto aggiungo lo 0
  482.                                                                 numbers.push(0.0);
  483.                                                         }
  484.                                                         /*****OPERATORS****************************************/
  485.                                                                 switch(rpn[h])
  486.                                                                 {
  487.                                                                         case '+':
  488.                                                                                 result = numbers.top() + result ;
  489.                                                                          break;
  490.                                                                         case '-':
  491.                                                                                 result = numbers.top() - result ;
  492.                                                                          break;
  493.                                                                         case '*':
  494.                                                                                  result = numbers.top() * result ;
  495.                                                                         break;
  496.                                                                         case '/':
  497.                                                                                 result = numbers.top() / result ;
  498.                                                                          break;
  499.                                                                          case '^':
  500.                                                                                 result = pow(numbers.top() , result) ;
  501.                                                                          break;
  502.                                                                          case '%':                                                                                              //Operatore modulo
  503.                                                                                 result =int(numbers.top()) % int(result) ;
  504.                                                                          break;
  505.                                                                 }
  506.                                                                 numbers.pop();
  507.                                                                 numbers.push(result);
  508.                                                 }
  509.                                                 if (chkfun(rpn[h])==1)                       //Se c'è un carattere che corrisponde a una funzione:
  510.                                                 {
  511.                                                         /*La funzione 'Fun', dato un carattere
  512.                                                         *corrispondente a una funzione e un valore
  513.                                                         *float, ne calcola la funzione corrispondente.*/
  514.                                                         result=Fun(rpn[h],numbers.top());        //Fun è dichiarata in 'funzioni.h'
  515.                                                         numbers.pop();
  516.                                                         numbers.push(result);
  517.                                                 }
  518.                                         }
  519.                                         if (chkop==0)    //Se nell'espressione non vi è alcun  operatore, allora vi deve essere un solo numero, perciò lo si associa a result.
  520.                                         {                                       //infatti chkop si incrementa se il carattere è un operatore(vedi sopra)
  521.                                                 result= numbers.top();
  522.                                         }
  523.                                         /*Rappresento il punto in coordinate (x;result)*/
  524.                                         ballX=conx(x);
  525.                                         ballY=cony(result);
  526.                                         DrawBall(hdcWindow);
  527.                                         /*Creo La tabella caratteri*/
  528.                                         f <<x<<"                    "<<result<<endl;
  529.                                 }
  530.                                 f.close();
  531.                         }
  532.                         ReleaseDC(hwnd, hdcWindow);
  533.                  }
  534.                   break;
  535.       case WM_COMMAND: /***************************************MENU*****************************************************/
  536.                    if (LOWORD(wParam)==MENU_FILE_EXIT)
  537.                    {
  538.                            DestroyWindow(hwnd);    //Chiudo la finestra
  539.                    }
  540.            if (LOWORD(wParam)==MENU_FILE_CURV)
  541.                    {
  542.                            //Crea e visualizza la finestra delle curve
  543.                            MSG messages2;
  544.                HWND hwnd2 = CreateWindowEx (0,name,"Curve:",WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE,400,400,400,300,hwnd, NULL, g_hInst,NULL);
  545.                ShowWindow (hwnd2, 1);
  546.                while (GetMessage (&messages2, NULL, 0, 0))
  547.                            {
  548.                        TranslateMessage(&messages2);
  549.                        DispatchMessage(&messages2);
  550.                            }
  551.                    }
  552.                    if (LOWORD(wParam)==MENU_FILE_ABOU)
  553.                    {
  554.                            MessageBox(hwnd,"Paint XY - Versione 1.2","By Dany",MB_OK|MB_ICONINFORMATION);
  555.                    }
  556.                    if (LOWORD(wParam)==MENU_FILE_CLEA)
  557.                    {
  558.                            /*Se nel menu clicchi su 'pulisci' allora la finestra 'scomparirà' (ncmdshow=0)
  559.                            e ricomparirà (ncmdshow=1) ma 'bo' e 'cachefun' saranno uguali a 0 e perciò
  560.                            il prog non avrà il "permesso" di ridisegnare le curve/funzioni*/
  561.                            curva=0;    
  562.                            bo=0;
  563.                            cachenum=0;
  564.                            ShowWindow(hwnd,0);
  565.                            ShowWindow(hwnd,1);
  566.                            /*Azzerando le variabili contatrici degli array, dopo aver pulito la finestra,
  567.                            se ridisegnano nuove curve, verranno sovrascritte a quelle vecchie che non
  568.                            verranno mai più ridisegnate :'(*/
  569.                            l=0;l2=0;l3=0;l4=0;l5=0;l6=0;  //Azzero le variabili contatrici degli array
  570.                            /*Azzero l'array delle string contenenti gli rpn delle varie funzioni disegnate
  571.                            così da non ridisegnarle*/
  572.                            for (int N=0;N<=20;N++)
  573.                                    cache[N]="";
  574.                    }
  575.                    if (LOWORD(wParam)==MENU_FILE_SETT)
  576.                    {
  577.                            //Crea e visualizza la finestra
  578.                            MSG messages4;
  579.                HWND hwnd4 = CreateWindowEx (0,name3,"Impostazioni:",WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE,400,400,390,200,hwnd, NULL, g_hInst,NULL);
  580.                            ShowWindow (hwnd4, 1);
  581.                            while (GetMessage (&messages4, NULL, 0, 0))
  582.                            {
  583.                        TranslateMessage(&messages4);
  584.                        DispatchMessage(&messages4);
  585.                            }
  586.                            preprec=prec;    //Il cursore della trackbar assume l'ultima posizione.
  587.                    }
  588.                    if (LOWORD(wParam)==MENU_FILE_FUNZ)
  589.                    {
  590.                            //Crea e visualizza la finestra
  591.                            MSG messages5;
  592.                HWND hwnd5 = CreateWindowEx (0,name2,"Funzioni:",WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE,400,400,400,250,hwnd, NULL, g_hInst,NULL);
  593.                            ShowWindow (hwnd5, 1);
  594.                            while (GetMessage (&messages5, NULL, 0, 0))
  595.                            {
  596.                        TranslateMessage(&messages5);
  597.                        DispatchMessage(&messages5);
  598.                            }
  599.                    }
  600.            break;
  601.       case WM_PAINT:
  602.          if(hbmBall && hbmMask)
  603.          {
  604.             PAINTSTRUCT ps;
  605.             HDC hdcWindow;
  606.             hdcWindow = BeginPaint(hwnd, &ps);
  607.             DrawGriglia(hdcWindow);
  608.                         /*******RIDISEGNA LE FUNZIONI SE LA FINESTRA VIENE RIDOTTA/COPERTA*****/
  609.                         if (bo>0) //Se il prog NON è stato appena pulito (o non è stato appena aperto)
  610.                         /*In pratica col ciclo passo tutte le 6 curve e per ognuna esamino gli array che contengono
  611.                         i parametri da me inseriti precedentemente, così per ridisegnarle basta ricaricare nei coefficient a,b,c
  612.                         i valori negli array ca,da,ea ecc...*/
  613.                         for (curva=1;curva<=6;curva++)    //Ciclo con tutti i tipi di curva
  614.                         for (i=-10;i<=10;i=i+inc)
  615.             {
  616.                                 x=i;
  617.                                 if (curva==1)  //(retta)
  618.                                 {
  619.                                         if (l>0)                //Se la curva non è mai stata disegnata, salta il ciclo
  620.                                         for  (k=0;k<=l-1;k++)    //Verifica tutte le posizioni dell'array e le usa per ridisegnare la funzione
  621.                                         {
  622.                                         a=ca[k];
  623.                                         b=cb[k];
  624.                                         c=cc[k];
  625.                                         if (b!=0)
  626.                                         y=((-c-(a*x))/b);
  627.                                         else            //RETTA PARALLELA ALL'ASSE DELLE X
  628.                                         {
  629.                                                 x=c/a;
  630.                                                 y=i;
  631.                                         }
  632.                                         //Converte i numeri in coordinate in pixel:
  633.                                         ballX=conx(x);
  634.                                         ballY=cony(y);
  635.                                         DrawBall(hdcWindow);
  636.                                         }
  637.                                 }
  638.                                 if (curva==2)  //(parabola con asse parallelo all'asse delle y)
  639.                                 {
  640.                                         if (l2>0)      //Se la curva non è mai stata disegnata, salta il ciclo
  641.                                         for(k=0;k<=l2-1;k++)    //Verifica tutte le posizioni dell'array e le usa per ridisegnare la funzione
  642.                                         {
  643.                                         a=da[k];
  644.                                         b=db[k];
  645.                                         c=dc[k];
  646.                                         y=(a*x*x)+(b*x)+c;
  647.                                         //Converte i numeri in coordinate in pixel:
  648.                                         ballX=conx(x);
  649.                                         ballY=cony(y);
  650.                                         DrawBall(hdcWindow);
  651.                                         }
  652.                                 }
  653.                                 if (curva==3)  //(Ellisse)
  654.                                 {
  655.                                         if (l3>0)       //Se la curva non è mai stata disegnata, salta il ciclo
  656.                                         for(k=0;k<=l3-1;k++)       //Verifica tutte le posizioni dell'array e le usa per ridisegnare la funzione
  657.                                         {
  658.                                         a=ea[k];
  659.                                         b=eb[k];
  660.                                         y=sqrt(b*b*(a*a-x*x)/(a*a));
  661.                                         //Converte i numeri in coordinate in pixel:
  662.                                         ballX=conx(x);
  663.                                         ballY=cony(y);
  664.                                         DrawBall(hdcWindow);
  665.                                         y=-sqrt(b*b*(a*a-x*x)/(a*a));
  666.                                         //Converte i numeri in coordinate in pixel:
  667.                                         ballX=conx(x);
  668.                                         ballY=cony(y);
  669.                                         DrawBall(hdcWindow);
  670.                                         }
  671.                                 }
  672.                                 if (curva==4)  //(Iperbole)
  673.                                 {
  674.                                         if (l4>0)    //Se la curva non è mai stata disegnata, salta il ciclo
  675.                                         for(k=0;k<=l4-1;k++)      //Verifica tutte le posizioni dell'array e le usa per ridisegnare la funzione
  676.                                         {
  677.                                         a=fa[k];
  678.                                         b=fb[k];
  679.                                         y=sqrt(b*b*(x*x-a*a)/(a*a));
  680.                                         //Converte i numeri in coordinate in pixel:
  681.                                         ballX=conx(x);
  682.                                         ballY=cony(y);
  683.                                         DrawBall(hdcWindow);
  684.                                         y=-sqrt(b*b*(x*x-a*a)/(a*a));
  685.                                         //Converte i numeri in coordinate in pixel:
  686.                                         ballX=conx(x);
  687.                                         ballY=cony(y);
  688.                                         DrawBall(hdcWindow);
  689.                                         }
  690.                                 }
  691.                                 if (curva==5)  //(Circonferenza)
  692.                                 {
  693.                                         if (l5>0)     //Se la curva non è mai stata disegnata, salta il ciclo
  694.                                         for(k=0;k<=l5-1;k++)     //Verifica tutte le posizioni dell'array e le usa per ridisegnare la funzione
  695.                                         {
  696.                                         a=ga[k];
  697.                                         b=gb[k];
  698.                                         c=gc[k];
  699.                                         y=b+sqrt((c*c)-((x-a)*(x-a)));
  700.                                         //Converte i numeri in coordinate in pixel:
  701.                                         ballX=conx(x);
  702.                                         ballY=cony(y);
  703.                                         DrawBall(hdcWindow);
  704.                                         y=-b-sqrt((c*c)-((x-a)*(x-a)))+2*b;
  705.                                         //Converte i numeri in coordinate in pixel:
  706.                                         ballX=conx(x);
  707.                                         ballY=cony(y);
  708.                                         DrawBall(hdcWindow);
  709.                                         }
  710.                                 }
  711.                                 if (curva==6)  //(Parabola con asse parallelo all'asse delle x)
  712.                                 {
  713.                                         if (l6>0)    //Se la curva non è mai stata disegnata, salta il ciclo
  714.                                         for(k=0;k<=l6-1;k++)     //Verifica tutte le posizioni dell'array e le usa per ridisegnare la funzione
  715.                                         {
  716.                                         a=ha[k];
  717.                                         b=hb[k];
  718.                                         c=hc[k];
  719.                                         y=(-b+sqrt(b*b-4*a*c+4*a*x))/2;
  720.                                         //Converte i numeri in coordinate in pixel:
  721.                                         ballX=conx(x);
  722.                                         ballY=cony(y);
  723.                                         DrawBall(hdcWindow);
  724.                                         y=-(-b+sqrt(b*b-4*a*c+4*a*x)+2*b)/2;
  725.                                         //Converte i numeri in coordinate in pixel:
  726.                                         ballX=conx(x);
  727.                                         ballY=cony(y);
  728.                                         DrawBall(hdcWindow);
  729.                                         }
  730.                                 }
  731.             }
  732.                         /*RIDISEGNO FUNZIONI***********************************************************************/
  733.                         /*Sempre se il prog NON è stato ripulito o appena aperto,
  734.                         cioè se è stato solo coperto o ridotto a icona per farla semplice*/
  735.                         if (cachenum>0)
  736.                         //Ciclo che tramite 'lo' scorre l'array 'cache' ricaricando tutte le funzioni in rpn
  737.                         //disegnate prima che coprissi la finestra.
  738.                         for (lo=1;lo<=cachenum;lo++)
  739.                         for (i=-10;i<=10;i=i+inc)
  740.                                 {
  741.                                         x=i;
  742.                                         stack <float> numbers;    
  743.                                         string longNumber = "";
  744.                                         float  result=0,prev=0,postv=0;
  745.                                         for (unsigned int h = 0; h < cache[lo].size(); h++)
  746.                                         {
  747.                                                 /*              Il carattere letto e' un numero. Questo numero viene memorizzato
  748.                                                 * nella stringa di appoggio.
  749.                                                 *               Se il prossimo carattere e' un numero,vuol dire che nella
  750.                                                 * stringa c'e un numero lungo perche' nella funzione di conversione
  751.                                                 * dopo ogni numero inserito nella stringa di output veniva messo anche
  752.                                                 * il simbolo di spazio. La prossima cifra del numero sara' aggiunta
  753.                                                 * alla fine della stringa di appoggio all'aumentare dell'indice.
  754.                                                 *               Se il prossimo carattere non e' un numero, la stringa d'appoggio
  755.                                                 * viene convertita in un numero vero e memorizzata nello stack. */
  756.                                                 if(chkchar(cache[lo][h])==1)
  757.                                                 {
  758.                                                         if (isdigit(cache[lo][h]))
  759.                                                         {
  760.                                                                 longNumber += cache[lo][h];
  761.                                                         }
  762.                                                                
  763.                                                         if ((cache[lo][h]=='x')||(cache[lo][h]=='X'))                         //sostitusco alla x nell'espressione il valore effettivo della x
  764.                                                         {
  765.                                                                 numbers.push(x);
  766.                                                         }
  767.  
  768.                                                         if (cache[lo][h]=='e')                         //sostituisco alla e nell'espressione il valore della costante
  769.                                                         {
  770.                                                                 numbers.push(2.71828);
  771.                                                         }
  772.  
  773.                                                         if (cache[lo][h]=='p')                                           //sostituisco alla ? nell'espressione il valore della costante
  774.                                                         {
  775.                                                                 numbers.push(3.14159);
  776.                                                         }
  777.                                                         //Se il carattere successivo non è una cifra e è diverso dalla virgola:
  778.                                                         if((!isdigit(cache[lo][h + 1]))&& (cache[lo][h+1]!='.')&&(cache[lo][h]!='x')&&(cache[lo][h]!='X')&&(cache[lo][h]!='e')&&(cache[lo][h]!='p'))  
  779.                                                         {
  780.                                                                 numbers.push(atof(longNumber.c_str()));
  781.                                                                 longNumber = "";
  782.                                                         }
  783.                                                         if (cache[lo][h+1]=='.')    //Se il carattere successivo è la virgola:
  784.                                                         {
  785.                                                                 numbers.push(atof(longNumber.c_str()));    //legge la parte precedente a questa (la parte intera )
  786.                                                                 longNumber = "";
  787.                                                                 prev = numbers.top();
  788.                                                                 numbers.pop();
  789.                                                                 int count=2;
  790.                                                                 while (isdigit(cache[lo][count+h]))      //Legge la parte successiva e la memorizza come numero
  791.                                                                 {
  792.                                                                         longNumber += cache[lo][h+count];
  793.                                                                         count++;
  794.                                                                 }
  795.                                                                 h=h+count;
  796.                                                                 postv=(atof(longNumber.c_str()));
  797.                                                                 longNumber="";
  798.                                                                 /*somma la parte precedente a quella successiva
  799.                                                                  fratto 10^il numero di cifre che ha es:
  800.                                                                  2.985     prev=2   postv=985
  801.                                                                  985 ha tre cifre quindi 985/10^3=0.985
  802.                                                                  li sommo e ottengo 2.985*/
  803.                                                                 numbers.push(prev+(postv/pow(10,numcif(postv))));      
  804.                                                                 postv=0;prev=0;
  805.                                                         }
  806.                                                 }
  807.                                                 result=numbers.top();
  808.                                                 if (chkchar(cache[lo][h])==2)
  809.                                                 {      
  810.                                                         result = numbers.top();
  811.                                                         numbers.pop();
  812.                                                         if (numbers.empty())       //se c'è un operatore all'inizio, è come se ci fosse lo 0 (es.-6=0-6)
  813.                                                         {
  814.                                                                 numbers.push(0.0);
  815.                                                         }
  816.                                                         /*****OPERATORS****************************************/
  817.                                                                 switch(cache[lo][h])
  818.                                                                 {
  819.                                                                         case '+':
  820.                                                                                 result = numbers.top() + result ;
  821.                                                                          break;
  822.                                                                         case '-':
  823.                                                                                 result = numbers.top() - result ;
  824.                                                                          break;
  825.                                                                         case '*':
  826.                                                                                  result = numbers.top() * result ;
  827.                                                                         break;
  828.                                                                         case '/':
  829.                                                                                 result = numbers.top() / result ;
  830.                                                                          break;
  831.                                                                          case '^':
  832.                                                                                 result = pow(numbers.top() , result) ;
  833.                                                                          break;
  834.                                                                          case '%':
  835.                                                                                 result =int(numbers.top()) % int(result) ;
  836.                                                                          break;
  837.                                                                 }
  838.                                                                 numbers.pop();
  839.                                                                 numbers.push(result);
  840.                                                 }
  841.                                                 if (chkfun(cache[lo][h])==1)                       //Se c'è una funzione:
  842.                                                 {
  843.                                                         result=Fun(cache[lo][h],numbers.top());
  844.                                                         numbers.pop();
  845.                                                         numbers.push(result);
  846.                                                 }
  847.                                         }
  848.                                         /*Rappresento il punto in coordinate (x;result)*/
  849.                                         ballX=conx(x);
  850.                                         ballY=cony(result);
  851.                                         DrawBall(hdcWindow);
  852.                                 }
  853.             EndPaint(hwnd, &ps);
  854.          }
  855.                  break;
  856.                  case WM_MOUSEMOVE:
  857.                          /*Coordinate mouse nella finestra
  858.                          *In pratica Grazie a GET_X_LPARAM (lParam); e a GET_Y_LPARAM (lParam);
  859.                          *Ottengo le coordinate in pixel dentro la finestra, per poi convertirle
  860.                          *In coordinate reali.*/
  861.                          cox = GET_X_LPARAM (lParam);
  862.                          coy = GET_Y_LPARAM (lParam);
  863.  
  864.                          cox=(cox-500)/50;
  865.                          coy=(500-coy)/50;
  866.  
  867.                          sprintf(coox, "%6.2f", cox);   //Converto da float a *char
  868.                          sprintf(cooy, "%6.2f", coy);   //Converto da float a *char
  869.  
  870.                         SetWindowText(lex,coox);   //Imposto nell'edit le coordinate x
  871.                         SetWindowText(ley,cooy);   //Imposto nell'edit le coordinate y
  872.                          break;
  873.       case WM_CLOSE:
  874.                   if(MessageBox(hwnd,"Vuoi davvero uscire?","Messaggio",MB_YESNO|MB_ICONQUESTION)==IDYES)
  875.          DestroyWindow(hwnd);
  876.          break;
  877.       case WM_DESTROY:
  878.          KillTimer(hwnd, idTimer1);
  879.          DeleteObject(hbmBall);
  880.          DeleteObject(hbmMask);
  881.          PostQuitMessage(0);
  882.          break;
  883.       default:
  884.          return DefWindowProc(hwnd, Message, wParam, lParam);
  885.    }
  886.    return 0;
  887. }
  888. //WndProc della finestra per rappresentare le curve
  889. //HBIMAP del pulsante di disegno
  890. HBITMAP bmp=(HBITMAP)LoadImage(0,"draw.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
  891. //HWND DEL PULSANTE DI DISEGNO
  892. HWND paint;
  893. //Variabili HWND:
  894. HWND radpar,radipe,radell,radret,radcir,radparx;  
  895. HWND edita,editb,editc,sintax;
  896. //Variabili controllo radiobutton in finestra di disegno curve
  897. int selret=0,selpar=0,selipe=0,selell=0,selcir=0,selparx=0;
  898. //Tooltipe
  899. TOOLINFO ti;
  900. HWND hwtoll;
  901.  
  902. LRESULT CALLBACK WindowProcedure2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  903. {              
  904.         InitCommonControls ();      //Applicazione visual style
  905.         switch (message)                  
  906.         {
  907.                         case WM_PAINT:
  908.                                 PAINTSTRUCT ps;
  909.                                 HDC hdcWindow;
  910.                                 hdcWindow = BeginPaint(hwnd, &ps);
  911.                                 /****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
  912.                                 hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  913.                 CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
  914.                             SelectObject (hdcWindow, hfont);
  915.                             SetRect (& rect, 100,100,700,200);
  916.                 SetTextColor (hdcWindow, RGB (0,0,0));
  917.  
  918.                                 TextOut(hdcWindow,0,0,"Selezionare il tipo di curva ed inserire i parametri.",55);
  919.                                 TextOut(hdcWindow,5,190,"Coefficiente A:",15);
  920.                                 TextOut(hdcWindow,5,215,"Coefficiente B:",15);
  921.                                 TextOut(hdcWindow,5,240,"Coefficiente C:",15);
  922.                                 TextOut(hdcWindow,5,150,"L'equazione è del tipo:",23);
  923.                                 EndPaint(hwnd,&ps);
  924.                                 break;
  925.             case WM_CREATE:
  926.                                 //ProgressBar
  927.                                 prog=CreateWindowEx(NULL, PROGRESS_CLASS, NULL, WS_CHILD|WS_VISIBLE, 215,200, 150, 30, hwnd, NULL, NULL, 0);
  928.                                 //Crea radio-button per decidere il tipo di curva:
  929.                                 radret=CreateWindow("Button","Retta",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0,20,55,20,hwnd,(HMENU) 1,NULL,NULL);
  930.                                 radpar=CreateWindow("Button","Parabola (y)",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0,45,100,20,hwnd,(HMENU) 2,NULL,NULL);
  931.                                 radipe=CreateWindow("Button","Iperbole",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0,70,80,20,hwnd,(HMENU) 3,NULL,NULL);
  932.                                 radell=CreateWindow("Button","Ellisse",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0,95,70,20,hwnd,(HMENU) 4,NULL,NULL);
  933.                                 radcir=CreateWindow("Button","Circonferenza",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0,120,100,20,hwnd,(HMENU) 5,NULL,NULL);
  934.                                 radparx=CreateWindow("Button","Parabola (x)",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,120,45,100,20,hwnd,(HMENU) 6,NULL,NULL);
  935.                                 //Crea EditBox per inserire i parametri
  936.                                 edita=CreateWindow("Edit","",WS_CHILD|WS_VISIBLE|WS_BORDER,150,190,50,20,hwnd,NULL,NULL,NULL);
  937.                                 editb=CreateWindow("Edit","",WS_CHILD|WS_VISIBLE|WS_BORDER,150,215,50,20,hwnd,NULL,NULL,NULL);
  938.                                 editc=CreateWindow("Edit","",WS_CHILD|WS_VISIBLE|WS_BORDER,150,240,50,20,hwnd,NULL,NULL,NULL);
  939.                                 //Crea EditBox per mostrare la sintassi di una cura selezionata
  940.                                 sintax=CreateWindow("Edit","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_READONLY,200,150,190,20,hwnd,NULL,NULL,NULL);
  941.                                 //Crea il pulsante che permette di disegnare la curva selezionata.
  942.                                 paint=CreateWindow("Button","",WS_VISIBLE|WS_CHILD|BS_BITMAP|WS_BORDER,295,35,83,83,hwnd,(HMENU) 7, NULL,NULL);
  943.                                 SendMessage(paint,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)bmp);
  944.                                 /****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
  945.                                 GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  946.                                 hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  947.                 CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
  948.                                 SendMessage (edita, WM_SETFONT, (WPARAM) hfont, true);
  949.                                 SendMessage (editb, WM_SETFONT, (WPARAM) hfont, true);
  950.                                 SendMessage (editc, WM_SETFONT, (WPARAM) hfont, true);  
  951.                                 SendMessage (radret, WM_SETFONT, (WPARAM) hfont, true);
  952.                                 SendMessage (radpar, WM_SETFONT, (WPARAM) hfont, true);
  953.                                 SendMessage (radipe, WM_SETFONT, (WPARAM) hfont, true);  
  954.                                 SendMessage (radell, WM_SETFONT, (WPARAM) hfont, true);
  955.                                 SendMessage (radcir, WM_SETFONT, (WPARAM) hfont, true);  
  956.                                 SendMessage (radparx, WM_SETFONT, (WPARAM) hfont, true);
  957.                                 SendMessage (sintax, WM_SETFONT, (WPARAM) hfont, true);
  958.                                 /*TOOLTIP*/
  959.                                 hwtoll=CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,0,0,0,0,paint, NULL, NULL,NULL);
  960.                                 SetWindowPos (hwtoll, HWND_TOPMOST, 0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  961.                                 GetClientRect (paint, &rect);
  962.                                 ////////////////////////////////// FORMATTAZIONE TOOLTIP
  963.                                 ti.cbSize = sizeof(TOOLINFO);
  964.                                 ti.uFlags = TTF_SUBCLASS;
  965.                                 ti.hwnd = paint;
  966.                                 ti.hinst = NULL;
  967.                                 ti.uId = 0;
  968.                                 ti.lpszText = "Disegna!";
  969.                                 ti.rect.left = rect.left;    
  970.                                 ti.rect.top = rect.top;
  971.                                 ti.rect.right = rect.right;
  972.                                 ti.rect.bottom = rect.bottom;
  973.                                 //////////////////////////////////
  974.                                 SendMessage(hwtoll, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  975.                 break;
  976.                         case WM_COMMAND:
  977.                                 if (LOWORD(wParam)==1)
  978.                                 {
  979.                                         SetWindowText(sintax,"Ax+By+C=0");   //Mostro la sintassi della curva
  980.                                         Edit_Enable(editc,TRUE);    //Abilita l'edit relativo al coefficiente C poichè contenuto nella sintassi dell'equazione
  981.                                 }
  982.                                 if (LOWORD(wParam)==2)
  983.                                 {
  984.                                         SetWindowText(sintax,"Ax²+Bx+C=y");  //Mostro la sintassi della curva
  985.                                         Edit_Enable(editc,TRUE);
  986.                                 }
  987.                                 if (LOWORD(wParam)==3)
  988.                                 {
  989.                                         SetWindowText(sintax,"(x²/A²)-(y²/B²)=1");  //Mostro la sintassi della curva
  990.                                         Edit_Enable(editc,FALSE); //DisAbilita l'edit relativo al coefficiente C poichè Non contenuto nella sintassi dell'equazione
  991.                                 }
  992.                                 if (LOWORD(wParam)==4)
  993.                                 {
  994.                                         SetWindowText(sintax,"(x²/A²)+(y²/B²)=1");  //Mostro la sintassi della curva
  995.                                         Edit_Enable(editc,FALSE);
  996.                                 }
  997.                                 if (LOWORD(wParam)==5)
  998.                                 {
  999.                                         SetWindowText(sintax,"(x-A)²+(y-B)²=C²");  //Mostro la sintassi della curva
  1000.                                         Edit_Enable(editc,TRUE);
  1001.                                 }
  1002.                                 if (LOWORD(wParam)==6)
  1003.                                 {
  1004.                                         SetWindowText(sintax,"Ay²+By+C=x");  //Mostro la sintassi della curva
  1005.                                         Edit_Enable(editc,TRUE);
  1006.                                 }
  1007.                                 if (LOWORD(wParam)==7)
  1008.                                 {
  1009.                                         bo++;  //Incremento 'bo' il che indica che se la finestra viene coperta oridotta a icona
  1010.                                                //le curve verranno disegnate
  1011.                                         //Controllo stato radiobutton
  1012.                                         selret=SendMessage(radret,BM_GETCHECK,0,0);
  1013.                                         selpar=SendMessage(radpar,BM_GETCHECK,0,0);
  1014.                                         selell=SendMessage(radell,BM_GETCHECK,0,0);
  1015.                                         selipe=SendMessage(radipe,BM_GETCHECK,0,0);
  1016.                                         selcir=SendMessage(radcir,BM_GETCHECK,0,0);
  1017.                                         selparx=SendMessage(radparx,BM_GETCHECK,0,0);
  1018.                                         //Nel caso sia selezionato il radiobutton....
  1019.                                         if (selret==BST_CHECKED)
  1020.                                         {
  1021.                                                 agg++; //Incremento la variabile che permette alla WM_TIMER in MainWindow di disegnare la curva
  1022.                                                 GetWindowText(edita,numa,5);  //Leggi il valore del paramtero a
  1023.                                                 GetWindowText(editb,numb,5);  //Leggi il valore del paramtero b
  1024.                                                 GetWindowText(editc,numc,5);  //Leggi il valore del paramtero c
  1025.                                                 curva=1;                      //Curva 1 Vuol dire retta
  1026.                                                 //Memorizza nell'array i vari valori dei coefficianti così da ridisegnarli
  1027.                                                 ca[l]=atof(numa);
  1028.                                                 cb[l]=atof(numb);
  1029.                                                 cc[l]=atof(numc);
  1030.                                                 l++;
  1031.                                         }
  1032.                                         if (selpar==BST_CHECKED)
  1033.                                         {
  1034.                                                 agg++; //Incremento la variabile che permette alla WM_TIMER in MainWindow di disegnare la curva
  1035.                                                 GetWindowText(edita,numa,5);  //Leggi il valore del paramtero a
  1036.                                                 GetWindowText(editb,numb,5);  //Leggi il valore del paramtero b
  1037.                                                 GetWindowText(editc,numc,5);  //Leggi il valore del paramtero c
  1038.                                                 curva=2;                      //Curva 2 Vuol dire parabola
  1039.                                                 //Memorizza nell'array i vari valori dei coefficianti così da ridisegnarli
  1040.                                                 da[l2]=atof(numa);
  1041.                                                 db[l2]=atof(numb);
  1042.                                                 dc[l2]=atof(numc);
  1043.                                                 l2++;
  1044.                                         }
  1045.                                         if (selell==BST_CHECKED)
  1046.                                         {
  1047.                                                 agg++; //Incremento la variabile che permette alla WM_TIMER in MainWindow di disegnare la curva
  1048.                                                 GetWindowText(edita,numa,5);  //Leggi il valore del paramtero a
  1049.                                                 GetWindowText(editb,numb,5);  //Leggi il valore del paramtero b
  1050.                                                 curva=3;                                                //Curva 3 Vuol dire ellisse
  1051.                                                 //Memorizza nell'array i vari valori dei coefficianti così da ridisegnarli
  1052.                                                 ea[l3]=atof(numa);
  1053.                                                 eb[l3]=atof(numb);
  1054.                                                 l3++;
  1055.                                         }
  1056.                                         if (selipe==BST_CHECKED)
  1057.                                         {
  1058.                                                 agg++; //Incremento la variabile che permette alla WM_TIMER in MainWindow di disegnare la curva
  1059.                                                 GetWindowText(edita,numa,5);  //Leggi il valore del paramtero a
  1060.                                                 GetWindowText(editb,numb,5);  //Leggi il valore del paramtero b
  1061.                                                 curva=4;                     //Curva 4 Vuol dire iperbole
  1062.                                                 //Memorizza nell'array i vari valori dei coefficianti così da ridisegnarli
  1063.                                                 fa[l4]=atof(numa);
  1064.                                                 fb[l4]=atof(numb);
  1065.                                                 l4++;
  1066.                                         }
  1067.                                         if (selcir==BST_CHECKED)
  1068.                                         {
  1069.                                                 agg++; //Incremento la variabile che permette alla WM_TIMER in MainWindow di disegnare la curva
  1070.                                                 GetWindowText(edita,numa,5);  //Leggi il valore del paramtero a
  1071.                                                 GetWindowText(editb,numb,5);  //Leggi il valore del paramtero b
  1072.                                                 GetWindowText(editc,numc,5);  //Leggi il valore del paramtero c
  1073.                                                 curva=5;                      //Curva 5 Vuol dire circonferenza
  1074.                                                 //Memorizza nell'array i vari valori dei coefficianti così da ridisegnarli
  1075.                                                 ga[l5]=atof(numa);
  1076.                                                 gb[l5]=atof(numb);
  1077.                                                 gc[l5]=atof(numc);
  1078.                                                 l5++;
  1079.                                         }
  1080.                                         if (selparx==BST_CHECKED)
  1081.                                         {
  1082.                                                 agg++; //Incremento la variabile che permette alla WM_TIMER in MainWindow di disegnare la curva
  1083.                                                 GetWindowText(edita,numa,5);  //Leggi il valore del paramtero a
  1084.                                                 GetWindowText(editb,numb,5);  //Leggi il valore del paramtero b
  1085.                                                 GetWindowText(editc,numc,5);  //Leggi il valore del paramtero c
  1086.                                                 curva=6;                      //Curva 6 Vuol dire parabola con asse parallello all'asse x
  1087.                                                 //Memorizza nell'array i vari valori dei coefficianti così da ridisegnarli
  1088.                                                 ha[l6]=atof(numa);
  1089.                                                 hb[l6]=atof(numb);
  1090.                                                 hc[l6]=atof(numc);
  1091.                                                 l6++;
  1092.                                         }
  1093.                                         if((selret!=BST_CHECKED) &&  (selpar!=BST_CHECKED) && (selipe!=BST_CHECKED) && (selell!=BST_CHECKED) && (selcir!=BST_CHECKED) && (selparx!=BST_CHECKED)) //Se non è selezionata alcuna curva:
  1094.                                         {
  1095.                                                 MessageBox(hwnd,"Selezionare una curva","Avviso!",MB_OK);
  1096.                                         }
  1097.                                 }
  1098.                                 break;
  1099.                         case WM_KEYDOWN:
  1100.                                 if (LOWORD(wParam)==VK_RETURN)     //Se si preme invio: è come se si clicca su :paint.
  1101.                                 {
  1102.                                         SendMessage(paint,BM_CLICK,NULL,NULL);   //simulare pressione tasto...
  1103.                                 }
  1104.                                 break;
  1105.             case WM_DESTROY:
  1106.                 PostQuitMessage (0);    
  1107.                 break;
  1108.             default:                  
  1109.                 return DefWindowProc (hwnd, message, wParam, lParam);
  1110.         }
  1111.         return 0;
  1112. }
  1113. //Function Window
  1114. //Variabile del ciclo
  1115. int h;
  1116. //Variabili HWND
  1117. HWND edfun,tabb,drf,gui;
  1118. //Variabile bitmap
  1119. HBITMAP bmp2=(HBITMAP)LoadImage(0,"draw.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
  1120. HBITMAP bmp3=(HBITMAP)LoadImage(0,"tab.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
  1121. //Window Procedure della Function Window
  1122. LRESULT CALLBACK WindowProcedure3 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  1123. {      
  1124.         InitCommonControls ();     //Applicazione visual style
  1125.         switch(message)
  1126.         {
  1127.                 case WM_CREATE:
  1128.                         /****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
  1129.                         GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  1130.                         hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  1131.             CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
  1132.                         //Progress Bar
  1133.                         prog2=CreateWindowEx(NULL, PROGRESS_CLASS, NULL, WS_CHILD|WS_VISIBLE, 5,180, 380, 30, hwnd, NULL, NULL, 0);
  1134.                         //Edit
  1135.                         edfun=CreateWindow("edit","<Scrivere quì la funzione>",WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,40,30,350,20,hwnd,NULL,NULL,NULL);
  1136.                         //Pulsanti
  1137.                         tabb=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_BITMAP,10,70,80,80,hwnd,(HMENU) 1,NULL,NULL);
  1138.                         drf=CreateWindow("button","",WS_VISIBLE|WS_CHILD|BS_BITMAP,105,70,80,80,hwnd,(HMENU) 2,NULL,NULL);
  1139.                         gui=CreateWindow("button","Guida",WS_VISIBLE|WS_CHILD|BS_BITMAP,230,70,110,80,hwnd,(HMENU) 3,NULL,NULL);
  1140.                         //Applico le bitmap
  1141.                         SendMessage(drf,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)bmp2);
  1142.                         SendMessage(tabb,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)bmp3);
  1143.                         //Setto i caratteri
  1144.                         SendMessage (edfun, WM_SETFONT, (WPARAM) hfont, true);    
  1145.                         SendMessage (gui, WM_SETFONT, (WPARAM) hfont, true);  
  1146.                         /*TOOLTIP*/
  1147.                                 hwtoll=CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,0,0,0,0,drf, NULL, NULL,NULL);
  1148.                                 SetWindowPos (hwtoll, HWND_TOPMOST, 0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  1149.                                 GetClientRect (drf, &rect);
  1150.                                 ////////////////////////////////// FORMATTAZIONE TOOLTIP
  1151.                                 ti.cbSize = sizeof(TOOLINFO);
  1152.                                 ti.uFlags = TTF_SUBCLASS;
  1153.                                 ti.hwnd = drf;
  1154.                                 ti.hinst = NULL;
  1155.                                 ti.uId = 0;
  1156.                                 ti.lpszText = "Disegna!";
  1157.                                 ti.rect.left = rect.left;    
  1158.                                 ti.rect.top = rect.top;
  1159.                                 ti.rect.right = rect.right;
  1160.                                 ti.rect.bottom = rect.bottom;
  1161.                                 //////////////////////////////////
  1162.                                 SendMessage(hwtoll, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  1163.                                 /*TOOLTIP*/
  1164.                                 hwtoll=CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,0,0,0,0,tabb, NULL, NULL,NULL);
  1165.                                 SetWindowPos (hwtoll, HWND_TOPMOST, 0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  1166.                                 GetClientRect (tabb, &rect);
  1167.                                 ////////////////////////////////// FORMATTAZIONE TOOLTIP
  1168.                                 ti.cbSize = sizeof(TOOLINFO);
  1169.                                 ti.uFlags = TTF_SUBCLASS;
  1170.                                 ti.hwnd = tabb;
  1171.                                 ti.hinst = NULL;
  1172.                                 ti.uId = 0;
  1173.                                 ti.lpszText = "Visualizza la tabella dell'ultima funzione disegnata.";
  1174.                                 ti.rect.left = rect.left;    
  1175.                                 ti.rect.top = rect.top;
  1176.                                 ti.rect.right = rect.right;
  1177.                                 ti.rect.bottom = rect.bottom;
  1178.                                 //////////////////////////////////
  1179.                                 SendMessage(hwtoll, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  1180.                 break;
  1181.                 case WM_PAINT:
  1182.                         PAINTSTRUCT ps;
  1183.                         HDC hdcWindow;
  1184.                         hdcWindow = BeginPaint(hwnd, &ps);
  1185.                         /****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
  1186.                         hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  1187.             CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
  1188.                         SelectObject (hdcWindow, hfont);
  1189.                         SetRect (& rect, 100,100,700,200);
  1190.             SetTextColor (hdcWindow, RGB (0,0,0));
  1191.                         TextOut(hdcWindow,0,0,"Digitare la funzione:",21);
  1192.                         TextOut(hdcWindow,8,30,"y=",2);
  1193.                         EndPaint(hwnd,&ps);
  1194.                         break;
  1195.                 case WM_COMMAND:
  1196.                         if (LOWORD(wParam)==1)
  1197.                         {
  1198.                                 system ("start Tab.txt");
  1199.                         }
  1200.                         if (LOWORD(wParam)==2)
  1201.                         {
  1202.                                 funpress++;                //Indica che è stato premuto il tasto disegna...servirà poi nella mainwindow per disegnare la funzione
  1203.                                 cachenum++;                 //Variabile contatrice dell'array di memoria delle funzioni in rpn
  1204.                                 //azzero "rpn"
  1205.                                 rpn="";
  1206.                                 stack <char> operators;       //Dichiaro stack che conterrà gli operatori:            
  1207.                                 char in[100]="";               //Memorizza array contenente la funzione
  1208.                                 GetWindowText(edfun,in,100);           //Acquisisco stringa in notazione infissa
  1209.                                 /*****************************************************************************/
  1210.                                 //CONVERTO LA STRINGA IN NOTAZIONE INFISSA IN RPN
  1211.                                 for (h=0;h<=sizeof(in);h++)
  1212.                                 {
  1213.                                         /* Se il carattere e' un numero, questo viene aggiunto alla fine  
  1214.                                         * della stringa di output. Se il prossimo carattere non e' un
  1215.                                         * numero, viene aggiunto il simbolo di spazio per la migliore
  1216.                                         * leggibilita' dell'espressione in output */
  1217.                                         if (chkchar(in[h])==1)
  1218.                                         {
  1219.                                                 /*Nel caso la 'e' o la 'p' siano parte di una funzione (lne o prm), non  le scrivo.*/
  1220.                                                 if (((in[h]=='e')&&(in[h-1]=='n')&&(in[h-2]=='l'))||((in[h]=='p')&&(in[h-1]=='r')&&(in[h-2]=='m')))
  1221.                                                 {}
  1222.                                                 else
  1223.                                                         rpn+=in[h];
  1224.  
  1225.                                                 if ((!isdigit(in[h + 1]))&&(in[h+1]!='.')&&(in[h+1]!=','))
  1226.                                                 {
  1227.                                                         rpn+=" ";
  1228.                                                 }
  1229.                                                 if ((in[h+1]=='.')||(in[h+1]==','))
  1230.                                                 {
  1231.                                                         rpn+=".";
  1232.                                                 }
  1233.                                         }
  1234.                                        
  1235.                                         /* Il carattere letto e' un operatore.
  1236.                                         *               Se lo stack per gli operatori e' vuoto o il carattere
  1237.                                         * precedente era la parentesi aperta o l'operatore letto ha
  1238.                                         * una precedenza minore rispetto a quella dell'operatore inserito
  1239.                                         * prima, l'operatore letto viene inserito normalmente nello stack.
  1240.                                         *               Altrimenti se l'operatore letto ha una precedenza maggiore
  1241.                                         * rispetto a quella dell'operatore inserito prima, dallo stack
  1242.                                         * viene tolto l'operatore con la precedenza maggiore e viene messo
  1243.                                         * nella stringa di output. */
  1244.                                         if (chkchar(in[h])==2)
  1245.                                         {
  1246.                                                 bool usc=false;
  1247.                                                 while (usc==false)
  1248.                                                 {
  1249.                                                         if ((operators.empty())||(operators.top()=='(')||(precedence(in[h],operators.top())))
  1250.                                                         {
  1251.                                                                 if ((chkchar(in[h-1])==1)||(in[h-1]==')'))
  1252.                                                                         operators.push(in[h]);
  1253.                                                                 usc=true;
  1254.                                                         }
  1255.                                                         else if (!precedence(in[h], operators.top()))
  1256.                                                         {
  1257.  
  1258.                                                                 rpn+=operators.top();
  1259.                                                                 rpn +=" ";
  1260.                                                                 operators.pop();
  1261.                                                         }
  1262.                                                 }
  1263.                                         }
  1264.                                         /* Se il carattere è la s, il successivo è la i e quello ancora è la n, allora c'è la funzione sin:  ecc.....
  1265.                                         La funzione 'charfun': data una serie di tre caratteri, se corrispondono a una funzione, copia il carattere corrispondente
  1266.                                         alla funzione nello stack*/
  1267.                                         char chf=charfun(in[h],in[h+1],in[h+2]);
  1268.                                         if (chf!=0)
  1269.                                                 operators.push(chf);
  1270.                                         /*              Se il carattere letto e' una parentesi aperta, questa viene
  1271.                                         * messa nello stack.
  1272.                                         *               Se e' una parentesi chiusa, vuol dire che tutti gli operatori
  1273.                                         * rimasti nello stack fino alla parentesi aperta vanno copiati nella
  1274.                                         * stringa di output. La parentesi aperta viene cancellata dallo stack
  1275.                                         * e dopo si contunua a leggere la stringa di input */
  1276.                                         if (in[h]=='(')
  1277.                                         {
  1278.                                                 operators.push(in[h]);
  1279.                                         }
  1280.                                         /*Se il carattere è il meno e precedentemente non vi è alcun valore, vuol dire che si intende
  1281.                                         *il negartivo di un valore es:-5, allora sostituisco al '-' ---->  '0-'   */
  1282.                                         if ((in[h]=='-')&&(chkchar(in[h-1])!=1))
  1283.                                         {
  1284.                                                         rpn+='0';
  1285.                                                         rpn+=' ';
  1286.                                                         operators.push('-');
  1287.                                         }
  1288.                                         if(in[h] == ')')
  1289.                                         {
  1290.                                                 while(operators.top() != '(')   //In pratica scorre nello stack verso sinistra copiando gli operatori incontrati.
  1291.                                                 {
  1292.                                                         rpn+=operators.top();
  1293.                                                         rpn+=" ";
  1294.                                                         operators.pop();
  1295.                                                 }
  1296.                                                 operators.pop();      //Cancella la parentesi aperta
  1297.                                         }
  1298.                                 }
  1299.                                 /* Tutti gli operatori rimasti nello stack vanno copiati nella
  1300.                                         stringa di output e poi cancellati dallo stack */
  1301.  
  1302.                                 while(!operators.empty())
  1303.                                 {
  1304.                                         rpn+=operators.top();
  1305.                                         rpn+=" ";
  1306.                                         operators.pop();
  1307.                 }
  1308. //////////////////Eventuale break point per verificare rpn.
  1309.                                 strcpy(funzione,in);     //Copio la funzione in 'funzione'
  1310.                                 cache[cachenum]=rpn;   //Copio nella posizione dell'array, la stringa rpn;
  1311.                         }
  1312.                         if (LOWORD(wParam)==3)
  1313.                         {
  1314.                                 system("start Funzioni.bmp");
  1315.                         }
  1316.                         break;
  1317.                 case WM_KEYDOWN:
  1318.                                 if (LOWORD(wParam)==VK_RETURN)     //Se si preme invio: è come se si clicca su :drf.
  1319.                                 {
  1320.                                         SendMessage(drf,BM_CLICK,NULL,NULL);   //simulare pressione tasto...
  1321.                                 }
  1322.                         break;
  1323.                 case WM_DESTROY:
  1324.                                 PostQuitMessage(0);
  1325.                                 break;
  1326.                 default:
  1327.                         return DefWindowProc(hwnd,message,wParam,lParam);
  1328.         }
  1329.         return 0;
  1330. }
  1331. //VARIABILI:
  1332. //HWND della finestra:
  1333. HWND hwndTrack,sinistra,destra,save,cancel;
  1334. //WndProc della finestra delle Impostazioni.
  1335. LRESULT CALLBACK WindowProcedure4 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  1336. {      
  1337.         InitCommonControls ();     //Applicazione visual style
  1338.         switch(message)
  1339.         {
  1340.                 case WM_CREATE:
  1341.                         //Salva-Annulla
  1342.                         save=CreateWindow("Button","Salva",WS_VISIBLE|WS_CHILD,10,140,80,30,hwnd,(HMENU) 5,NULL,NULL);
  1343.                         cancel=CreateWindow("Button","Annulla",WS_VISIBLE|WS_CHILD,300,140,80,30,hwnd,(HMENU) 6,NULL,NULL);
  1344.                         //TrackBar
  1345.                         hwndTrack = CreateWindowEx(0,TRACKBAR_CLASS,"Trackbar Control",WS_CHILD|WS_VISIBLE|TBS_AUTOTICKS|TBS_ENABLESELRANGE,
  1346.                         100,25,120,30,hwnd,(HMENU)3,NULL,NULL);
  1347.                         //Static
  1348.                         sinistra=CreateWindow("STATIC", "Approssimativo", WS_CHILD | WS_VISIBLE,0, 0, 100, 30,hwnd, (HMENU)1, NULL, NULL);
  1349.                         destra=CreateWindow("STATIC", "Preciso", WS_CHILD | WS_VISIBLE,0, 0, 80, 30,hwnd, (HMENU)2, NULL, NULL);
  1350.                         //Configuro la TrackBar
  1351.                         SendMessage(hwndTrack, TBM_SETRANGE,  TRUE,  MAKELONG(100, 1000)); //Gradazione
  1352.                         SendMessage(hwndTrack, TBM_SETPAGESIZE, 0,  20);  
  1353.                         SendMessage(hwndTrack, TBM_SETTICFREQ, 100, (LPARAM)0); //Densità
  1354.                         SendMessage(hwndTrack, TBM_SETPOS, FALSE, (LPARAM)prec); //Posizione iniziale
  1355.                         SendMessage(hwndTrack, TBM_SETBUDDY, TRUE, (LPARAM) sinistra); //Static di riferimento sinistro
  1356.                         SendMessage(hwndTrack, TBM_SETBUDDY, FALSE, (LPARAM) destra); //Static di riferimento destro
  1357.                         /****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
  1358.                         GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  1359.                         hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  1360.             CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
  1361.                         SendMessage(save,WM_SETFONT,(WPARAM) hfont,true);
  1362.                         SendMessage(cancel,WM_SETFONT,(WPARAM) hfont,true);
  1363.                         SendMessage(sinistra,WM_SETFONT,(WPARAM) hfont,true);
  1364.                         SendMessage(destra,WM_SETFONT,(WPARAM) hfont,true);
  1365.                         break;
  1366.                 case WM_PAINT:
  1367.                         PAINTSTRUCT ps;
  1368.                         HDC hdcWindow;
  1369.                         hdcWindow = BeginPaint(hwnd, &ps);
  1370.                         /****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
  1371.                         hfont = CreateFont (22,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  1372.             CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
  1373.                         SelectObject (hdcWindow, hfont);
  1374.                         SetRect (& rect, 100,100,700,200);
  1375.             SetTextColor (hdcWindow, RGB (0,0,0));
  1376.                        
  1377.                         TextOut(hdcWindow,10,70,"Regolare l'accuratezza delle funzioni.",38);
  1378.                         TextOut(hdcWindow,10,100,"Più è accurato, più punti vengono disegnati.",45);
  1379.  
  1380.                         EndPaint(hwnd,&ps);
  1381.                         break;
  1382.                 case WM_COMMAND:
  1383.                         if (LOWORD(wParam)==5)
  1384.                         {
  1385.                                 prec=float(SendMessage(hwndTrack,TBM_GETPOS,NULL,NULL));   //Carico l'ultima posizione
  1386.                                 inc=1/prec;    //calcolo l'incremento
  1387.                                 DestroyWindow(hwnd);   //Chiudo la finestra
  1388.                         }
  1389.                         if (LOWORD(wParam)==6)
  1390.                         {
  1391.                                 prec=preprec;    //Annullo una eventuale modifica
  1392.                                 DestroyWindow(hwnd);   //Chiudo la finestra
  1393.                         }
  1394.                         break;
  1395.                 case WM_DESTROY:
  1396.                         PostQuitMessage(0);    
  1397.                         break;
  1398.                 default:
  1399.                         return DefWindowProc(hwnd,message,wParam,lParam);
  1400.         }
  1401.         return 0;
  1402. }
  1403. //Creazione finestra principale/Dichiarazione di hinstance per le altre finestre.
  1404. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
  1405. {
  1406.    InitCommonControls ();      //Applicazione visual style
  1407.    WNDCLASSEX WndClass,WndClass2,WndClass3,WndClass4;
  1408.    HWND hwnd;
  1409.    MSG Msg;
  1410.    
  1411.    g_hInst = hInstance;
  1412.    //Main Window
  1413.    WndClass.cbSize        = sizeof(WNDCLASSEX);
  1414.    WndClass.style         = 0;
  1415.    WndClass.lpfnWndProc   = WndProc;
  1416.    WndClass.cbClsExtra    = 0;
  1417.    WndClass.cbWndExtra    = 0;
  1418.    WndClass.hInstance     = g_hInst;
  1419.    WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  1420.    WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  1421.    WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  1422.    WndClass.lpszMenuName  = NULL;
  1423.    WndClass.lpszClassName = g_szClassName;
  1424.    WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  1425.    //Curve Window
  1426.    WndClass2.cbSize        = sizeof(WNDCLASSEX);
  1427.    WndClass2.style         = 0;
  1428.    WndClass2.lpfnWndProc   = WindowProcedure2;
  1429.    WndClass2.cbClsExtra    = 0;
  1430.    WndClass2.cbWndExtra    = 0;
  1431.    WndClass2.hInstance     = hInstance;
  1432.    WndClass2.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  1433.    WndClass2.hCursor       = LoadCursor(NULL, IDC_ARROW);
  1434.    WndClass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  1435.    WndClass2.lpszMenuName  = NULL;
  1436.    WndClass2.lpszClassName = name;
  1437.    WndClass2.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  1438.    //FunctionWindow
  1439.    WndClass3.cbSize        = sizeof(WNDCLASSEX);
  1440.    WndClass3.style         = 0;
  1441.    WndClass3.lpfnWndProc   = WindowProcedure3;
  1442.    WndClass3.cbClsExtra    = 0;
  1443.    WndClass3.cbWndExtra    = 0;
  1444.    WndClass3.hInstance     = hInstance;
  1445.    WndClass3.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  1446.    WndClass3.hCursor       = LoadCursor(NULL, IDC_ARROW);
  1447.    WndClass3.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  1448.    WndClass3.lpszMenuName  = NULL;
  1449.    WndClass3.lpszClassName = name2;
  1450.    WndClass3.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  1451.    //Setting Window
  1452.    WndClass4.cbSize        = sizeof(WNDCLASSEX);
  1453.    WndClass4.style         = 0;
  1454.    WndClass4.lpfnWndProc   = WindowProcedure4;
  1455.    WndClass4.cbClsExtra    = 0;
  1456.    WndClass4.cbWndExtra    = 0;
  1457.    WndClass4.hInstance     = hInstance;
  1458.    WndClass4.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  1459.    WndClass4.hCursor       = LoadCursor(NULL, IDC_ARROW);
  1460.    WndClass4.hbrBackground = (HBRUSH)(16);
  1461.    WndClass4.lpszMenuName  = NULL;
  1462.    WndClass4.lpszClassName = name3;
  1463.    WndClass4.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  1464.  
  1465.    //Main Window
  1466.    if(!RegisterClassEx(&WndClass))
  1467.    {
  1468.       MessageBox(0, "Window1 Registration Failed!", "Error!",
  1469.          MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
  1470.       return 0;
  1471.    }
  1472.    //Second Window
  1473.     if(!RegisterClassEx(&WndClass2))
  1474.    {
  1475.       MessageBox(0, "Window2 Registration Failed!", "Error!",
  1476.          MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
  1477.       return 0;
  1478.    }
  1479.    //Third Window
  1480.     if(!RegisterClassEx(&WndClass3))
  1481.    {
  1482.       MessageBox(0, "Window3 Registration Failed!", "Error!",
  1483.          MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
  1484.       return 0;
  1485.    }
  1486.    //Fourt Window
  1487.     if(!RegisterClassEx(&WndClass4))
  1488.    {
  1489.       MessageBox(0, "Window4 Registration Failed!", "Error!",
  1490.          MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
  1491.       return 0;
  1492.    }
  1493.    //CREAZIONE:
  1494.    //Main Window
  1495.    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,g_szClassName,"Paint XY",
  1496.       WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE,
  1497.      175, 0, 1011, 1070,NULL, NULL, g_hInst, NULL);
  1498.    if (hwnd == NULL)
  1499.    {
  1500.       MessageBox(0, "Window Creation Failed!", "Error!",
  1501.          MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
  1502.       return 0;
  1503.    }
  1504.    //Visualizza Main Window
  1505.    ShowWindow(hwnd, nCmdShow);
  1506.    UpdateWindow(hwnd);
  1507.    //Messaggio da Main Window
  1508.    while(GetMessage(&Msg, NULL, 0, 0))
  1509.    {
  1510.       TranslateMessage(&Msg);
  1511.       DispatchMessage(&Msg);
  1512.    }
  1513.    return Msg.wParam;
  1514. }