Advertisement
rhouland

C++ button Edit Label

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