Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "OS_1.h"
- #define MAX_LOADSTRING 100
- HINSTANCE hInst;
- TCHAR szMainTitle[]=_T("Лабораторная работа №1 по ОС студ. Беляева М.О. группа ИУС-10б");
- TCHAR szWindowClass[MAX_LOADSTRING];
- ATOM MainClass(HINSTANCE hInstance);
- ATOM ChildClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
- int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPTSTR lpCmdLine,
- _In_ int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- MSG msg;
- HACCEL hAccelTable;
- LoadString(hInstance, IDC_OS_1, szWindowClass, MAX_LOADSTRING);
- MainClass(hInstance);
- ChildClass(hInstance);
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_OS_1));
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- return (int) msg.wParam;
- }
- ATOM MainClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
- wcex.lpfnWndProc = MainWndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_OS_1));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = MAKEINTRESOURCE(IDC_OS_1);
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
- return RegisterClassEx(&wcex);
- }
- ATOM ChildClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
- wcex.lpfnWndProc = ChildWndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_OS_1));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = MAKEINTRESOURCE(IDC_OS_1);
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
- return RegisterClassEx(&wcex);
- }
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HWND hWndMain, hWndChild;
- hInst = hInstance;
- hWndMain = CreateWindow(szWindowClass, szMainTitle, WS_EX_APPWINDOW | WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
- hWndChild = CreateWindow(szWindowClass,_T("DERP"), WS_CHILD | WS_OVERLAPPEDWINDOW,
- 0, 0, GetSystemMetrics(SM_CXFULLSCREEN)/5, GetSystemMetrics(SM_CYFULLSCREEN)/5, hWndMain, NULL, hInstance, NULL);
- if (!hWndMain&&!hWndChild)
- {
- return FALSE;
- }
- ShowWindow(hWndMain, SW_MAXIMIZE);
- ShowWindow(hWndChild, SW_NORMAL);
- UpdateWindow(hWndMain);
- UpdateWindow(hWndChild);
- return TRUE;
- }
- LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- TCHAR lpString[] = _T("События данного окна обрабатыватся функцией LRESULT CALLBACK MainWndProc()");
- switch (message)
- {
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
- switch (wmId)
- {
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
- case WM_LBUTTONDBLCLK:
- Beep(1000,1000);
- break;
- case WM_RBUTTONDBLCLK:
- MessageBox(hWnd,lpString,_T("Информационное сообщение"),NULL);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- RECT rect;
- enum location {TOP,RIGHT,BOTTOM,LEFT};
- location loc=TOP;
- int width, height, d;
- switch (message)
- {
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
- switch (wmId)
- {
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
- case WM_LBUTTONDBLCLK:
- if(GetWindowRect(hWnd, &rect))
- {
- width=rect.right-rect.left;
- height=rect.bottom-rect.top;
- }
- else break;
- if(loc==TOP)
- {
- if(GetSystemMetrics(SM_CXFULLSCREEN)-rect.right<100)
- {
- d=GetSystemMetrics(SM_CXFULLSCREEN)-rect.right; loc=RIGHT;
- }
- else
- d=100;
- MoveWindow(hWnd,d,0,width,height,true);
- }
- if(loc==RIGHT)
- {
- if(GetSystemMetrics(SM_CYFULLSCREEN)-rect.bottom<100)
- {
- d=GetSystemMetrics(SM_CYFULLSCREEN)-rect.bottom; loc=BOTTOM;
- }
- else
- d=100;
- MoveWindow(hWnd,0,d,width,height,true);
- }
- if(loc==BOTTOM)
- {
- if(rect.left<100)
- {
- d=rect.left; loc=LEFT;
- }
- else
- d=100;
- MoveWindow(hWnd,-d,0,width,height,true);
- }
- if(loc==LEFT)
- {
- if(rect.top<100)
- {
- d=rect.top; loc=TOP;
- }
- else
- d=100;
- MoveWindow(hWnd,0,-d,width,height,true);
- }
- break;
- case WM_RBUTTONDBLCLK:
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
Add Comment
Please, Sign In to add comment