Advertisement
rhouland

C++ button Edit Label

May 14th, 2018
1,545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <Windows.h>
  5. #include <cstdio>
  6. #include <string>
  7. #include <cstring>
  8. #include <tchar.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11.  
  12. // Copyright: rhouland@epastas.lt  &  evgeniistorozhev@mail.ru
  13.  
  14. LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
  15.    
  16.     static HWND HWNDStatic; // Label OutPut
  17.     static HWND HWNDButton;
  18.     static HWND HWNDButton2;
  19.     static HWND HWNDButton3;
  20.     static HWND HWNDEdit1;
  21.     static HWND HWNDEdit2;
  22.    
  23.     switch(Message) {
  24.        
  25.         case WM_DESTROY: {
  26.             PostQuitMessage(0);
  27.             break; 
  28.         }
  29.        
  30.         case WM_CREATE: {
  31.                
  32.         CreateWindow(TEXT("STATIC"),TEXT(" Enter Digit A : "),
  33.         WS_VISIBLE | WS_CHILD | SS_CENTER | SS_CENTERIMAGE,
  34.         110,30,170,32,hwnd,(HMENU)1,NULL,NULL );
  35.        
  36.         HWNDEdit1 = CreateWindow(TEXT("edit"),TEXT(""),
  37.         WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
  38.         310,35,170,20,hwnd,(HMENU)2,NULL,NULL);
  39.        
  40.         CreateWindow(TEXT("STATIC"),TEXT(" Enter Digit B : "),
  41.         WS_VISIBLE | WS_CHILD | SS_CENTER | SS_CENTERIMAGE,
  42.         110,70,170,32,hwnd,(HMENU)3,NULL,NULL );
  43.        
  44.         HWNDEdit2 = CreateWindow(TEXT("edit"),TEXT(""),
  45.         WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
  46.         310,75,170,20,hwnd,(HMENU)4,NULL,NULL);
  47.        
  48.         HWNDButton = CreateWindow(TEXT("button"),TEXT(" Call A + B "),
  49.         WS_VISIBLE | WS_CHILD,
  50.         80,120,130,35,hwnd,(HMENU) 5,NULL,NULL );  
  51.        
  52.         HWNDButton2 = CreateWindow(TEXT("button"),TEXT(" Call A * B "),
  53.         WS_VISIBLE | WS_CHILD,
  54.         240,120,130,35,hwnd,(HMENU) 8,NULL,NULL ); 
  55.        
  56.         HWNDButton3 = CreateWindow(TEXT("button"),TEXT(" Call A / B "),
  57.         WS_VISIBLE | WS_CHILD,
  58.         390,120,130,35,hwnd,(HMENU) 9,NULL,NULL );     
  59.                    
  60.         HWNDStatic = CreateWindow(TEXT("STATIC"),TEXT(" .... "),
  61.         WS_VISIBLE | WS_CHILD | SS_CENTER | SS_CENTERIMAGE,
  62.         250,200,90,22,hwnd,(HMENU)6,NULL,NULL);
  63.            
  64.         CreateWindow(TEXT("button"), TEXT("Exit!"),
  65.         WS_VISIBLE | WS_CHILD | SS_CENTER,
  66.         250,300,90,35,hwnd, (HMENU) 7, NULL, NULL);
  67.        
  68.         CreateWindow(TEXT("button"), TEXT("Clear All!"),
  69.         WS_VISIBLE | WS_CHILD | SS_CENTER,
  70.         220,240,160,35,hwnd, (HMENU) 10, NULL, NULL);
  71.        
  72.         case WM_COMMAND: // Dead programm!
  73.         if (LOWORD(wParam) == 7)
  74.         {
  75.         PostQuitMessage(0);
  76.         }
  77.        
  78.         if (LOWORD(wParam) == 5) // Call A + B
  79.         {
  80.        
  81.         char hhh[400];
  82.         int vt=16;
  83.         GetWindowText( HWNDEdit1, hhh, vt );
  84.         double aaa = atof(hhh);
  85.        
  86.         char yyy[400];
  87.         int vtf=16;
  88.         GetWindowText( HWNDEdit2, yyy, vtf );
  89.         double bbb = atof(yyy);
  90.        
  91.         double fn1=aaa, fn2=bbb, fn3=fn1+fn2;
  92.         std::ostringstream ss;
  93.         ss << fn3;
  94.         SetWindowText(HWNDStatic, ss.str().c_str());
  95.         SetWindowText(HWNDButton, "Result A + B ");
  96.         SetWindowText(HWNDButton2, "Call A * B ");
  97.         SetWindowText(HWNDButton3, "Call A / B ");
  98.         }
  99.        
  100.         if (LOWORD(wParam) == 8) // Call A * B
  101.         {
  102.        
  103.         char hhh[400];
  104.         int vt=16;
  105.         GetWindowText( HWNDEdit1, hhh, vt );
  106.         double aaa = atof(hhh);
  107.        
  108.         char yyy[400];
  109.         int vtf=16;
  110.         GetWindowText( HWNDEdit2, yyy, vtf );
  111.         double bbb = atof(yyy);
  112.            
  113.         double fn1=aaa, fn2=bbb, fn3=fn1*fn2;
  114.         std::ostringstream ss;
  115.         ss << fn3;
  116.         SetWindowText(HWNDStatic, ss.str().c_str());
  117.         SetWindowText(HWNDButton2, "Result A * B ");
  118.         SetWindowText(HWNDButton, "Call A + B ");
  119.         SetWindowText(HWNDButton3, "Call A / B ");
  120.         }        
  121.  
  122.         if (LOWORD(wParam) == 9) // Call A / B
  123.         {
  124.        
  125.         char hhh[400];
  126.         int vt=16;
  127.         GetWindowText( HWNDEdit1, hhh, vt );
  128.         double aaa = atof(hhh);
  129.        
  130.         char yyy[400];
  131.         int vtf=16;
  132.         GetWindowText( HWNDEdit2, yyy, vtf );
  133.         double bbb = atof(yyy);
  134.            
  135.         double fn1=aaa, fn2=bbb, fn3=fn1/fn2;
  136.         std::ostringstream ss;
  137.         ss << fn3;
  138.         SetWindowText(HWNDStatic, ss.str().c_str());
  139.         SetWindowText(HWNDButton3, "Result A / B ");
  140.         SetWindowText(HWNDButton, "Call A + B ");
  141.         SetWindowText(HWNDButton2, "Call A * B ");
  142.         }
  143.  
  144.         if (LOWORD(wParam) == 10) // Clear all
  145.         {    
  146.         SetWindowText(HWNDStatic, " .... ");
  147.         SetWindowText(HWNDButton3, "Call A / B ");
  148.         SetWindowText(HWNDButton, "Call A + B ");
  149.         SetWindowText(HWNDButton2, "Call A * B ");
  150.         SetWindowText(HWNDEdit1, "");
  151.         SetWindowText(HWNDEdit2, "");
  152.         }
  153.            
  154.         }
  155.         default:
  156.         return DefWindowProc(hwnd, Message, wParam, lParam);
  157.     }
  158.    
  159.     return 0;
  160. }
  161.  
  162. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  163.     setlocale(LC_ALL, "Lithuanian");
  164.     WNDCLASSEX wc;
  165.     HWND hwnd;
  166.     MSG msg;
  167.    
  168.     memset(&wc,0,sizeof(wc));
  169.     wc.cbSize        = sizeof(WNDCLASSEX);
  170.     wc.lpfnWndProc   = WndProc;
  171.     wc.hInstance     = hInstance;
  172.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  173.    
  174.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  175.     wc.lpszClassName = "WindowClass";
  176.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  177.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  178.  
  179.     if(!RegisterClassEx(&wc)) {
  180.         MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  181.         return 0;
  182.     }
  183.  
  184.     hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Butt-Lbl-Out",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
  185.         CW_USEDEFAULT,
  186.         CW_USEDEFAULT,
  187.         640,480,NULL,NULL,hInstance,NULL);
  188.  
  189.     if(hwnd == NULL) {
  190.         MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  191.         return 0;
  192.     }
  193.  
  194.     while(GetMessage(&msg, NULL, 0, 0) > 0) {
  195.         TranslateMessage(&msg);
  196.         DispatchMessage(&msg);
  197.     }
  198.     return msg.wParam;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement