/***************************************************
***********PAINT XY -SISTEMI & GRAFICI DA FILE-*****
***********AUTORE: DANY****************************
***********DATA: 17/07/12************************
***********ORE: 20:23*****************************
***********VERSIONE: 1.1***************************/
//Dichiarazione Header
#include <windows.h>
#include <Windowsx.h>
#include <commctrl.h>
#include <cmath>
#include <ctime>
#include <stack>
#include <fstream>
#include <cstring>
//Dichiarazione librerie:
#include "funzioni.h"
//Dichiarazioni per visual style (grafica win 7)
#pragma comment( lib, "comctl32.lib")
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
//Fine Dichiarazioni... //prima della p--> \
//Namespace:
using namespace std;
//Dichiarazione variabili globali:
//Class Name delle finestre
static char g_szClassName[] = "Main",name[]="File",name2[]="System";
static HINSTANCE g_hInst = NULL;
//Timer per la WM_Timer nella mainWindows
const UINT idTimer1 = 1;
UINT nTimerDelay = 1;
//Bitmap
HBITMAP hbmBall, hbmMask,griglia,maskgri;
BITMAP bm;
//Coordinate Punto funzione
int ballX, ballY;
//Variabile che indica se è stato cliccato il tasto disegna nella finestra dei file
int agg=0;
//Font dei Caratteri:
RECT rect;
HFONT hfont;
LOGFONT lf;
//Progress Bar in file Window
HWND prog;
//Progress Bar in system windows
HWND prog2;
//stringhe che in function window contiene le funzioni in notazione polacca inversa.
string rpn="",rpn2="",rpn3="",rpn4="";
//Variabile che indica se il pulsante disegna in function window è stato premuto.
int funpress=0;
//Point che contiene le posizioni dei punti che collegherà la linea
POINT pp[2],p[2];
//Minimi e massimi delle equazioni dei sistemi
float Mx=0,My=0;
//Precisione
int prec=0;
//Se checkbox è checkata in filewindow
int ck,ckx;
//Dichiarazione della WndProc Della MainWindow
LRESULT CALLBACK WndProc(HWND hwnd ,UINT Message, WPARAM wParam, LPARAM lParam);
//Disegna il punto utilizzato nelle rappresentazioni di cruve e funzioni.
void DrawBall(HDC hdc)
{
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
SelectObject(hdcMemory, hbmMask);
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hbmBall);
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCPAINT);
DeleteDC(hdcMemory);
}
//Disegna la griglia di sfondo
void DrawGriglia(HDC hdc)
{
HDC hdcMemory=0;
hdcMemory=CreateCompatibleDC(hdc);
SelectObject(hdcMemory, maskgri);
BitBlt(hdc, 0, 0, 1000, 1000, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, griglia);
BitBlt(hdc, 0, 0, 1000, 1000, hdcMemory, 0, 0, SRCPAINT);
DeleteDC(hdcMemory);
}
/*************************************************************************************************************/
//Dichiarazione variabili in WndProc
//Variabili disegno funzione
double i,x,y,j;
//Variabili Menu:
HMENU file,hfile,info,hinfo,modifica,hmodifica;
int MENU_FILE_EXIT=0; //Valore ritorno se si clicca su "Esci"
int MENU_FILE_CURV=1; //Valore ritorno se si clicca su "Disegna Equazione"
int MENU_FILE_FUNZ=2; //Valore ritorno se si clicca su "Disegna da file"
int MENU_FILE_ABOU=3; //Valore ritorno se si clicca su "Informazioni su "Paint XY"
int MENU_FILE_HELP=4; //Valore ritorno se si clicca su "HELP"
int MENU_FILE_CLEA=6; //Valore ritorno se si clicca su "Pulisci"
/*Variabili posizione mouse*/
HWND lix,ley;
float cox=0,coy=0;
char cux[7]="",cooy[7]="";
/*result:*/
float result,result2,result3,result4;
//Scrive punti di inersezione
char pax[6],pay[6];
/*WNDPROC DELLA MAIN*/
LRESULT CALLBACK WndProc(HWND hwnd ,UINT Message, WPARAM wParam, LPARAM lParam)
{
InitCommonControls (); //Applicazione visual style
switch(Message)
{
case WM_CREATE:
//Nella finestra principale:
//Inizializzazione delle immagini BMP
hbmBall = LoadBitmap(g_hInst, "BALLBMP");
griglia = LoadBitmap(g_hInst, "gri");
hbmMask = LoadBitmap(g_hInst, "MASKBMP");
maskgri = LoadBitmap(g_hInst, "maskgri");
if(!hbmBall || !hbmMask)
{
MessageBox(hwnd, "Load of resources failed.", "Error",MB_OK | MB_ICONEXCLAMATION);
return -1;
}
GetObject(hbmBall, sizeof(bm), &bm);
//Timer:
SetTimer(hwnd, idTimer1, nTimerDelay, NULL);
//Menu:
//Dichiarazione Menu:
file=CreateMenu();
hfile=CreatePopupMenu();
info=CreateMenu();
hinfo=CreatePopupMenu();
modifica=CreateMenu();
hmodifica=CreatePopupMenu();
//Creazione Menu:
/*File*/
AppendMenu(file,MF_STRING|MF_POPUP,(UINT_PTR) hfile,TEXT("File"));
AppendMenu(hfile,MF_STRING,MENU_FILE_EXIT,TEXT("Esci"));
/*Modifica*/
AppendMenu(file,MF_STRING|MF_POPUP,(UINT_PTR) hmodifica,TEXT("Disegna"));
AppendMenu(hmodifica,MF_STRING,MENU_FILE_CURV,TEXT("Grafico da File"));
AppendMenu(hmodifica,MF_STRING,MENU_FILE_FUNZ,TEXT("Sistema"));
AppendMenu(hmodifica,MF_STRING,MENU_FILE_CLEA,TEXT("Pulisci"));
/*Info*/
AppendMenu(file,MF_STRING|MF_POPUP,(UINT_PTR) hinfo,TEXT("Info"));
AppendMenu(hinfo,MF_STRING,MENU_FILE_ABOU,TEXT("Informazioni su Paint XY"));
AppendMenu(hinfo,MF_STRING,MENU_FILE_HELP,TEXT("Help"));
//Rende visibile i menu
SetMenu(hwnd,file);
//Piccolo edit che scrive la posizione del mouse nella finestra:
lix=CreateWindow("edit","",WS_CHILD|WS_VISIBLE|ES_READONLY|WS_BORDER,5,5,50,20,hwnd,(HMENU)100,0,0);
ley=CreateWindow("edit","",WS_CHILD|WS_VISIBLE|ES_READONLY|WS_BORDER,60,5,50,20,hwnd,(HMENU)100,0,0);
/****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, 5, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
SendMessage (lix, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (ley, WM_SETFONT, (WPARAM) hfont, true);
break;
case WM_TIMER:
if(hbmBall && hbmMask)
{
HDC hdcWindow;
hdcWindow = GetDC(hwnd);
/*SETTO LA PENNA E LA CASUALITÃ DEL COLORE*/
srand(time(NULL));
HPEN penna=CreatePen(PS_SOLID,3, RGB(rand()%255,100-rand()%255,100+rand()%255));
SelectObject(hdcWindow,penna);
//Disegno Equazioni:***************************************************************************************************************
if (funpress>0) //Se è stato cliccato il pulsante disegna nella funciton windows:
{
/*FUNZIONAMENTO IN BREVE:
*Il grafico si compone da destra verso sinistra con linee che si alternano:
*una va dall'alto in basso, la successiva dal basso all'alto in modo che
*dato che i punti si collegano in successione, visaranno meno linee trasversali possibile*/
int alt=0;
funpress=0;
//Il ciclo va dall'opposto del massimo di x a quest'ultimo con
//un incremento del doppio di questo fratto la precisione scelta.
for (i=-Mx;i<=Mx;i=i+(2*Mx)/prec)
{
x=i;
//Aggiorno la progress bar
SendMessage(prog,PBM_SETPOS,1+(i+Mx)*100/(2*Mx),0);
alt++;
//'Alt' si incrementa ogni ciclo, permette di alternare il verso in cui il
//programma trova i punti (infatti i 2 ccli sono inversi)
//in modo che, dato che il programma collega i punti in successione,
//ridurre al minimo le linee trasversali.
if (alt%2==0)
for (j=-My;j<=My;j=j+(My*2)/prec)
{
y=j;
//Risolvo le equazioni in notazione rpn
result=SolveRPN(rpn,x,y);
result2=SolveRPN(rpn2,x,y);
result3=SolveRPN(rpn3,x,y);
result4=SolveRPN(rpn4,x,y);
//Se la differenza tra i due membri è minore della
//millesima parte del valore massimo, allora disegna il punto(o linea)
//Questo è più efficace di 'result==result2' poichè può capitare
//che a causa dell'incremento nel ciclo il valore della prima
//espressione non sarà mai uguale a quella della seconda, e perciò
//metto un margine di errore.
if (fabs(result-result2)<=Mx/1000)
{
//Converto i valori in coordinate pixel in proporzione
//al massimo delle rispettive varabili
ballX=conx(x,Mx);
ballY=cony(y,My);
//memorizzo il punto nell'array
pp[1].x=ballX;
pp[1].y=ballY;
/*Il programma traccia una linea che collega i due punti nell'array 'pp'
* SE:
-LE COO. DEL PUNTO PRECEDENTEMENTE (PP[0])TROVATO DA COLLEGARE A QUESTO
APPENA TROVATO SONO DIVERSE DA 0 (COSì NON SI COLLEGA ALL'INIZIO DELLA
FINESTRA, POICHè L'ARRAY è INIZIALIZZATO CON PP[0]=0.
-LA DISTANZA TRA I DUE PUNTI è MINORE DI 220 COSì DA EVITARE IL
COLLEGAMENTO ERRONEO DI PUNTI DISTANTI COME IN "Y=1/X". INFATTI
SENZA DI QUESTA, VI SAREBBE UNA LINEA CHE COLLEGA ERRONEAMENTE
IL PUNTO PIù IN BASSO CON QUELLO PIù IN ALTO (DETTO TERRA TERRA)
-E' ATTIVATA LA SPUNTA A "COLLEGA CON LINEE" */
if ((pp[0].x>0)&&(pp[0].y>0)&&(dist(pp[1],pp[0])<220)&&(ckx==BST_CHECKED))
Polyline(hdcWindow,pp ,2);
//Se la spunta non è attivata, allora disegna solo un punto
if (ckx!=BST_CHECKED)
DrawBall(hdcWindow);
//pp[0] riassume il valore attuale delle coordinate e si ripete il ciclo
pp[0].x=ballX;
pp[0].y=ballY;
}
//CIò SI RIPETE UGUALMENTE PER L'ALTRA EQUAZIONE*/
if (fabs(result3-result4)<=Mx/1000)
{
ballX=conx(x,Mx);
ballY=cony(y,My);
p[1].x=ballX;
p[1].y=ballY;
if ((p[0].x>0)&&(p[0].y>0)&&(dist(p[1],p[0])<220)&&(ckx==BST_CHECKED))
Polyline(hdcWindow,p ,2);
if (ckx!=BST_CHECKED)
DrawBall(hdcWindow);
p[0].x=ballX;
p[0].y=ballY;
}
/*SE PER LA COPPIA X-Y VENGONO VERIFICATE TUTTE LE EQUAZIONI, SIAMO DI FRONTE A UN PUNTO DI
*INTERSEZIONE*/
if ((fabs(result-result2)<=Mx/1000)&&(fabs(result3-result4)<=Mx/1000))
{
sprintf(pax, "%6.2f", x); //Converto da float a *char
sprintf(pay, "%6.2f", y); //Converto da float a *char
TextOut(hdcWindow,conx(x,Mx),cony(y,My),pax,sizeof(pax));
TextOut(hdcWindow,conx(x,Mx)+40,cony(y,My),pay,sizeof(pay));
}
}
else
//CICLO INVERSO:
for (j=My;j>=-My;j=j-(My*2)/prec)
{
//FUNZIONA UGUALE A QUELLO PRECEDENTE
y=j;
result=SolveRPN(rpn,x,y);
result2=SolveRPN(rpn2,x,y);
result3=SolveRPN(rpn3,x,y);
result4=SolveRPN(rpn4,x,y);
if (fabs(result-result2)<=Mx/1000)
{
ballX=conx(x,Mx);
ballY=cony(y,My);
pp[1].x=ballX;
pp[1].y=ballY;
if ((pp[0].x>0)&&(pp[0].y>0)&&(dist(pp[1],pp[0])<220&&(ckx==BST_CHECKED)))
Polyline(hdcWindow,pp ,2);
if (ckx!=BST_CHECKED)
DrawBall(hdcWindow);
pp[0].x=ballX;
pp[0].y=ballY;
}
if (fabs(result3-result4)<=Mx/1000)
{
ballX=conx(x,Mx);
ballY=cony(y,My);
p[1].x=ballX;
p[1].y=ballY;
if ((p[0].x>0)&&(p[0].y>0)&&(dist(p[1],p[0])<220)&&(ckx==BST_CHECKED))
Polyline(hdcWindow,p ,2);
if (ckx!=BST_CHECKED)
DrawBall(hdcWindow);
p[0].x=ballX;
p[0].y=ballY;
}
if ((fabs(result-result2)<=Mx/1000)&&(fabs(result3-result4)<=Mx/1000))
{
sprintf(pax, "%6.2f", x); //Converto da float a *char
sprintf(pay, "%6.2f", y); //Converto da float a *char
TextOut(hdcWindow,conx(x,Mx),cony(y,My),pax,sizeof(pax));
TextOut(hdcWindow,conx(x,Mx)+40,cony(y,My),pay,sizeof(pay));
}
}
}
//Una volta disegnate le equazioni, i due "POINT" vengono azzerati, per evitare
//Che il successivo sistema si colleghi a quello vecchio.
pp[0].x=0;
pp[0].y=0;
p[0].x=0;
p[0].y=0;
}
/*DISEGNO GRAFICO DA FILE **************************************************************/
if (agg>0)
{
fstream ll,kk;
agg=0;
kk.open("X.txt",ios::in);
//Controllo l'esistenza del file
if(kk==NULL)
{
MessageBox(hwnd,"'X.txt' è stato rinominato o eliminato.Controllare.",
"Errore!",MB_ICONERROR);
return 1;
}
Mx=0;
//Ciclo che individua il massimo dei valori
while (!kk.eof())
{
kk >>x;
if (fabs(x)>Mx)
Mx=fabs(x);
}
kk.close();
ll.open("Y.txt",ios::in);
//Controllo l'esistenza del file
if(ll==NULL)
{
MessageBox(hwnd,"'Y.txt' è stato rinominato o eliminato.Controllare.",
"Errore!",MB_ICONERROR);
return 1;
}
My=0;
//Ciclo che individua il massimo dei valori
while (!ll.eof())
{
ll >>y;
if (fabs(y)>My)
My=fabs(y);
}
ll.close();
fstream ff,gg;
ff.open("X.txt",ios::in);
gg.open("Y.txt",ios::in);
//Mentre i file "X.txt" e "Y.txt" non finiscono
//Legge i valori x e y.
while ((!ff.eof())&&(!gg.eof()))
{
ff >>x;
gg >>y;
ballX=conx(x,Mx);
ballY=cony(y,My);
//Se è stato cliccato su "collega con linee"
//lo collega con una linea usando lo stesso metodo per
//i sistemi di equazioni.
if (ck==BST_CHECKED)
{
pp[1].x=ballX;
pp[1].y=ballY;
if ((pp[0].x>0)&&(pp[0].y>0))
Polyline(hdcWindow,pp ,2);
pp[0].x=ballX;
pp[0].y=ballY;
}
//Altrimenti colloca solo i punti.
if (ck!=BST_CHECKED)
DrawBall(hdcWindow);
}
ff.close();
gg.close();
}
pp[0].x=0;
pp[0].y=0;
ReleaseDC(hwnd, hdcWindow);
}
break;
case WM_COMMAND: /***************************************MENU*****************************************************/
if (LOWORD(wParam)==MENU_FILE_EXIT)
{
DestroyWindow(hwnd); //Chiudo la finestra
}
if (LOWORD(wParam)==MENU_FILE_CURV)
{
//Crea e visualizza la finestra delle curve
MSG messages2;
HWND hwnd2 = CreateWindowEx (0,name,"Grafico da File",WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE,400,400,355,300,hwnd, NULL, g_hInst,NULL);
ShowWindow (hwnd2, 1);
while (GetMessage (&messages2, NULL, 0, 0))
{
TranslateMessage(&messages2);
DispatchMessage(&messages2);
}
}
if (LOWORD(wParam)==MENU_FILE_ABOU)
{
MessageBox(hwnd,"Paint XY -SISTEMI & FILE- Versione 1.1","By Dany",MB_OK|MB_ICONINFORMATION);
}
if (LOWORD(wParam)==MENU_FILE_CLEA)
{
ShowWindow(hwnd,0);
ShowWindow(hwnd,1);
Mx=0;My=0;
}
if (LOWORD(wParam)==MENU_FILE_FUNZ)
{
//Crea e visualizza la finestra
MSG messages5;
HWND hwnd5 = CreateWindowEx (0,name2,"Sistema:",WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE,400,400,400,350,hwnd, NULL, g_hInst,NULL);
ShowWindow (hwnd5, 1);
while (GetMessage (&messages5, NULL, 0, 0))
{
TranslateMessage(&messages5);
DispatchMessage(&messages5);
}
}
if (LOWORD(wParam)==MENU_FILE_HELP)
{
system("Guida.txt");
}
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdcWindow;
hdcWindow = BeginPaint(hwnd, &ps);
DrawGriglia(hdcWindow); //Ridisegno la griglia se la finestra viene ridotta a icona/coperta
EndPaint(hwnd, &ps);
break;
case WM_MOUSEMOVE:
/*Coordinate mouse nella finestra
*In pratica Grazie a GET_X_LPARAM (lParam); e a GET_Y_LPARAM (lParam);
*Ottengo le coordinate in pixel dentro la finestra, per poi convertirle
*In coordinate reali.*/
cox = GET_X_LPARAM (lParam);
coy = GET_Y_LPARAM (lParam);
cox=(cox-500)/(500/Mx);
coy=(500-coy)/(500/My);
sprintf(cux, "%6.2f", cox); //Converto da float a *char
sprintf(cooy, "%6.2f", coy); //Converto da float a *char
SetWindowText(lix,cux); //Imposto nell'edit le coordinate x
SetWindowText(ley,cooy); //Imposto nell'edit le coordinate y
break;
case WM_KEYDOWN:
if (LOWORD(wParam)==VK_DELETE) //Pulizia istantanea se si preme CANC
{
ShowWindow(hwnd,0);
ShowWindow(hwnd,1);
Mx=0;My=0;
}
break;
case WM_CLOSE:
if(MessageBox(hwnd,"Vuoi davvero uscire?","Messaggio",MB_YESNO|MB_ICONQUESTION)==IDYES)
DestroyWindow(hwnd);
break;
case WM_DESTROY:
KillTimer(hwnd, idTimer1);
DeleteObject(hbmBall);
DeleteObject(hbmMask);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
//WndProc della finestra per rappresentare Grafici da file
//HWND
HWND rodo;
HWND avvia,line,xtxt,ytxt;
//WndProc della finestra "grafici da file"
LRESULT CALLBACK WindowProcedure2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
InitCommonControls (); //Applicazione visual style
switch (message)
{
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdcWindow;
hdcWindow = BeginPaint(hwnd, &ps);
/****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
hfont = CreateFont (22,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, 5, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
SelectObject (hdcWindow, hfont);
SetRect (& rect, 100,100,700,200);
SetTextColor (hdcWindow, RGB (0,0,0));
TextOut(hdcWindow,0,0,"Crea un Grafico con i valori nei file 'X.txt' e 'Y.txt'",55);
EndPaint(hwnd,&ps);
break;
case WM_CREATE:
//Bottoni
avvia=CreateWindow("Button","AVVIA!",WS_VISIBLE|WS_CHILD,77,100,200,50,hwnd,(HMENU)1,NULL,NULL);
xtxt=CreateWindow("Button","X.txt",WS_VISIBLE|WS_CHILD,102,180,60,60,hwnd,(HMENU)2,NULL,NULL);
ytxt=CreateWindow("Button","Y.txt",WS_VISIBLE|WS_CHILD,202,180,60,60,hwnd,(HMENU)3,NULL,NULL);
//Checkbox
line=CreateWindow("Button","Collega con linee",WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX,117,50,200,25,hwnd,NULL,NULL,NULL);
/****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, 5, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
SendMessage (avvia, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (line, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (xtxt, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (ytxt, WM_SETFONT, (WPARAM) hfont, true);
break;
case WM_COMMAND:
if (LOWORD(wParam)==1)
{
//Controlla lo stato della checkbox
ck=SendMessage(line, BM_GETCHECK, 0,0);
agg++; //è stato premuto il tasto AVVIA!
}
if (LOWORD(wParam)==2) //apre x.txt
system ("start X.txt");
if (LOWORD(wParam)==3)
system ("start Y.txt"); //apre y.txt
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
//Function Window
//Variabile del ciclo
int h;
//HWND
HWND edit,edit2,edit3,edit4,button,sbox;
HWND maxx,maxy,acc;
HBITMAP maskgraf,graf;
//Disegna la parentesi graffa
void DrawGraf(HDC hdc)
{
HDC hdcMemory=0;
hdcMemory=CreateCompatibleDC(hdc);
SelectObject(hdcMemory, maskgraf);
BitBlt(hdc, 15, 30, 25, 60, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, graf);
BitBlt(hdc, 15, 30, 25, 60, hdcMemory, 0, 0, SRCPAINT);
DeleteDC(hdcMemory);
}
//Window Procedure della System Window
LRESULT CALLBACK WindowProcedure3 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
InitCommonControls (); //Applicazione visual style
switch(message)
{
case WM_CREATE:
//Inizializzo la graffa
graf = LoadBitmap(g_hInst, "graf");
maskgraf = LoadBitmap(g_hInst, "maskgra");
/*CHECKBOX*/
sbox=CreateWindow("Button","Collega con linee",WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX,170,165,150,25,hwnd,NULL,NULL,NULL);
/*BARRA*/
prog=CreateWindowEx(NULL, PROGRESS_CLASS, NULL, WS_CHILD|WS_VISIBLE, 20,288, 350, 30, hwnd, NULL, NULL, 0);
/*EDIT*/
edit=CreateWindow("edit","<primo membro>",WS_VISIBLE|WS_CHILD|WS_BORDER|EM_GETLINE,55,30,150,20,hwnd,0,0,0);
edit2=CreateWindow("edit","<secondo membro>",WS_VISIBLE|WS_CHILD|WS_BORDER|EM_GETLINE,219,30,150,20,hwnd,0,0,0);
edit3=CreateWindow("edit","<primo membro>",WS_VISIBLE|WS_CHILD|WS_BORDER|EM_GETLINE,55,70,150,20,hwnd,0,0,0);
edit4=CreateWindow("edit","<secondo membro>",WS_VISIBLE|WS_CHILD|WS_BORDER|EM_GETLINE,219,70,150,20,hwnd,0,0,0);
/*BUTTON*/
button=CreateWindow("Button","CALCOLA!",WS_VISIBLE|WS_CHILD,4,220,385,50,hwnd,(HMENU)2,NULL,NULL);
/*MIN E MAX X E Y E PRECISIONE*/
maxx=CreateWindow("edit","",WS_VISIBLE|WS_CHILD|WS_BORDER,95,130,60,20,hwnd,NULL,NULL,NULL);
maxy=CreateWindow("edit","",WS_VISIBLE|WS_CHILD|WS_BORDER,240,130,60,20,hwnd,NULL,NULL,NULL);
acc=CreateWindow("edit","300",WS_VISIBLE|WS_CHILD|WS_BORDER,95,165,50,20,hwnd,NULL,NULL,NULL);
/****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, 5, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
SendMessage (edit, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (edit2, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (button, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (edit3, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (edit4, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (maxx, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (maxy, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (acc, WM_SETFONT, (WPARAM) hfont, true);
SendMessage (sbox, WM_SETFONT, (WPARAM) hfont, true);
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdcWindow;
hdcWindow = BeginPaint(hwnd, &ps);
/****SETTO I CARATTERI DA UTILIZZARE: FONT, DIMENSIONI ECC...**/
hfont = CreateFont (20,0,0,0, 500, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, 5, VARIABLE_PITCH, TEXT ("Monotype Corsiva"));
SelectObject (hdcWindow, hfont);
SetRect (& rect, 100,100,700,200);
SetTextColor (hdcWindow, RGB (0,0,0));
DrawGraf(hdcWindow);
TextOut(hdcWindow,1,1,"Comporre il sistema desiderato.",31);
TextOut(hdcWindow,206,30,"=",1);
TextOut(hdcWindow,206,70,"=",1);
TextOut(hdcWindow,25,130,"max x =",7);
TextOut(hdcWindow,190,130,"max y =",7);
TextOut(hdcWindow,25,165,"precisione",10);
EndPaint(hwnd,&ps);
break;
case WM_COMMAND:
if (LOWORD(wParam)==2)
{
funpress++; //Indica che è stato premuto il tasto CALCOLA!
//Inizializzo gli array che contengono le espressioni
char in[100]="",in2[100]="",in3[100]="",in4[100]="";
//Prendo il testo negli edit e lo metto negli array
GetWindowText(edit,in,100);
GetWindowText(edit2,in2,100);
GetWindowText(edit3,in3,100);
GetWindowText(edit4,in4,100);
//Mi trovo la notazione polacca inversa (RPN)
rpn=FoundRPN(in);
rpn2=FoundRPN(in2);
rpn3=FoundRPN(in3);
rpn4=FoundRPN(in4);
//leggo i massimi e i minimi e la precisione:
//ne inizializzo gli array
char minix[6]="",maxix[6]="",miniy[6]="",maxiy[6]="",accu[5]="";
//Li catturo dagli edit
GetWindowText(acc,accu,5);
GetWindowText(maxx,maxix,6);
GetWindowText(maxy,maxiy,6);
//Converto le string in float.
Mx=atof(maxix);
My=atof(maxiy);
prec=atoi(accu);
//Controllo lo stato della checkbox
ckx=SendMessage(sbox, BM_GETCHECK, 0,0);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
//Creazione finestra principale/Dichiarazione di hinstance per le altre finestre.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
InitCommonControls (); //Applicazione visual style
WNDCLASSEX WndClass,WndClass2,WndClass3;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
//Main Window
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//Da File Window
WndClass2.cbSize = sizeof(WNDCLASSEX);
WndClass2.style = 0;
WndClass2.lpfnWndProc = WindowProcedure2;
WndClass2.cbClsExtra = 0;
WndClass2.cbWndExtra = 0;
WndClass2.hInstance = hInstance;
WndClass2.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass2.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass2.lpszMenuName = NULL;
WndClass2.lpszClassName = name;
WndClass2.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//SystemWindow
WndClass3.cbSize = sizeof(WNDCLASSEX);
WndClass3.style = 0;
WndClass3.lpfnWndProc = WindowProcedure3;
WndClass3.cbClsExtra = 0;
WndClass3.cbWndExtra = 0;
WndClass3.hInstance = hInstance;
WndClass3.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass3.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass3.hbrBackground = (HBRUSH)(15);
WndClass3.lpszMenuName = NULL;
WndClass3.lpszClassName = name2;
WndClass3.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//Main Window
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window1 Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
//Da file Window
if(!RegisterClassEx(&WndClass2))
{
MessageBox(0, "Window2 Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
//System Window
if(!RegisterClassEx(&WndClass3))
{
MessageBox(0, "Window3 Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
//CREAZIONE:
//Main Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Paint XY- Sistemi -",
WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE,
175, 0, 1011, 1000,
NULL, NULL, g_hInst, NULL);
//incaso di errore
if (hwnd == NULL)
{
MessageBox(0, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
//Visualizza Main Window
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//Messaggio da Main Window
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}