<<<<<------main.cpp------->>>> #include <windows.h> #include <commctrl.h> #inclu
ID: 3571274 • Letter: #
Question
<<<<<------main.cpp------->>>>
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
HINSTANCE hInst;
//declare global variables
//windows handles variables ( elements like buttons text boxes etc)
HWND textBox1;
// char variables
char numtext[10];
// double variables
double number1,number2,result;
//variable to know the operation
enum operation {SUM,MUL,DIV,SUB,NONE};
//string result
string to_string(double x);// function to transform to double to string
string resultstring;
operation SelOperation=NONE;
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
}
return TRUE;
case WM_CLOSE:
{
EndDialog(hwndDlg, 0);
}
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
// code for each button
//get handle for text box
case 1:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"1");
// show thetext
break;
case 2:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"2");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 3:
//get handle
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"3");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 4:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"4");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 5:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"5");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 6:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"6");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 7:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"7");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 8:
//get the number in the textbox
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"8");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 9:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"9");
// show the text
SetWindowText(textBox1,numtext);
break;
case 10:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"0");
// show the text
SetWindowText(textBox1,numtext);
break;
case 11:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,".");
// show the text
SetWindowText(textBox1,numtext);
break;
case 12:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
SetWindowText(textBox1,"0");
cout<<"hello";
break;
case 100:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number1=atof(numtext);
//define operation
SelOperation=SUM;
//delete text box
SetWindowText(textBox1,"");
break;
case 101:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number1=atof(numtext);
//define operation
SelOperation=DIV;
//delete text box
SetWindowText(textBox1,"");
break;
case 102:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number1=atof(numtext);
//define operation
SelOperation=MUL;
//delete text box
SetWindowText(textBox1,"");
break;
case 103:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number2=atof(numtext);
//cout<<number2+0;
// Perform operation
switch (SelOperation)
{
case SUM:
result=number1+number2;
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
SetWindowText(textBox1,numtext);
break;
case DIV:
result=number1/number2;
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
SetWindowText(textBox1,numtext);
break;
case MUL:
result=number1*number2;
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
SetWindowText(textBox1,numtext);
break;
}
break;
}
}
return TRUE;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
// function
std::string to_string(double x)
{
std::ostringstream ss;
ss << x;
return ss.str();
}
<<<<----- resource.h ----->>>>>
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define DLG_MAIN 100
<<<<<------- resource.rc ------>>>>>
// Generated by ResEdit 1.6.6
// Copyright (C) 2006-2015
// http://www.resedit.net
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 186, 212
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
EDITTEXT 200, 17, 12, 148, 18, ES_RIGHT | ES_AUTOHSCROLL, WS_EX_LEFT
GROUPBOX "Numbers", 0, 14, 52, 105, 156, 0, WS_EX_LEFT
PUSHBUTTON "1", 1, 22, 136, 25, 20, 0, WS_EX_LEFT
GROUPBOX "OP.", 0, 129, 47, 51, 161, 0, WS_EX_LEFT
PUSHBUTTON "2", 2, 56, 136, 23, 20, 0, WS_EX_LEFT
PUSHBUTTON "3", 3, 87, 136, 24, 22, 0, WS_EX_LEFT
PUSHBUTTON "+", 100, 139, 60, 33, 32, 0, WS_EX_LEFT
PUSHBUTTON "/", 101, 140, 98, 31, 31, 0, WS_EX_LEFT
PUSHBUTTON "X", 102, 141, 135, 31, 30, 0, WS_EX_LEFT
PUSHBUTTON "=", 103, 141, 172, 31, 29, 0, WS_EX_LEFT
PUSHBUTTON "4", 4, 22, 105, 24, 21, 0, WS_EX_LEFT
PUSHBUTTON "5", 5, 56, 105, 23, 20, 0, WS_EX_LEFT
PUSHBUTTON "6", 6, 87, 105, 22, 19, 0, WS_EX_LEFT
PUSHBUTTON "7", 7, 22, 74, 23, 21, 0, WS_EX_LEFT
PUSHBUTTON "8", 8, 56, 74, 23, 21, 0, WS_EX_LEFT
PUSHBUTTON "9", 9, 87, 74, 22, 20, 0, WS_EX_LEFT
PUSHBUTTON "CE", 12, 23, 171, 24, 20, 0, WS_EX_LEFT
PUSHBUTTON "0", 10, 57, 171, 22, 20, 0, WS_EX_LEFT
PUSHBUTTON ".", 11, 88, 171, 23, 22, 0, WS_EX_LEFT
}
//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 RT_MANIFEST ".\manifest.xml"
Explanation / Answer
<<<<<------main.cpp------->>>>
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath> // pow function
using namespace std;
HINSTANCE hInst;
//declare global variables
//windows handles variables ( elements like buttons text boxes etc)
HWND textBox1;
// char variables
char numtext[10];
// double variables
double number1,number2,result;
//variable to know the operation
enum operation {SUM,MUL,DIV,SUB,NONE,POW};
//string result
string to_string(double x);// function to transform to double to string
string resultstring;
operation SelOperation=NONE;
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
}
return TRUE;
case WM_CLOSE:
{
EndDialog(hwndDlg, 0);
}
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
// code for each button
//get handle for text box
case 1:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"1");
// show thetext
break;
case 2:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"2");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 3:
//get handle
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"3");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 4:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"4");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 5:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"5");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 6:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"6");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 7:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"7");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 8:
//get the number in the textbox
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"8");
// show thetext
SetWindowText(textBox1,numtext);
break;
case 9:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"9");
// show the text
SetWindowText(textBox1,numtext);
break;
case 10:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,"0");
// show the text
SetWindowText(textBox1,numtext);
break;
case 11:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
strcat(numtext,".");
// show the text
SetWindowText(textBox1,numtext);
break;
case 12:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
SetWindowText(textBox1,"0");
cout<<"hello";
break;
case 100:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number1=atof(numtext);
//define operation
SelOperation=SUM;
//delete text box
SetWindowText(textBox1,"");
break;
case 101:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number1=atof(numtext);
//define operation
SelOperation=DIV;
//delete text box
SetWindowText(textBox1,"");
break;
case 102:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number1=atof(numtext);
//define operation
SelOperation=MUL;
//delete text box
SetWindowText(textBox1,"");
break;
case 103:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number2=atof(numtext);
//factorial
case 105:
//get the number in the textbox
textBox1=GetDlgItem(hwndDlg,200);
//get the text from the box
GetWindowText(textBox1,&numtext[0],10);
//add the number to the text
number1=atof(numtext);
//initialize result with 1
result=1;
// run the factorial loop 1*2*3...N
for (int j=2;j<=number1;j++)
result*=j;
//convert result into string
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
//set window text
SetWindowText(textBox1,numtext);
break;
//Power number1 ^ number2
case 104:
//get the number in the textbox
//get handle
textBox1=GetDlgItem(hwndDlg,200);
GetWindowText(textBox1,&numtext[0],10);
number1=atof(numtext);
//define operation
SelOperation=POW;
//delete text box
SetWindowText(textBox1,"");
break;
//cout<<number2+0;
// Perform operation
switch (SelOperation)
{
case SUM:
result=number1+number2;
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
SetWindowText(textBox1,numtext);
break;
case DIV:
result=number1/number2;
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
SetWindowText(textBox1,numtext);
break;
case MUL:
result=number1*number2;
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
SetWindowText(textBox1,numtext);
break;
case POW:
result=pow(number1,number2);
resultstring = to_string(result);
//transform double to char
strcpy( numtext, resultstring.c_str() );
SetWindowText(textBox1,numtext);
break;
}
break;
}
}
return TRUE;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
// function
std::string to_string(double x)
{
std::ostringstream ss;
ss << x;
return ss.str();
}
<<<<----- resource.h ----->>>>>
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define DLG_MAIN 100
<<<<<------- resource.rc ------>>>>>
// Generated by ResEdit 1.6.6
// Copyright (C) 2006-2015
// http://www.resedit.net
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 186, 212
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
EDITTEXT 200, 17, 12, 148, 18, ES_RIGHT | ES_AUTOHSCROLL, WS_EX_LEFT
GROUPBOX "Numbers", 0, 14, 52, 105, 156, 0, WS_EX_LEFT
PUSHBUTTON "1", 1, 22, 136, 25, 20, 0, WS_EX_LEFT
GROUPBOX "OP.", 0, 129, 47, 51, 161, 0, WS_EX_LEFT
PUSHBUTTON "2", 2, 56, 136, 23, 20, 0, WS_EX_LEFT
PUSHBUTTON "3", 3, 87, 136, 24, 22, 0, WS_EX_LEFT
PUSHBUTTON "+", 100, 141, 60, 20, 20, 0, WS_EX_LEFT
PUSHBUTTON "/", 101, 141, 85, 20, 20, 0, WS_EX_LEFT
PUSHBUTTON "X", 102, 141, 110, 20, 20, 0, WS_EX_LEFT
PUSHBUTTON "=", 103, 141, 135, 20, 20, 0, WS_EX_LEFT
PUSHBUTTON "^", 104, 141, 160, 20, 20, 0, WS_EX_LEFT
PUSHBUTTON "!", 105, 141, 185, 20, 20, 0, WS_EX_LEFT
PUSHBUTTON "4", 4, 22, 105, 24, 21, 0, WS_EX_LEFT
PUSHBUTTON "5", 5, 56, 105, 23, 20, 0, WS_EX_LEFT
PUSHBUTTON "6", 6, 87, 105, 22, 19, 0, WS_EX_LEFT
PUSHBUTTON "7", 7, 22, 74, 23, 21, 0, WS_EX_LEFT
PUSHBUTTON "8", 8, 56, 74, 23, 21, 0, WS_EX_LEFT
PUSHBUTTON "9", 9, 87, 74, 22, 20, 0, WS_EX_LEFT
PUSHBUTTON "CE", 12, 23, 171, 24, 20, 0, WS_EX_LEFT
PUSHBUTTON "0", 10, 57, 171, 22, 20, 0, WS_EX_LEFT
PUSHBUTTON ".", 11, 88, 171, 23, 22, 0, WS_EX_LEFT
}
//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 RT_MANIFEST ".\manifest.xml"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.