Code:
#include <windows.h>
static char gszClassName[] = "MyWindowClass";
static HINSTANCE ghInstance = NULL;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HWND hBorder,hBox1,hPlus,hBox2,hEqual,hBox3;
char str1[10];
char str2[10];
char str3[10];
int x1,x2;
switch(Message)
{
case WM_CREATE:
{
hBorder = CreateWindowEx
(
NULL,
"Static",
"",
WS_CHILD | WS_VISIBLE | WS_BORDER,
4, 2,
196, 46,
hwnd, NULL,
ghInstance,
NULL
);
hBox1 = CreateWindowEx
(
WS_EX_RIGHT | WS_EX_CLIENTEDGE,
"Edit",
"",
WS_CHILD | WS_VISIBLE,
10, 12,
30, 25,
hwnd, NULL,
ghInstance,
NULL
);
hPlus = CreateWindowEx
(
NULL,
TEXT("Static"),
TEXT("+"),
WS_CHILD | WS_VISIBLE | SS_SIMPLE,
50, 16,
10, 15,
hwnd, NULL,
ghInstance,
NULL
);
hBox2 = CreateWindowEx
(
WS_EX_RIGHT | WS_EX_CLIENTEDGE,
"Edit",
"",
WS_CHILD | WS_VISIBLE,
70, 12,
30, 25,
hwnd, NULL,
ghInstance,
NULL
);
hEqual = CreateWindowEx
(
WS_EX_CLIENTEDGE,
"Button",
"=",
WS_CHILD | WS_VISIBLE,
110, 16,
30, 18,
hwnd, NULL,
ghInstance,
NULL
);
hBox3 = CreateWindowEx
(
WS_EX_RIGHT | WS_EX_CLIENTEDGE,
"Edit",
"",
WS_CHILD | WS_VISIBLE,
148, 12,
45, 25,
hwnd, NULL,
ghInstance,
NULL
);
}
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case hEqual:
{
GetWindowText(hBox1,str1,10);
GetWindowText(hBox2,str2,10);
x1 = atoi(str1);
x2 = atoi(str2);
if (x1)
SetWindowText(hBox3,itoa(x1+x2,str3,10));
else
MessageBox(hwnd,"Error",NULL,NULL);
}
break;
}
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndC;
HWND hwnd;
MSG Msg;
ghInstance = hInstance;
WndC.cbSize = sizeof(WNDCLASSEX);
WndC.style = NULL;
WndC.lpfnWndProc = WndProc;
WndC.cbClsExtra = 0;
WndC.cbWndExtra = 0;
WndC.hInstance = ghInstance;
WndC.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndC.hCursor = LoadCursor(NULL, IDC_ARROW);
WndC.hbrBackground = (HBRUSH)(COLOR_WINDOW+0);
WndC.lpszMenuName = NULL;
WndC.lpszClassName = gszClassName;
WndC.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndC))
{
MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONSTOP | MB_OK);
return 0;
}
hwnd = CreateWindowEx
(
WS_EX_STATICEDGE,
gszClassName,
"math_test",
WS_SYSMENU | WS_MINIMIZEBOX, //WS_OVERLAPPEDWINDOW
CW_USEDEFAULT, CW_USEDEFAULT,
210, 75,
NULL, NULL,
ghInstance,
NULL
);
if(hwnd == NULL)
{
MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONSTOP | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Is there something wrong with the bold faced part of the code, WM_COMMAND? Cause nothing happens when i click the equal button.