1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

c++ mini projects

Discussion in 'C++' started by imported_rakesh, Aug 26, 2010.

  1. imported_rakesh

    imported_rakesh New Member

    Joined:
    Aug 26, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    how to develop scientific calculator programimg
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Have you started anything with it.
     
  3. imported_pavankumar

    imported_pavankumar New Member

    Joined:
    Oct 22, 2010
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    u mean like a windows scientific calci using graphics or normal programming?
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    I meant what have you started now.
     
  5. anubhooti

    anubhooti New Member

    Joined:
    Oct 17, 2010
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    plz help me in making my program in tc++..i hav to make a program of cd world...contents-issuing a cd,date,return date,costs,details of person etc..n modifying dat...
     
  6. anubhooti

    anubhooti New Member

    Joined:
    Oct 17, 2010
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include"stdio.h"
    #include"conio.h"
    #include"dos.h"
    #include"stdlib.h"
    #include"string.h"
    
    void DISPNUM(char *);
    void main()
    {
    	clrscr();
    
    	_setcursortype(0);
    	gotoxy(30,19);
    	textcolor(GREEN+BLINK);
    	cprintf("SIMPLE CALCULATOR");
    	gotoxy(50,21);
    	textcolor(BLUE+BLINK);
    	cprintf("By Rakesh Juyal");
    	getch();
    //	clrscr();
    
    	int x=30,y=10;
    
    	textcolor(WHITE);
    	gotoxy(x,y);
    	cprintf("7    8    9");
    	gotoxy(x,y+2);
    	cprintf("4    5    6");
    	gotoxy(x,y+4);
    	cprintf("1    2    3");
    	gotoxy(x,y+6);
    	cprintf("0");
    
    	textcolor(RED);
    	gotoxy(x+5,y+6);
    	cprintf(".    =");
    
    
    	textcolor(GREEN);
    	x=x+15;
    	gotoxy(x,y);
    	cprintf("/");
    
    	gotoxy(x,y+2);
    	cprintf("*");
    
    	gotoxy(x,y+4);
    	cprintf("-");
    
    	gotoxy(x,y+6);
    	cprintf("+");
    
    //Draw The For Calc//
    	x=28;y=5;
    	gotoxy(x,y);
    
    	textcolor(WHITE);
    
    	//  Ú	     & 		¿ //
    	cprintf("%c",218);
    	gotoxy(28+20,y);
    	cprintf("%c",191);
    	//  Ú	     & 		¿ //
    
    //Horiz. Boundary
    	for(x=29;x<=28+19;x++)
    	{
    		gotoxy(x,y);
    		cprintf("%c",196);
    		gotoxy(x,y+12);
    		cprintf("%c",196);
    	}
    //End of Horiz. Bound
    
    //  Ù  		    &           À  //
    	cprintf("%c",217);
    	x=28;y=y+12;
    	gotoxy(x,y);
    	cprintf("%c",192);
    //End of  Ù  		    &           À  //
    
    //Vertic. Bound.
    
    	for(y=6;y<=16;y++)
    	{
    		gotoxy(x,y);
    		cprintf("%c",179);
    		gotoxy(x+20,y);
    		cprintf("%c",179);
    	}
    //End of Vertic Bou.
    
    	y=6;
    
    	for(x=30;x<=30+16;x++)
    	{
    		gotoxy(x,y);
    		cprintf("%c",196);
    		gotoxy(x,y+2);
    		cprintf("%c",196);
    	}
    
    	gotoxy(30,y+1);
    	cprintf("%c               %c",179,179);
    
    	gotoxy(30,y);
    	cprintf("%c",218);
    	gotoxy(30+16,y);
    	cprintf("%c",191);
    
    
    	gotoxy(30,y+2);
    	cprintf("%c",192);
    	gotoxy(30+16,y+2);
    	cprintf("%c",217);
    
    
    //End of Vertic Bound.
    
    	//OutPut at X=30,Y=8//
    
    
    	char ch;
    char operand1[15]="",operand2[15]="",BLANK[15]="            ";
    	char operator1,first='y';
    	long double num1=0,num2=0;
    	int i=0,ERROR=0; //Digits
    	int MAX=10;
    	DISPNUM(0);
    	do
    	{
    		ch=getch();
    		if(ch=='x1b')
    		{
    			for(int i=1000;i>=200;i=i-50)
    			{
    				sound(i);
    				delay(100);
    			}
    			nosound();
    			break;
    		}
    
    		//Numeric//
    		if((ch>='0')&&(ch<='9'))
    		{
    			if(i<MAX)
    			{
    				if(first=='y')
    				{
    					operand1[i]=ch;
    					DISPNUM(operand1);
    					i++;
    				}
    				else
    				{
    					operand2[i]=ch;
    					DISPNUM(operand2);
    					i++;
    				}
    			}
    			else		//More than 8 digit
    			{
    				ERROR=1;
    			}
    		}
    		else if(ch=='.')
    		{
    			if(first=='y')
    			{
    				if(strchr(operand1,'.')==NULL)
    				{
    					operand1[i]=ch;
    					i++;
    				}
    				DISPNUM(operand1);
    			}
    			else
    			{
    				if(strchr(operand2,'.')==NULL)
    				{
    					operand2[i]=ch;
    					i++;
    				}
    				DISPNUM(operand2);
    			}
    		}
    		//Non Numeric
    		else if (ch=='*')
    		{
    			operator1='*';
    			first='n';
    			i=0;
    		}
    		else if (ch=='/')
    		{
    			operator1='/';
    			first='n';
    			i=0;
    		}
    		else if (ch=='+')
    		{
    			operator1='+';
    			first='n';
    			i=0;
    		}
    		else if (ch=='-')
    		{
    			operator1='-';
    			first='n';
    			i=0;
    		}
    		else if ((ch=='=')||(ch=='
    '))
    		{
    			//Store in Floating
    			if(strcmpi(operand1,BLANK)!=0)
    			{
    				num1=_atold(operand1);
    			}
    			if(strcmpi(operand2,BLANK)!=0)
    			{
    				num2=_atold(operand2);
    			}
    			//Now Calculate
    			switch (operator1)
    			{
    				case '+':
    					num1=num1+num2;
    					break;
    				case '-':
    					num1=num1-num2;
    					break;
    				case '*':
    					num1=num1*num2;
    					break;
    				case '/':
    					num1=num1/num2;
    					break;
    			}
    			//ltoa(num1,operand1,10);
    			gcvt(num1,12,operand1);
    			DISPNUM(operand1);
    			i=0;
    			first='y';
    
    			strcpy(operand1,BLANK);
    			strcpy(operand2,BLANK);
    		}
    		else              //Invalid Choice
    		{
    			ERROR=1;
    		}
    
    //Beep On ERROR else ------ //
    		if (ERROR==0)
    		{
    			sound(920);
    		}
    		else
    		{
    			sound(100);
    			ERROR=0;
    		}
    		delay(250);
    		nosound();
    
    		gotoxy(1,1);
    		cprintf("%d",i);
    
    	}while(1);
    
    
    //	clrscr();
    	gotoxy(30,19);
    	textcolor(GREEN+BLINK);
    	cprintf("SIMPLE CALCULATOR");
    	gotoxy(50,21);
    	textcolor(BLUE+BLINK);
    	cprintf("By Rakesh Juyal");
    //	getch();
    }
    void DISPNUM(char *num)
    {
    	textbackground(RED);
    	gotoxy(31,7);
    	cprintf("               ");
    	gotoxy(31,7);
    	cprintf("%s",num);
    }
     
  7. ashken

    ashken New Member

    Joined:
    Oct 22, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    I have a developed a UI with basic functionality, from here you can go ahead to implement the functionality of the calculator.

    Code:
    //To be compiled with visual C++ 2008.create a blank win32 project
    
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    
    #include <windows.h>
    #include <commctrl.h>
    
    #define ID_FILE 0
    #define ID_ABOUT 22
    #define ID_EXIT 23
    //edit box
    #define ID_EDIT 1
    //buttons
    #define BTN1 2
    #define BTN2 3
    #define BTN3 4
    #define BTN4 5
    #define BTN5 6
    #define BTN6 7
    #define BTN7 8
    #define BTN8 9
    #define BTN9 10
    #define BTN0 11
    #define BTNd 12
    #define BTNmod 13
    
    #define plus 14
    #define minus 15
    #define mult 16
    #define div 17
    #define Cl 18
    #define equi 19
    #define MC 20
    #define MR 21
    
    char classname[]="mycalc";
    
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    void menus(HWND);
    
    HINSTANCE hInst;
    HWND editbox;
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpstr,int cmd)
    {
    
        HWND hwnd;
        WNDCLASSEX wc;
        MSG msg;
    
        wc.hInstance = hInstance;
        wc.lpszClassName = classname;
        wc.lpfnWndProc = WndProc;
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = 0;
    
        wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
        wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
        wc.hCursor = LoadCursor(NULL,IDC_ARROW);
        wc.lpszMenuName =0;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = wc.cbClsExtra;
        wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(0,"Window Class Registration Failed","Error",MB_OK);
            return 1;
        }
    
        hwnd = CreateWindowEx(
                              0,
                              classname,
                              "Calculator",
                              WS_OVERLAPPEDWINDOW&~(WS_MAXIMIZEBOX|WS_THICKFRAME),//disable window resizing & maximizebox
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              230,
                              250,
                              0,
                              NULL,
                              hInstance,
                              NULL
                              );
    
        ShowWindow(hwnd,cmd);
    
        while(GetMessage(&msg,NULL,0,0)>0)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
    {
    
        switch(message)
        {
            case WM_CREATE:
            menus(hwnd);
            //HWND editbox;
            HWND one,two,three,four,five,six,seven ,eight,nine,zero,dot,modulo;
            HWND add,mc,sub,mr,timx, cls,equival,divi;
    
            editbox = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILD|WS_VISIBLE,10,10,200,25,hwnd,(HMENU)ID_EDIT,GetModuleHandle(NULL),NULL);
    
            one = CreateWindow("button","1",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,10,55,30,25,hwnd,(HMENU)BTN1,hInst,0);
            two = CreateWindow("button","2",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,45,55,30,25,hwnd,(HMENU)BTN2,hInst,0);
            three = CreateWindow("button","3",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,80,55,30,25,hwnd,(HMENU)BTN3,hInst,0);
            four = CreateWindow("button","4",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,10,90,30,25,hwnd,(HMENU)BTN4,hInst,0);
            five = CreateWindow("button","5",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,45,90,30,25,hwnd,(HMENU)BTN5,hInst,0);
            six = CreateWindow("button","6",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,80,90,30,25,hwnd,(HMENU)BTN6,hInst,0);
            seven = CreateWindow("button","7",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,10,125,30,25,hwnd,(HMENU)BTN7,hInst,0);
            eight = CreateWindow("button","8",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,45,125,30,25,hwnd,(HMENU)BTN8,hInst,0);
            nine = CreateWindow("button","9",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,80,125,30,25,hwnd,(HMENU)BTN9,hInst,0);
            zero = CreateWindow("button","0",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,10,160,30,25,hwnd,(HMENU)BTN0,hInst,0);
            dot = CreateWindow("button",".",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,45,160,30,25,hwnd,(HMENU)BTNd,hInst,0);
            modulo = CreateWindow("button","%",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,80,160,30,25,hwnd,(HMENU)BTNmod,hInst,0);
    
            add = CreateWindow("button","+",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,55,30,25,hwnd,(HMENU)plus,hInst,0);
            mc = CreateWindow("button","MC",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,55,30,25,hwnd,(HMENU)MC,hInst,0);
            sub = CreateWindow("button","-",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,90,30,25,hwnd,(HMENU)minus,hInst,0);
            mr = CreateWindow("button","MR",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,90,30,25,hwnd,(HMENU)MR,hInst,0);
            timx = CreateWindow("button","x",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,125,30,25,hwnd,(HMENU)mult,hInst,0);
            cls = CreateWindow("button","C",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,125,30,25,hwnd,(HMENU)Cl,hInst,0);
            divi = CreateWindow("button","/",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,160,30,25,hwnd,(HMENU)div,hInst,0);
            equival = CreateWindow("button","=",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,160,30,25,hwnd,(HMENU)equi,hInst,0);
    
            break;
    
            case WM_COMMAND:
            DWORD len;
            DWORD buffsize;
            LPSTR text;
            switch(LOWORD(wparam))
            {
                case ID_ABOUT:
                MessageBox(hwnd,"Calculator Application Example Using Win32 API\nBy - Ashken","About",MB_OK);
                break;
                case ID_EXIT:
                SendMessage(hwnd,WM_CLOSE,0,0);
                break;
    
                case BTN0:
    			SetWindowText(editbox,"0");
                break;
    
                case BTN1:
                SetWindowText(editbox,"1");
                break;
    
                case BTN2:
                SetWindowText(editbox,"2");
                break;
                case BTN3:
                SetWindowText(editbox,"3");
                break;
                case BTN4:
                SetWindowText(editbox,"4");
                break;
                case BTN5:
                SetWindowText(editbox,"5");
                break;
                case BTN6:
                SetWindowText(editbox,"6");
                break;
                case BTN7:
                SetWindowText(editbox,"7");
                break;
                case BTN8:
                SetWindowText(editbox,"8");
                break;
    
                case BTN9:
                SetWindowText(editbox,"9");
                break;
    			case BTNd:
    				SetWindowText(editbox,".");
    				break;
    			case BTNmod:
    				SetWindowText(editbox,"%");
    				break;
    			case Cl:
    				SetWindowText(editbox,"");
    				break;
    
    
            }
    
    
            break;
    
            case WM_DESTROY:
            PostQuitMessage(0);
            break;
    
            default:
            return DefWindowProc(hwnd,message,wparam,lparam);
        }
        return 0;
    }
    
    void menus(HWND handle)
    {
        HMENU bar,menu;
        bar = CreateMenu();
        menu = CreateMenu();
        AppendMenu(menu,MF_STRING,ID_ABOUT,"&About");
    	AppendMenu(menu,MF_SEPARATOR,0,0);
        AppendMenu(menu,MF_STRING,ID_EXIT,"&Quit");
    
        AppendMenu(bar,MF_POPUP,(UINT_PTR)menu,"&File");
        SetMenu(handle,bar);
    
    }
    
    
    regards!!
     
  8. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    Askhen this is really nice. Thanks for sharing.
     
  9. ashken

    ashken New Member

    Joined:
    Oct 22, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    I was able to add some functionality on the calculator,it can now perform simple math on integers.

    Code:
    #include <windows.h>
    #include <commctrl.h>
    #include <shlwapi.h>
    
    #define ID_FILE 0
    #define ID_ABOUT 22
    #define ID_EXIT 23
    //edit box
    #define ID_EDIT 1
    //buttons
    #define BTN1 2
    #define BTN2 3
    #define BTN3 4
    #define BTN4 5
    #define BTN5 6
    #define BTN6 7
    #define BTN7 8
    #define BTN8 9
    #define BTN9 10
    #define BTN0 11
    #define BTNd 12
    #define BTNmod 13
    
    #define plus 14
    #define minus 15
    #define mult 16
    #define div 17
    #define Cl 18
    #define equi 19
    #define MC 20
    #define MR 21
    
    #define statab 23
    #define okbut 24
    char classname[]="mycalc";
    
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    LRESULT CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);
    void reg();
    void create();
    
    void sum(HWND);
    void subt(HWND);
    void division(HWND);
    void multiplication(HWND);
    
    void menus(HWND);
    HINSTANCE dhinst;
    HINSTANCE hInst;
    HWND editbox;
    HWND zero;
    
    int plusb;
    int alt;
    int multiply;
    int divide;
    int subtract;
    HWND stat,okb;
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpstr,int cmd)
    {
    	dhinst=hInstance;
        HWND hwnd;
        WNDCLASSEX wc;
        MSG msg;
        wc.hInstance = hInstance;
        wc.lpszClassName = classname;
        wc.lpfnWndProc = WndProc;
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = 0;
        wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
        wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
        wc.hCursor = LoadCursor(NULL,IDC_ARROW);
        wc.lpszMenuName =0;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = wc.cbClsExtra;
        wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
        if(!RegisterClassEx(&wc))
        {
            MessageBox(0,"Window Class Registration Failed","Error",MB_OK);
            return 1;
        }
        hwnd = CreateWindowEx(
                              0,
                              classname,
                              "Calculator",
                              WS_OVERLAPPEDWINDOW&~(WS_MAXIMIZEBOX|WS_THICKFRAME),
                              300,
                              150,
                              230,
                              250,
                              0,
                              NULL,
                              hInstance,
                              NULL
                              );
        ShowWindow(hwnd,cmd);
        while(GetMessage(&msg,NULL,0,0)>0)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
    {
        switch(message)
        {
            case WM_CREATE:
    			reg();
            menus(hwnd);
            HWND one,two,three,four,five,six,seven ,eight,nine,dot,modulo;
            HWND add,mc,sub,mr,timx, cls,equival,divi;
            editbox = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",ES_NUMBER|WS_CHILD|WS_VISIBLE,10,10,200,25,hwnd,(HMENU)ID_EDIT,GetModuleHandle(NULL),NULL);
            one = CreateWindow("button","1",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,10,55,30,25,hwnd,(HMENU)BTN1,hInst,0);
            two = CreateWindow("button","2",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,45,55,30,25,hwnd,(HMENU)BTN2,hInst,0);
            three = CreateWindow("button","3",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,80,55,30,25,hwnd,(HMENU)BTN3,hInst,0);
            four = CreateWindow("button","4",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,10,90,30,25,hwnd,(HMENU)BTN4,hInst,0);
            five = CreateWindow("button","5",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,45,90,30,25,hwnd,(HMENU)BTN5,hInst,0);
            six = CreateWindow("button","6",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,80,90,30,25,hwnd,(HMENU)BTN6,hInst,0);
            seven = CreateWindow("button","7",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,10,125,30,25,hwnd,(HMENU)BTN7,hInst,0);
            eight = CreateWindow("button","8",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,45,125,30,25,hwnd,(HMENU)BTN8,hInst,0);
            nine = CreateWindow("button","9",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,80,125,30,25,hwnd,(HMENU)BTN9,hInst,0);
            zero = CreateWindow("button","0",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,10,160,30,25,hwnd,(HMENU)BTN0,hInst,0);
            dot = CreateWindow("button",".",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,45,160,30,25,hwnd,(HMENU)BTNd,hInst,0);
            modulo = CreateWindow("button","%",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,80,160,30,25,hwnd,(HMENU)BTNmod,hInst,0);
            add = CreateWindow("button","+",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,55,30,25,hwnd,(HMENU)plus,hInst,0);
            mc = CreateWindow("button","MC",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,55,30,25,hwnd,(HMENU)MC,hInst,0);
            sub = CreateWindow("button","-",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,90,30,25,hwnd,(HMENU)minus,hInst,0);
            mr = CreateWindow("button","MR",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,90,30,25,hwnd,(HMENU)MR,hInst,0);
            timx = CreateWindow("button","x",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,125,30,25,hwnd,(HMENU)mult,hInst,0);
            cls = CreateWindow("button","C",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,125,30,25,hwnd,(HMENU)Cl,hInst,0);
            divi = CreateWindow("button","/",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,145,160,30,25,hwnd,(HMENU)div,hInst,0);
            equival = CreateWindow("button","=",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE|WS_CHILD,180,160,30,25,hwnd,(HMENU)equi,hInst,0);
    
            break;
            case WM_COMMAND:
            INT len;
            
            LPSTR text;
    		
    
            len=GetWindowTextLength(editbox)+1;
    		text=(LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len);
    		GetWindowText(editbox,text,len);
    		BOOL success;
    
            switch(LOWORD(wparam))
            {
                case ID_ABOUT:
                create();
                break;
                case ID_EXIT:
                SendMessage(hwnd,WM_CLOSE,0,0);
                break;
    
    			case BTN0:
                if(text==NULL)
    				{
    					StrCpy(text,"0");
    				}
    			    else{
    					StrCat(text,"0");
    				}
    			SetWindowText(editbox,text);
                break;
    
                case BTN1:
    				if(text==NULL)
    				{
    					StrCpy(text,"1");
    				}
    				else{
    					StrCat(text,"1");
    				}
                SetWindowText(editbox,text);
                break;
                case BTN2:
    				if(text==NULL)
    				{
    					StrCpy(text,"2");
    				}
    				else
    				{
    					StrCat(text,"2");
    				}
                SetWindowText(editbox,text);
                break;
    
                case BTN3:
               if(text==NULL)
    			{
    				StrCpy(text,"3");
    			}
    			else
    			{
    				StrCat(text,"3");
    			}
                SetWindowText(editbox,text);
                break;
                case BTN4:
    				if(text==NULL)
    				{
    					StrCpy(text,"4");
    				}
    				else
    				{
    					StrCat(text,"4");
    				}
                SetWindowText(editbox,text);
                break;
                case BTN5:
    				if(text==NULL)
    				{
    					StrCpy(text,"5");
    				}
    				else
    				{
    					StrCat(text,"5");
    				}
                SetWindowText(editbox,text);
                break;
                case BTN6:
    				if(text==NULL)
    				{
    					StrCpy(text,"6");
    				}
    				else{
    					StrCat(text,"6");
    				}
                SetWindowText(editbox,text);
                break;
                case BTN7:
    				if(text==NULL)
    				{
    					StrCpy(text,"7");
    				}
    				else
    				{
    					StrCat(text,"7");
    				}
                SetWindowText(editbox,text);
                break;
                case BTN8:
    				if(text==NULL)
    				{
    					StrCpy(text,"8");
    				}
    				else
    				{
    					StrCat(text,"8");
    				}
                SetWindowText(editbox,text);
                break;
                case BTN9:
    				if(text==NULL)
    				{
    					StrCpy(text,"9");
    				}
    				else
    				{
    					StrCat(text,"9");
    				}
                SetWindowText(editbox,text);
                break;
    			case BTNd:
    				MessageBeep(MB_ICONERROR);
    				break;
    			case BTNmod:
    				MessageBeep(MB_ICONERROR);
    				SetWindowText(editbox,text);
    				break;
    			case MC:
    				SetWindowText(editbox,"");
    				break;
    			case MR:
    				SetWindowText(editbox,"");
    				break;
    			case Cl:
    				SetWindowText(editbox,"");
    				break;
    			case plus:
    				plusb=GetDlgItemInt(hwnd,ID_EDIT,&success,FALSE);
    				SetWindowText(editbox,"");
    				break;
    
    			case mult:
    				multiply=GetDlgItemInt(hwnd,ID_EDIT,&success,FALSE);
    			    SetWindowText(editbox,"");
    				break;
    
    			case div:
    				divide = GetDlgItemInt(hwnd,ID_EDIT,&success,FALSE);
    				SetWindowText(editbox,"");
    				break;
    
    			case minus:
    				subtract=GetDlgItemInt(hwnd,ID_EDIT,&success,FALSE);
    				SetWindowText(editbox,"");
    				break;
    
    			case equi:
    				alt=GetDlgItemInt(hwnd,ID_EDIT,&success,FALSE);
    			
    				if(plusb!=NULL)
    					sum(hwnd);
    				
    			    else if(multiply !=NULL)
    					multiplication(hwnd);
    				
    				else if(divide != NULL && alt != NULL)
    					division(hwnd);
    				else if(subtract !=NULL)
    					subt(hwnd);
    				
    				break;
            }
    		
            break;
            case WM_DESTROY:
            PostQuitMessage(0);
            break;
            default:
            return DefWindowProc(hwnd,message,wparam,lparam);
        }
        return 0;
    }
    
    void menus(HWND handle)
    {
        HMENU bar,menu;
        bar = CreateMenu();
        menu = CreateMenu();
        AppendMenu(menu,MF_STRING,ID_ABOUT,"&About");
    	AppendMenu(menu,MF_SEPARATOR,0,0);
        AppendMenu(menu,MF_STRING,ID_EXIT,"&Quit");
    
        AppendMenu(bar,MF_POPUP,(UINT)menu,"&File");
        SetMenu(handle,bar);
    }
    
    void reg()
    {
    	WNDCLASSEX wc={0};
    	wc.hInstance =dhinst;
    	wc.lpfnWndProc = DlgProc;
    	wc.cbSize=sizeof(WNDCLASSEX);
    	wc.lpszClassName = "aap";
    	wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
    
    	RegisterClassEx(&wc);
    }
    void create()
    {
    	CreateWindowEx(
    		WS_EX_DLGMODALFRAME|WS_EX_TOPMOST,
    		"aap",
    		"About",
    		WS_VISIBLE|WS_CAPTION,
    		370,
    		270,
    		180,
    		150,
    		0,
    		0,
    		dhinst,
    		0);
    }
    
    LRESULT CALLBACK DlgProc(HWND hwndd,UINT dmsg,WPARAM wpar,LPARAM lpar)
    {
    	switch(dmsg)
    	{
    	case WM_CREATE:
    		stat = CreateWindow("static","Calculator Application \n\n     by  ashken",WS_CHILD|WS_VISIBLE,10,10,200,100,hwndd,(HMENU)statab,0,0);
    		okb = CreateWindow("button","Close",BS_DEFPUSHBUTTON|WS_CHILD|WS_VISIBLE,50,80,80,25,hwndd,(HMENU)okbut,0,0);
           break;
    	case WM_COMMAND:
    		switch(wpar)
    		{
    		case okbut:
    			DestroyWindow(hwndd);
    			break;
    		}
    		break;
    	case WM_DESTROY:
    		DestroyWindow(hwndd);
    		break;
    	default:
    		return(DefWindowProc(hwndd,dmsg,wpar,lpar));
    	}
    	return 0;
    }
    
    void sum(HWND hwnd)
    {
        plusb += alt;
        SetWindowText(editbox,"");
        SetDlgItemInt(hwnd,ID_EDIT,plusb,FALSE);
    	plusb=NULL;
    }
    void subt(HWND hwnd)
    {
       subtract-=alt;
       SetWindowText(editbox,"");
       SetDlgItemInt(hwnd,ID_EDIT,subtract,FALSE);
       subtract=NULL;
    }
    void multiplication(HWND hwnd)
    {
         multiply *= alt;
         SetWindowText(editbox,"");
    	 SetDlgItemInt(hwnd,ID_EDIT,multiply,FALSE);
    	 multiply=NULL;
    }
    void division(HWND hwnd)
    {
        divide /=alt;
    	SetWindowText(editbox,"");
    	SetDlgItemInt(hwnd,ID_EDIT,divide,FALSE);
    	divide=NULL;
    }
    
    
     
  10. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    Thanks for sharing.
     
  11. saara.ansari

    saara.ansari New Member

    Joined:
    Dec 3, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    m student
    Location:
    on EARTH
    ahan very nice sharing.....thanx 4 sharing
     

Share This Page