Guest User

Untitled

a guest
Dec 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.12 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "OS_1.h"
  3.  
  4. #define MAX_LOADSTRING 100
  5.  
  6. HINSTANCE hInst;                   
  7. TCHAR szMainTitle[]=_T("Лабораторная работа №1 по ОС студ. Беляева М.О. группа ИУС-10б");                   
  8. TCHAR szWindowClass[MAX_LOADSTRING];           
  9. ATOM                MainClass(HINSTANCE hInstance);
  10. ATOM                ChildClass(HINSTANCE hInstance);
  11. BOOL                InitInstance(HINSTANCE, int);
  12. LRESULT CALLBACK    MainWndProc(HWND, UINT, WPARAM, LPARAM);
  13. LRESULT CALLBACK    ChildWndProc(HWND, UINT, WPARAM, LPARAM);
  14. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  15.  
  16. int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
  17.                      _In_opt_ HINSTANCE hPrevInstance,
  18.                      _In_ LPTSTR    lpCmdLine,
  19.                      _In_ int       nCmdShow)
  20. {
  21.     UNREFERENCED_PARAMETER(hPrevInstance);
  22.     UNREFERENCED_PARAMETER(lpCmdLine);
  23.     MSG msg;
  24.     HACCEL hAccelTable;
  25.     LoadString(hInstance, IDC_OS_1, szWindowClass, MAX_LOADSTRING);
  26.     MainClass(hInstance);
  27.     ChildClass(hInstance);
  28.     if (!InitInstance (hInstance, nCmdShow))
  29.     {
  30.         return FALSE;
  31.     }
  32.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_OS_1));
  33.     while (GetMessage(&msg, NULL, 0, 0))
  34.     {
  35.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  36.         {
  37.             TranslateMessage(&msg);
  38.             DispatchMessage(&msg);
  39.         }
  40.     }
  41.     return (int) msg.wParam;
  42. }
  43.  
  44. ATOM MainClass(HINSTANCE hInstance)
  45. {
  46.     WNDCLASSEX wcex;
  47.     wcex.cbSize = sizeof(WNDCLASSEX);
  48.     wcex.style          = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  49.     wcex.lpfnWndProc    = MainWndProc;
  50.     wcex.cbClsExtra     = 0;
  51.     wcex.cbWndExtra     = 0;
  52.     wcex.hInstance      = hInstance;
  53.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_OS_1));
  54.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  55.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  56.     wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_OS_1);
  57.     wcex.lpszClassName  = szWindowClass;
  58.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  59.     return RegisterClassEx(&wcex);
  60. }
  61.  
  62. ATOM ChildClass(HINSTANCE hInstance)
  63. {
  64.     WNDCLASSEX wcex;
  65.     wcex.cbSize = sizeof(WNDCLASSEX);
  66.     wcex.style          = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
  67.     wcex.lpfnWndProc    = ChildWndProc;
  68.     wcex.cbClsExtra     = 0;
  69.     wcex.cbWndExtra     = 0;
  70.     wcex.hInstance      = hInstance;
  71.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_OS_1));
  72.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  73.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  74.     wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_OS_1);
  75.     wcex.lpszClassName  = szWindowClass;
  76.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  77.     return RegisterClassEx(&wcex);
  78. }
  79.  
  80. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  81. {
  82.    HWND hWndMain, hWndChild;
  83.    hInst = hInstance;
  84.    hWndMain = CreateWindow(szWindowClass, szMainTitle, WS_EX_APPWINDOW | WS_OVERLAPPEDWINDOW,
  85.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  86.    hWndChild = CreateWindow(szWindowClass,_T("DERP"), WS_CHILD | WS_OVERLAPPEDWINDOW,
  87.        0, 0, GetSystemMetrics(SM_CXFULLSCREEN)/5, GetSystemMetrics(SM_CYFULLSCREEN)/5, hWndMain, NULL, hInstance, NULL);
  88.    if (!hWndMain&&!hWndChild)
  89.    {
  90.       return FALSE;
  91.    }
  92.    ShowWindow(hWndMain, SW_MAXIMIZE);
  93.    ShowWindow(hWndChild, SW_NORMAL);
  94.    UpdateWindow(hWndMain);
  95.    UpdateWindow(hWndChild);
  96.    return TRUE;
  97. }
  98.  
  99. LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  100. {
  101.     int wmId, wmEvent;
  102.     TCHAR lpString[] = _T("События данного окна обрабатыватся функцией LRESULT CALLBACK MainWndProc()");
  103.     switch (message)
  104.     {
  105.     case WM_COMMAND:
  106.         wmId    = LOWORD(wParam);
  107.         wmEvent = HIWORD(wParam);
  108.         switch (wmId)
  109.         {
  110.         case IDM_ABOUT:
  111.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  112.             break;
  113.         case IDM_EXIT:
  114.             DestroyWindow(hWnd);
  115.             break;
  116.         default:
  117.             return DefWindowProc(hWnd, message, wParam, lParam);
  118.         }
  119.         break;
  120.     case WM_LBUTTONDBLCLK:
  121.         Beep(1000,1000);
  122.         break;
  123.     case WM_RBUTTONDBLCLK:
  124.         MessageBox(hWnd,lpString,_T("Информационное сообщение"),NULL);
  125.         break;
  126.     case WM_DESTROY:
  127.         PostQuitMessage(0);
  128.         break;
  129.     default:
  130.         return DefWindowProc(hWnd, message, wParam, lParam);
  131.     }
  132.     return 0;
  133. }
  134.  
  135. LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  136. {
  137.     int wmId, wmEvent;
  138.     RECT rect;
  139.     enum location {TOP,RIGHT,BOTTOM,LEFT};
  140.     location loc=TOP;
  141.     int width, height, d;
  142.     switch (message)
  143.     {
  144.     case WM_COMMAND:
  145.         wmId    = LOWORD(wParam);
  146.         wmEvent = HIWORD(wParam);
  147.         switch (wmId)
  148.         {
  149.         case IDM_ABOUT:
  150.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  151.             break;
  152.         case IDM_EXIT:
  153.             DestroyWindow(hWnd);
  154.             break;
  155.         default:
  156.             return DefWindowProc(hWnd, message, wParam, lParam);
  157.         }
  158.         break;
  159.     case WM_LBUTTONDBLCLK:
  160.         if(GetWindowRect(hWnd, &rect))
  161.         {
  162.             width=rect.right-rect.left;
  163.             height=rect.bottom-rect.top;
  164.         }
  165.         else break;
  166.         if(loc==TOP)
  167.         {
  168.             if(GetSystemMetrics(SM_CXFULLSCREEN)-rect.right<100)
  169.             {
  170.                 d=GetSystemMetrics(SM_CXFULLSCREEN)-rect.right; loc=RIGHT;
  171.             }
  172.             else
  173.                 d=100;
  174.             MoveWindow(hWnd,d,0,width,height,true);
  175.         }
  176.         if(loc==RIGHT)
  177.         {
  178.             if(GetSystemMetrics(SM_CYFULLSCREEN)-rect.bottom<100)
  179.             {
  180.                 d=GetSystemMetrics(SM_CYFULLSCREEN)-rect.bottom; loc=BOTTOM;
  181.             }
  182.             else
  183.                 d=100;
  184.             MoveWindow(hWnd,0,d,width,height,true);
  185.         }
  186.         if(loc==BOTTOM)
  187.         {
  188.             if(rect.left<100)
  189.             {
  190.                 d=rect.left; loc=LEFT;
  191.             }
  192.             else
  193.                 d=100;
  194.             MoveWindow(hWnd,-d,0,width,height,true);
  195.         }
  196.         if(loc==LEFT)
  197.         {
  198.             if(rect.top<100)
  199.             {
  200.                 d=rect.top; loc=TOP;
  201.             }
  202.             else
  203.                 d=100;
  204.             MoveWindow(hWnd,0,-d,width,height,true);
  205.         }
  206.         break;
  207.     case WM_RBUTTONDBLCLK:
  208.         break;
  209.     case WM_DESTROY:
  210.         PostQuitMessage(0);
  211.         break;
  212.     default:
  213.         return DefWindowProc(hWnd, message, wParam, lParam);
  214.     }
  215.     return 0;
  216. }
  217.  
  218. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  219. {
  220.     UNREFERENCED_PARAMETER(lParam);
  221.     switch (message)
  222.     {
  223.     case WM_INITDIALOG:
  224.         return (INT_PTR)TRUE;
  225.  
  226.     case WM_COMMAND:
  227.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  228.         {
  229.             EndDialog(hDlg, LOWORD(wParam));
  230.             return (INT_PTR)TRUE;
  231.         }
  232.         break;
  233.     }
  234.     return (INT_PTR)FALSE;
  235. }
Add Comment
Please, Sign In to add comment