1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
#include "windows.h"
enum { ID_LABEL = 1,ID_IMAGE,ID_EDIT,ID_LIST,ID_BUTTON1,ID_COMBO,ID_BUTTON2,ID_BUTTON0,
ID_BUTTON3,ID_BUTTON4,ID_BUTTON5,ID_BUTTON6,ID_BUTTON7,ID_BUTTON8,ID_BUTTON9,
ID_BUTTONPLUS, ID_BUTTONMINUS, ID_BUTTONTIME, ID_BUTTONDIVIDE, ID_BUTTONEQUAL};
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
HINSTANCE g_hInst;
TCHAR szAppName[] = TEXT("Calculator");
TCHAR szWinClass[] = TEXT("WIN_CLASS");
HWND static_label;
HWND edit;
HWND list;
//number
HWND button0;
HWND button1;
HWND button2;
HWND button3;
HWND button4;
HWND button5;
HWND button6;
HWND button7;
HWND button8;
HWND button9;
//operation
HWND buttonPlus;
HWND buttonMinus;
HWND buttonTime;
HWND buttonDivide;
HWND buttonEqual;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR lpCmdLine,
int nCmdShow){
MSG msg;
WNDCLASS wc;
HWND hwnd;
g_hInst = hInstance;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WinProc;
wc.lpszClassName = szWinClass;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if( !RegisterClass(&wc))
{
MessageBox(NULL, TEXT("Error registering class"), TEXT("ERROR"), MB_OK);
return 0;
}
hwnd = CreateWindow(szWinClass,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
400,
(HWND) NULL,
(HMENU) NULL,
(HINSTANCE) hInstance,
(void *) NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, (HWND) NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
PAINTSTRUCT ps;
HDC hdc;
switch(msg){
case WM_CREATE:
static_label = CreateWindow("Static","Please Enter A Number",WS_CHILD | WS_VISIBLE,35,15,175,25,hwnd,0,g_hInst,0);
edit = CreateWindow("Edit", NULL,WS_BORDER | NULL | WS_CHILD | WS_VISIBLE | NULL | NULL ,35,45,175,20,hwnd,(HMENU)ID_EDIT,g_hInst,0);
button0 = CreateWindow("Button","0",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,80,220,35,35,hwnd,(HMENU)ID_BUTTON0,g_hInst,0);
button1 = CreateWindow("Button","1",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,35,170,35,35,hwnd,(HMENU)ID_BUTTON1,g_hInst,0);
button2 = CreateWindow("Button","2",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,80,170,35,35,hwnd,(HMENU)ID_BUTTON2,g_hInst,0);
button3 = CreateWindow("Button","3",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,125,170,35,35,hwnd,(HMENU)ID_BUTTON3,g_hInst,0);
button4 = CreateWindow("Button","4",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,35,120,35,35,hwnd,(HMENU)ID_BUTTON4,g_hInst,0);
button5 = CreateWindow("Button","5",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,80,120,35,35,hwnd,(HMENU)ID_BUTTON5,g_hInst,0);
button6 = CreateWindow("Button","6",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,125,120,35,35,hwnd,(HMENU)ID_BUTTON6,g_hInst,0);
button7 = CreateWindow("Button","7",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,35,70,35,35,hwnd,(HMENU)ID_BUTTON7,g_hInst,0);
button8 = CreateWindow("Button","8",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,80,70,35,35,hwnd,(HMENU)ID_BUTTON8,g_hInst,0);
button9 = CreateWindow("Button","9",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,125,70,35,35,hwnd,(HMENU)ID_BUTTON9,g_hInst,0);
buttonDivide = CreateWindow("Button","/",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,170,70,35,35,hwnd,(HMENU)ID_BUTTONDIVIDE,g_hInst,0);
buttonTime = CreateWindow("Button","*",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,170,120,35,35,hwnd,(HMENU)ID_BUTTONTIME,g_hInst,0);
buttonMinus = CreateWindow("Button","-",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,170,170,35,35,hwnd,(HMENU)ID_BUTTONMINUS,g_hInst,0);
buttonPlus = CreateWindow("Button","+",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,170,220,35,35,hwnd,(HMENU)ID_BUTTONPLUS,g_hInst,0);
buttonEqual = CreateWindow("Button","=",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,125,220,35,35,hwnd,(HMENU)ID_BUTTONEQUAL,g_hInst,0);
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
case WM_COMMAND: //Command from Child windows and menus are under this message
switch(wParam) //the ID is wParam
{
case ID_BUTTON0: //check for our button ID
{
// Static labels dont do messages
//we can set the text directly though
SetWindowText(edit,"0");
//SetWindowText(edit,"0");
break;
}
case ID_BUTTON1:
{
SetWindowText(edit,"1");
break;
}
case ID_BUTTON2:
{
SetWindowText(edit,"2");
break;
}
case ID_BUTTON3:
{
SetWindowText(edit,"3");
break;
}
case ID_BUTTON4:
{
SetWindowText(edit,"4");
break;
}
case ID_BUTTON5:
{
SetWindowText(edit,"5");
break;
}
case ID_BUTTON6:
{
SetWindowText(edit,"6");
break;
}
case ID_BUTTON7:
{
SetWindowText(edit,"7");
break;
}
case ID_BUTTON8:
{
SetWindowText(edit,"8");
break;
}
case ID_BUTTON9:
{
SetWindowText(edit,"9");
break;
}
case ID_BUTTONPLUS:
{
SetWindowText(edit,"+");
break;
}
case ID_BUTTONMINUS:
{
SetWindowText(edit,"-");
break;
}
case ID_BUTTONTIME:
{
SetWindowText(edit,"*");
break;
}
case ID_BUTTONDIVIDE:
{
SetWindowText(edit,"/");
break;
}
case ID_BUTTONEQUAL:
{
SetWindowText(edit,"=");
break;
}
}//switch.
break;
case WM_DESTROY:
PostQuitMessage(0);
break; // pass to DefWindowProc(...) as well
case WM_CLOSE:
DestroyWindow(hwnd);
break;
}return DefWindowProc(hwnd, msg, wParam, lParam);}
|