Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <stdio.h>
- #include <cstdio>
- #include <tchar.h>
- #include <time.h>
- enum Operation { None, Add, Sub, Mul, Div }Op;
- HWND EraseAll, EraseLast;
- HWND Numbers[10], AddBtn, SubBtn, Equal, OutputField;
- HWND hwnd;
- double Result;
- char buff[255];
- bool A = false;
- void a() {
- int PositionX = 50, PositionY = 100;
- for (int i = 1; i < 10; i++) {
- MoveWindow(Numbers[i], PositionX+(rand()%200)+1, PositionY + (rand() % 200) + 1, 50 + (rand() % 200) + 1, 50 + (rand() % 200) + 1, 1);
- if (PositionX == 150) {
- PositionX = 50;
- PositionY += 50;
- }
- else {
- PositionX += 50;
- }
- }
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- switch (msg) {
- case WM_TIMER:
- if (A)a();
- break;
- case WM_KEYDOWN:
- switch ((int)wParam) {
- case VK_RETURN:
- {
- if (!A) {
- SetTimer(hwnd, 100, 20, NULL);
- A = true;
- }
- else {
- KillTimer(hwnd, 100);
- A = false;
- }
- }
- break;
- }
- break;
- case WM_COMMAND: {
- if ((HWND)lParam == EraseAll) {
- SetWindowText(OutputField, "");
- }
- if ((HWND)lParam == EraseLast) {
- GetWindowText(OutputField, buff, 255);
- int i = strlen(buff);
- if (i > 0)
- buff[i - 1] = '\0';
- SetWindowText(OutputField, buff);
- }
- if ((HWND)lParam == Equal) {
- GetWindowText(OutputField, buff, 255);
- int Num = atof(buff);
- switch (Op) {
- case Add:
- Result += Num;
- break;
- case Sub:
- Result -= Num;
- break;
- case Mul:
- Result *= Num;
- break;
- case Div:
- Result /= Num;
- break;
- }
- sprintf_s(buff, "%.0f", Result);
- SetWindowText(OutputField, buff);
- Result = 0.0;
- Op = None;
- }
- if ((HWND)lParam == AddBtn) {
- GetWindowText(OutputField, buff, 255);
- Result = atof(buff);
- SetWindowText(OutputField, "");
- Op = Add;
- }
- if ((HWND)lParam == SubBtn) {
- GetWindowText(OutputField, buff, 255);
- Result = atof(buff);
- SetWindowText(OutputField, "");
- Op = Sub;
- }
- for (int i = 0; i < 10; i++) {
- if ((HWND)lParam == Numbers[i]) {
- GetWindowText(OutputField, buff, 255);
- if (strlen(buff) <= 16) {
- double Num = (atof(buff) * 10) + i;
- sprintf_s(buff, "%.0f", Num);
- SetWindowText(OutputField, buff);
- }
- }
- }
- }break;
- case WM_CLOSE:DestroyWindow(hwnd); break;
- case WM_DESTROY:PostQuitMessage(0); break;
- default:return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
- srand(time(NULL));
- WNDCLASSEX window;
- MSG msg;
- TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
- window.cbClsExtra = NULL;
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(NULL, IDC_ARROW);
- window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- window.hInstance = hInstance;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = CS_VREDRAW | CS_HREDRAW;
- RegisterClassEx(&window);
- hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 300, 400, NULL, NULL, hInstance, NULL);
- int PositionX = 50, PositionY = 100;
- for (int i = 1; i < 10; i++) {
- char buff[255];
- sprintf_s(buff, "%d", i);
- Numbers[i] = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", buff, WS_CHILD | WS_VISIBLE, PositionX, PositionY, 50, 50, hwnd, NULL, hInstance, NULL);
- if (PositionX == 150) {
- PositionX = 50;
- PositionY += 50;
- }
- else {
- PositionX += 50;
- }
- }
- Numbers[0] = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "0", WS_CHILD | WS_VISIBLE, PositionX, PositionY, 100, 50, hwnd, NULL, hInstance, NULL);
- AddBtn = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "+", WS_CHILD | WS_VISIBLE, 200, 100, 50, 50, hwnd, NULL, hInstance, NULL);
- SubBtn = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "-", WS_CHILD | WS_VISIBLE, 200, 150, 50, 50, hwnd, NULL, hInstance, NULL);
- Equal = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "=", WS_CHILD | WS_VISIBLE, 200, 200, 50, 100, hwnd, NULL, hInstance, NULL);
- OutputField = CreateWindowEx(WS_EX_WINDOWEDGE, "STATIC", NULL, WS_CHILD | WS_VISIBLE, 50, 20, 200, 50, hwnd, NULL, hInstance, NULL);
- EraseAll = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "C", WS_CHILD | WS_VISIBLE, 200, 70, 50, 30, hwnd, NULL, hInstance, NULL);
- EraseLast = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "<-", WS_CHILD | WS_VISIBLE, 150, 70, 50, 30, hwnd, NULL, hInstance, NULL);
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- UnregisterClass(Class_Name, hInstance);
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement