Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.52 KB | None | 0 0
  1. #include <windows.h>
  2. #include <time.h>
  3.  //V-6
  4. LPCSTR registration_error_message = "Couldn't initialize class!";
  5. LPCSTR registration_error_title = "Error: initializing";
  6. LPCSTR creating_window_error_title = "Error: creating";
  7.  LPCSTR creating_window_error_message = "Couldn't create window!";
  8. LPCSTR button_show_text = "Show";
  9. LPCSTR button_clear_text = "Clear";
  10. LPCSTR button_about_text = "About";
  11. LPCSTR main_window_name = "Hello App";
  12. LPCSTR main_window_class = "hello_class";
  13. LPCSTR about_text = "Sergey Rakhmanov (IU3-21B)";
  14. LRESULT CALLBACK window_callback(HWND, UINT, WPARAM, LPARAM);
  15. HINSTANCE hInst;
  16. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
  17. HWND main_window;
  18.  MSG msg;
  19. WNDCLASSEX wc;
  20. wc.cbSize = sizeof(wc);
  21.  wc.style = CS_HREDRAW | CS_VREDRAW;
  22. wc.lpfnWndProc = window_callback;
  23. wc.lpszMenuName = NULL;
  24.  wc.lpszClassName = main_window_class;
  25.  wc.cbWndExtra = 0;
  26. wc.cbClsExtra = 0;
  27. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  28. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  29.  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  30. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  31.  wc.hInstance = hInstance;
  32. if(!RegisterClassEx(&wc)){
  33.  MessageBox(NULL, registration_error_message, registration_error_title, MB_OK);
  34. return NULL;
  35. }
  36. main_window = CreateWindow(main_window_class, main_window_name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
  37.  
  38. if(!main_window){MessageBox(NULL, creating_window_error_message, creating_window_error_title, MB_OK); return NULL; }
  39. ShowWindow(main_window, iCmdShow);
  40.  UpdateWindow(main_window);
  41. while(GetMessage(&msg, NULL, 0, 0)){ TranslateMessage(&msg); DispatchMessage(&msg); }
  42. return msg.wParam ;
  43.  }
  44.  
  45. #define BTN_WIDTH 150
  46. #define BTN_HEIGHT 20
  47.  LRESULT CALLBACK window_callback(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
  48.  HDC hdc;
  49.  PAINTSTRUCT ps;
  50.  RECT rect;
  51. HWND button_show, button_clear, button_author;
  52.  int loword;
  53. static int choise = 0;
  54. static HPEN hpen;
  55. static HBRUSH hbrush;
  56. switch (iMsg) {
  57. case WM_CREATE :
  58. button_show = CreateWindow ("button", button_show_text, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 50, BTN_WIDTH, BTN_HEIGHT, hwnd, (HMENU) 1, hInst, NULL);
  59. button_clear = CreateWindow ("button", button_clear_text, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 100, BTN_WIDTH, BTN_HEIGHT, hwnd, (HMENU) 2, hInst, NULL);
  60.  button_author = CreateWindow ("button", button_about_text, WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON, 100, 250, BTN_WIDTH, BTN_HEIGHT, hwnd, (HMENU) 3, hInst, NULL);
  61. return 0;
  62.  
  63. case WM_COMMAND :
  64. hpen = CreatePen(PS_SOLID, 10,RGB(204, 51, 0));
  65. hbrush = CreateSolidBrush(RGB(204, 51, 0));
  66. loword=LOWORD(wParam);
  67.  
  68. switch(loword){
  69. case 1: choise = 1; break; case 2: choise = 2; break; case 3: choise = 3; break; default: break; }
  70.  
  71. InvalidateRect(hwnd, NULL, TRUE);
  72. return 0;
  73.  case WM_PAINT:
  74. hdc = BeginPaint(hwnd, &ps);
  75. GetClientRect(hwnd, &rect);
  76. SelectObject(hdc, hbrush);
  77. SelectObject(hdc, hpen);
  78.  switch(choise){
  79. case 1:
  80.  Rectangle(hdc, 600, 100, 624, 300);
  81.  hbrush = CreateSolidBrush(RGB(0, 255, 0));
  82.  hpen = CreatePen(PS_SOLID, 10,RGB(0, 255, 0));
  83.  SelectObject(hdc, hbrush);
  84. SelectObject(hdc, hpen);
  85. Ellipse(hdc, 525, 50, 698, 200);
  86. break;
  87. case 2:
  88. break; case 3:
  89.  TextOut(hdc, 500, 100, about_text, strlen(about_text));
  90.  break; }
  91. EndPaint(hwnd, &ps); return 0; case WM_DESTROY : PostQuitMessage(0); return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement