Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tchar.h>
- #include <iostream>
- #define ID_EXIT 1
- #define ID_BUTTON 2
- static TCHAR szWindowClass[] = _T("win32app");
- static TCHAR szTitle[] = _T("1st Lab.");
- int x1, x2, y1, y2, index;
- HINSTANCE hInst;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- STARTUPINFO si;
- ZeroMemory(&pi, sizeof(STARTUPINFO));
- PROCESS_INFORMATION pi;
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(NULL_BRUSH);
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
- if (!RegisterClassEx(&wcex))
- {
- MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Win32 Guided Tour"), NULL);
- return 1;
- }
- hInst = hInstance;
- //x1 = 500; y1 = 10; x2 = 500; y2 = 340;
- // The parameters to CreateWindow explained:
- // szWindowClass: the name of the application
- // szTitle: the text that appears in the title bar
- // WS_OVERLAPPEDWINDOW: the type of window to create
- // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
- // 500, 100: initial size (width, length)
- // NULL: the parent of this window
- // NULL: this application does not have a menu bar
- // hInstance: the first parameter from WinMain
- // NULL: not used in this application
- HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 250, 170, 250, 250, NULL, NULL, hInstance, NULL);
- if (!hWnd)
- {
- MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("Win32 Guided Tour"), NULL);
- return 1;
- }
- // The parameters to ShowWindow explained:
- // hWnd: the value returned from CreateWindow
- // nCmdShow: the fourth parameter from WinMain
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- ////////////////////////////
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- static HWND hExit, hButton;
- switch (message)
- {
- case WM_CREATE:
- hExit = CreateWindowEx(WS_EX_CLIENTEDGE, L"button", L"Выход", WS_CHILD | WS_VISIBLE | WS_BORDER | BS_DEFPUSHBUTTON, 50, 100, 125, 45, hWnd, (HMENU)ID_EXIT, hInst, NULL);
- hButton = CreateWindow(L"button", L"ON/OFF", WS_CHILD | WS_VISIBLE | WS_BORDER | BS_DEFPUSHBUTTON, 50, 50, 125, 45, hWnd, (HMENU)ID_BUTTON, hInst, NULL);
- // hStat = CreateWindow(L"STATIC", NULL, WS_CHILD | WS_VISIBLE, 450, 170, 50, 20, hWnd, (HMENU)ID_STATIC1, hInst, NULL);
- // hStat2 = CreateWindow(L"static", NULL, WS_CHILD | WS_VISIBLE, 450, 195, 50, 20, hWnd, (HMENU)ID_STATIC2, hInst, NULL);
- ///////////////////////////////////////////////////////////////////////////////////////////////
- // hListBox = CreateWindow(L"listbox", NULL, WS_CHILD | WS_VISIBLE | LBS_STANDARD, 570, 45, 200, 70, hWnd, (HMENU)ID_LIST, hInst, NULL);
- // hStat3 = CreateWindow(L"static", NULL, WS_CHILD | WS_VISIBLE, 550, 170, 320, 110, hWnd, (HMENU)ID_STATIC3, hInst, NULL);
- break;
- /*
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- SetBkMode(hdc, 0);
- TextOut(hdc, 30, 170, location, _tcslen(location));
- TextOut(hdc, 124, 195, range, _tcslen(range));
- BOOL Line(HDC hdc, int x1, int y1, int x2, int y2);
- {
- MoveToEx(hdc, x1, y1, NULL); //сделать текущими координаты x1, y1
- return LineTo(hdc, x2, y2);
- }
- EndPaint(hWnd, &ps);
- break;
- */
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case ID_BUTTON:
- {
- CreateProcess(L"C:\\Users\\Максим\\Desktop\\Учёба\\2 курс\\2 семестр\\ОСи\\Лабораторная 3\\ОС 3я лаба\\global\\Debug\\client.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
- break;
- }
- case ID_EXIT:
- {
- DestroyWindow(hWnd);
- return 0;
- break;
- }
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement