Advertisement
seba101

(WINAPI) Zamiana liter

Dec 19th, 2017
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <math.h>
  3. #include <list>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. LPCSTR NazwaKlasy = TEXT("Klasa Okienka");
  9. MSG Komunikat;
  10. HDC hdc;
  11. HWND hwnd;
  12. RECT Rect;
  13. HWND hTextWpisz, hButtonZmien, hTextCo, hTextNaCo, hTextWyswietl;
  14. SYSTEMTIME czasAktualny, czasStartu;
  15. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  16.  
  17. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  18. {
  19.     WNDCLASSEX wc;
  20.     wc.cbSize = sizeof(WNDCLASSEX);
  21.     wc.style = CS_HREDRAW | CS_VREDRAW;
  22.     wc.lpfnWndProc = WndProc;
  23.     wc.cbClsExtra = 0;
  24.     wc.cbWndExtra = 0;
  25.     wc.hInstance = hInstance;
  26.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  27.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  28.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  29.     wc.lpszMenuName = NULL;
  30.     wc.lpszClassName = NazwaKlasy;
  31.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  32.  
  33.     if (!RegisterClassEx(&wc))
  34.     {
  35.         MessageBox(NULL, TEXT("Nie mozna utworzyc okna"), TEXT("Niestety..."),
  36.             MB_ICONEXCLAMATION | MB_OK);
  37.         return 1;
  38.     }
  39.  
  40.     hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, NazwaKlasy, TEXT("Oto okienko"), WS_OVERLAPPEDWINDOW,
  41.         CW_USEDEFAULT, CW_USEDEFAULT, 800, 400, NULL, NULL, hInstance, NULL);
  42.  
  43.     hTextWpisz = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
  44.         hwnd, NULL, hInstance, NULL);
  45.     hTextCo= CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
  46.         hwnd, NULL, hInstance, NULL);
  47.     hTextNaCo = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
  48.         hwnd, NULL, hInstance, NULL);
  49.     hTextWyswietl = CreateWindowEx(0, "Static", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
  50.         hwnd, NULL, hInstance, NULL);
  51.     hButtonZmien = CreateWindowEx(0, "BUTTON", "Zmien", WS_CHILD | WS_VISIBLE,
  52.         0, 0, 150, 30, hwnd, NULL, hInstance, NULL);
  53.  
  54.  
  55.     if (hwnd == NULL)
  56.     {
  57.         MessageBox(NULL, TEXT("Okno odmówiło przyjścia na świat!"), TEXT("Ale kicha..."), MB_ICONEXCLAMATION);
  58.         return 1;
  59.     }
  60.  
  61.     ShowWindow(hwnd, nCmdShow);
  62.     UpdateWindow(hwnd);
  63.  
  64.     while (GetMessage(&Komunikat, NULL, 0, 0))
  65.     {
  66.         TranslateMessage(&Komunikat);
  67.         DispatchMessage(&Komunikat);
  68.     }
  69.     return Komunikat.wParam;
  70. }
  71. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  72. {
  73.     char text[250];
  74.     char co[2];
  75.     char naco[2];
  76.  
  77.  
  78.     switch (msg)
  79.     {
  80.     case WM_COMMAND:
  81.         if ((HWND)lParam == hButtonZmien)
  82.         {
  83.             GetWindowText(hTextWpisz, text, 250);
  84.             GetWindowText(hTextCo, co, 2);
  85.             GetWindowText(hTextNaCo, naco, 2);
  86.             for (int i = 0; i < 250; i++)
  87.             {
  88.                 if (text[i] == co[0])
  89.                 {
  90.                     text[i] = naco[0];
  91.                 }
  92.             }
  93.  
  94.             SetWindowText(hTextWyswietl, text);
  95.         }
  96.         break;
  97.     case WM_CREATE:
  98.         break;
  99.     case WM_CLOSE:
  100.         DestroyWindow(hwnd);
  101.         break;
  102.     case WM_DESTROY:
  103.         PostQuitMessage(0);
  104.         break;
  105.  
  106.     case WM_SIZE:
  107.         GetClientRect(hwnd, &Rect);
  108.         MoveWindow(hTextWpisz, Rect.right / 2 - 75, Rect.bottom / 2 - 100, 150, 50, TRUE);
  109.         MoveWindow(hTextCo, Rect.right / 2 - 25, Rect.bottom / 2 - 40, 25, 25, TRUE);
  110.         MoveWindow(hTextNaCo, Rect.right / 2, Rect.bottom / 2 - 40, 25, 25, TRUE);
  111.         MoveWindow(hButtonZmien, Rect.right / 2 - 25, Rect.bottom / 2 , 50, 25, TRUE);
  112.         MoveWindow(hTextWyswietl, Rect.right / 2 -75, Rect.bottom / 2 + 30 , 150, 50, TRUE);
  113.  
  114.         break;
  115.     default:
  116.         return DefWindowProc(hwnd, msg, wParam, lParam);
  117.     }
  118.  
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement