Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <windows.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5. HWND hedit, hedit2;
  6. int vl, vl2;
  7.  
  8. LONG WINAPI WndProc(HWND, UINT, WPARAM, LPARAM);
  9.  
  10.  
  11. int WINAPI WinMain(HINSTANCE hInstance,
  12.         HINSTANCE hPrevInstance,
  13.         LPSTR lpCmdLine,
  14.         int nCmdShow)
  15. {
  16.     HWND hwnd;
  17.     MSG msg;
  18.     WNDCLASS w;
  19.         memset(&w, 0, sizeof (WNDCLASS));
  20.         w.style = CS_HREDRAW | CS_VREDRAW;
  21.         w.lpfnWndProc = WndProc;
  22.         w.hInstance = hInstance;
  23.         w.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  24.         w.lpszClassName = "My Class";
  25.     RegisterClass(&w);
  26.     hwnd = CreateWindow("My Class", "primer",
  27.             WS_OVERLAPPEDWINDOW,
  28.             500, 300, 500, 380, NULL, NULL, hInstance, NULL);
  29.  
  30.     hedit = CreateWindow("edit", "0", WS_CHILD | WS_VISIBLE | ES_LEFT,
  31.             10, 10, 80, 30, hwnd, (HMENU) 10000, hInstance, NULL);
  32.  
  33.     hedit2 = CreateWindow("edit", "0", WS_CHILD | WS_VISIBLE | ES_LEFT,
  34.             150, 10, 80, 30, hwnd, (HMENU) 10001, hInstance, NULL);
  35.  
  36.     CreateWindow("button", "+", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
  37.                   10, 100, 40, 20, hwnd, (HMENU) 1000, hInstance, NULL);
  38.    
  39.     ShowWindow(hwnd, nCmdShow);
  40.     UpdateWindow(hwnd);
  41.     while (GetMessage(&msg, NULL, 0, 0))
  42.     {
  43.         TranslateMessage(&msg);
  44.         DispatchMessage(&msg);
  45.     }
  46.     return msg.wParam;
  47. }
  48.  
  49. LONG WINAPI WndProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam) {
  50.     TCHAR val[33] = {0};
  51.     switch (Message)
  52.     {
  53.             case WM_DESTROY: PostQuitMessage(0);
  54.             break;  
  55.         case WM_COMMAND:
  56.         {
  57.             switch (LOWORD(wparam))
  58.             {
  59.                     case 1000:
  60.                 {
  61.                     GetWindowText(hedit, val, 33);
  62.                     vl = atoi(val);
  63.                     GetWindowText(hedit2, val, 33);
  64.                     vl2 = atoi(val);
  65.                     int res = vl + vl2;
  66.                     itoa(res, val, 10);
  67.                     MessageBox(hwnd, LPSTR(resCHR), "Результат", MB_OK);
  68.                 }
  69.             }
  70.         };
  71.         default: return DefWindowProc(hwnd, Message, wparam, lparam);
  72.     }
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement