Advertisement
lofojak

5sPP2Task4

Oct 9th, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | Source Code | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. HWND edt;
  8. string gLogin = "roma";
  9.  
  10. LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
  11. {
  12.     if (message == WM_DESTROY)
  13.         PostQuitMessage(0);
  14.     else if (message == WM_COMMAND)
  15.     {
  16.         if (LOWORD(wparam) == 1) {
  17.             int textLength = GetWindowTextLength(edt);
  18.             string txt(textLength, '\0');
  19.             GetWindowTextA(edt, &txt[0], textLength + 1);
  20.             if (txt.compare(gLogin) == 0)
  21.                 MessageBox(0, L"Yes", L"Your login", MB_OK);
  22.             else
  23.                 MessageBox(0, L"No", L"Your login", MB_OK);
  24.            
  25.         }
  26.     }
  27.     else return DefWindowProcA(hwnd, message, wparam, lparam);
  28. }
  29.  
  30. int main()
  31. {
  32.     WNDCLASSA wcl;
  33.     memset(&wcl, 0, sizeof(WNDCLASSA));
  34.     wcl.lpszClassName = "my_Window";
  35.     wcl.lpfnWndProc = WndProc;
  36.     RegisterClassA(&wcl);
  37.     HWND hwnd = CreateWindow(L"my_Window", L"Окошечко", WS_OVERLAPPEDWINDOW, 10, 10, 640, 480, NULL, NULL, NULL, NULL);
  38.  
  39.     MSG msg;
  40.     ShowWindow(hwnd, SW_SHOWNORMAL);
  41.  
  42.     HWND lbl = CreateWindow(L"static", L"Login: ", WS_VISIBLE | WS_CHILD, 50, 10, 40, 25, hwnd, NULL, NULL, NULL);
  43.     edt = CreateWindow(L"edit", L"YourLogin", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_RIGHT, 100, 10, 100, 20, hwnd, NULL, NULL, NULL);
  44.     HWND btn = CreateWindow(L"button", L"Ok", WS_VISIBLE | WS_CHILD, 210, 10, 50, 20, hwnd, (HMENU)1, NULL, NULL);
  45.  
  46.     while (GetMessage(&msg, NULL, 0, 0))
  47.     {
  48.         TranslateMessage(&msg);
  49.         DispatchMessage(&msg);
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement