#include <windows.h>
#include <iostream>
#include "resource.h"
#include "Main.h"

HWND hWnd, hwScreen;

CCalc szCalc;

LRESULT CALLBACK MainDlgProc( HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
	DialogBox( hInstance, MAKEINTRESOURCE(IDD_MAIN), hWnd, (DLGPROC)MainDlgProc );
	return 0;
}

LRESULT CALLBACK MainDlgProc( HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam )
{
	char szBuffer[246] = { 0 }, szBuffer2[246] = { 0 };
	char szBuffer3[246] = { 0 }, szFinalBuffer[246] = { 0 };

	int iEqual;
	
	bool SetComplete, Addition, Subtraction, Division, Multiplication;

	hwScreen = GetDlgItem(hDlg,IDC_Screen);

	switch( Msg )
	{
	case WM_INITDIALOG:
		{
			break;
		}
	case WM_COMMAND:
		switch(wParam)
		{
		case WM_DESTROY:
			{
				PostQuitMessage(0);
				break;
			}
		case IDC_One:
			{
				iEqual = 1;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Two:
			{
				iEqual = 2;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Three:
			{
				iEqual = 3;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Four:
			{
				iEqual = 4;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Five:
			{
				iEqual = 5;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Six:
			{
				iEqual = 6;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Seven:
			{
				iEqual = 7;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Eight:
			{
				iEqual = 8;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Nine:
			{
				iEqual = 9;

				if(SetComplete = true)
				{
					GetWindowText(hwScreen, szBuffer3, sizeof(szBuffer3));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer3);
					strcat(szFinalBuffer, szBuffer);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				else
				{
					GetWindowText(hwScreen, szBuffer2, sizeof(szBuffer2));

					sprintf(szBuffer, "%d", iEqual);

					strcpy(szFinalBuffer, szBuffer);
					strcat(szFinalBuffer, szBuffer2);

					SetWindowText(hwScreen, szFinalBuffer);
				}
				
				break;
			}
		case IDC_Plus:
			{
				Addition = true;
				Subtraction = false;
				Division = false;
				Multiplication = false;

				GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));
			
				strcpy(szFinalBuffer, szBuffer);
				strcat(szFinalBuffer, " + ");
				
				SetWindowText(hwScreen, szFinalBuffer);

				SetComplete = true;

				break;
			}
		case IDC_Subtract:
			{
				Addition = false;
				Subtraction = true;
				Division = false;
				Multiplication = false;

				GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));
			
				strcpy(szFinalBuffer, szBuffer);
				strcat(szFinalBuffer, " - ");
				
				SetWindowText(hwScreen, szFinalBuffer);

				SetComplete = true;

				break;
			}
		case IDC_Divide:
			{
				Addition = false;
				Subtraction = false;
				Division = true;
				Multiplication = false;

				GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));
			
				strcpy(szFinalBuffer, szBuffer);
				strcat(szFinalBuffer, " / ");
				
				SetWindowText(hwScreen, szFinalBuffer);

				SetComplete = true;

				break;
			}
		case IDC_Multiply:
			{
				Addition = false;
				Subtraction = false;
				Division = false;
				Multiplication = true;

				GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));
			
				strcpy(szFinalBuffer, szBuffer);
				strcat(szFinalBuffer, " * ");
				
				SetWindowText(hwScreen, szFinalBuffer);

				SetComplete = true;

				break;
			}
		case IDC_Equal:
			{
				if(Addition = true)
				{
					GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));  
					strncpy(szBuffer2,szBuffer,strstr(szBuffer," ")-szBuffer);   
					sprintf(szFinalBuffer, "%s = %d", szBuffer, szCalc.SetAdd(atol(szBuffer2), atol((strchr(szBuffer, ' + ')+3)))); 
					SetWindowText(hwScreen, szFinalBuffer);  
				}
				else if(Subtraction = true)
				{
					GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));  
					strncpy(szBuffer2,szBuffer,strstr(szBuffer," ")-szBuffer);   
					sprintf(szFinalBuffer, "%s = %d", szBuffer, szCalc.SetSub(atol(szBuffer2), atol((strchr(szBuffer, ' - ')+3)))); 
					SetWindowText(hwScreen, szFinalBuffer); 
				}
				else if(Division = true)
				{
					GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));  
					strncpy(szBuffer2,szBuffer,strstr(szBuffer," ")-szBuffer);   
					sprintf(szFinalBuffer, "%s = %d", szBuffer, szCalc.SetDiv(atol(szBuffer2), atol((strchr(szBuffer, ' / ')+3)))); 
					SetWindowText(hwScreen, szFinalBuffer); 
				}
				else if(Multiplication = true)
				{
					GetWindowText(hwScreen, szBuffer, sizeof(szBuffer));  
					strncpy(szBuffer2,szBuffer,strstr(szBuffer," ")-szBuffer);   
					sprintf(szFinalBuffer, "%s = %d", szBuffer, szCalc.SetMul(atol(szBuffer2), atol((strchr(szBuffer, ' * ')+3)))); 
					SetWindowText(hwScreen, szFinalBuffer);
				}

				break;
			}
		case IDC_Clear:
			{
				SetWindowText(hwScreen, "");
		
				SetComplete = false;
				Addition = false;
				Subtraction = false;
				Division = false;
				Multiplication = false;
			
				break;
			}
		}
	}
	return FALSE;
}

when i press "IDC_Equal" it only ever does addition, even if Addition = false; im really not sure why and i cant think why. Maybe someone can help

What if you declared the bool status at the begining and if the required task is performed, the status is changed

if ( Addition = true) ? or if (Addition == true) ?

You need to change e.g. if(Addition = true) to if(Addition == true)

Since Addition is a boolean value, you could also simply code:

if (Addition) { //do whatever }

That is of course unless you are attempting to make the boolean value true...which would defeat the purpose of checking it in the conditional statement in the first place...

Note: You have similar syntax elsewhere in your code, i.e. lines: 47, 76, 105, 134, 163, 192, 221, 250, 279, 378, 385, 392, 399...

You need to change e.g. if(Addition = true) to if(Addition == true)

ah yes. i always get confused with logical and bitwise operations

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.