Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tchar.h>
  5. #include <iostream>
  6. #define ID_EXIT 1
  7. #define ID_BUTTON 2
  8.  
  9. static TCHAR szWindowClass[] = _T("win32app");
  10. static TCHAR szTitle[] = _T("1st Lab.");
  11.  
  12.  
  13. int x1, x2, y1, y2, index;
  14. HINSTANCE hInst;
  15.  
  16. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  17. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
  18.  
  19.  
  20.  
  21. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  22. {
  23. STARTUPINFO si;
  24. ZeroMemory(&pi, sizeof(STARTUPINFO));
  25. PROCESS_INFORMATION pi;
  26.  
  27.  
  28. WNDCLASSEX wcex;
  29.  
  30. wcex.cbSize = sizeof(WNDCLASSEX);
  31. wcex.style = CS_HREDRAW | CS_VREDRAW;
  32. wcex.lpfnWndProc = WndProc;
  33. wcex.cbClsExtra = 0;
  34. wcex.cbWndExtra = 0;
  35. wcex.hInstance = hInstance;
  36. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  37. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  38. wcex.hbrBackground = (HBRUSH)(NULL_BRUSH);
  39. wcex.lpszMenuName = NULL;
  40. wcex.lpszClassName = szWindowClass;
  41. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  42.  
  43. if (!RegisterClassEx(&wcex))
  44. {
  45. MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Win32 Guided Tour"), NULL);
  46. return 1;
  47. }
  48.  
  49. hInst = hInstance;
  50.  
  51. //x1 = 500; y1 = 10; x2 = 500; y2 = 340;
  52. // The parameters to CreateWindow explained:
  53. // szWindowClass: the name of the application
  54. // szTitle: the text that appears in the title bar
  55. // WS_OVERLAPPEDWINDOW: the type of window to create
  56. // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
  57. // 500, 100: initial size (width, length)
  58. // NULL: the parent of this window
  59. // NULL: this application does not have a menu bar
  60. // hInstance: the first parameter from WinMain
  61. // NULL: not used in this application
  62. HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 250, 170, 250, 250, NULL, NULL, hInstance, NULL);
  63.  
  64.  
  65. if (!hWnd)
  66. {
  67. MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("Win32 Guided Tour"), NULL);
  68. return 1;
  69. }
  70.  
  71. // The parameters to ShowWindow explained:
  72. // hWnd: the value returned from CreateWindow
  73. // nCmdShow: the fourth parameter from WinMain
  74. ShowWindow(hWnd, nCmdShow);
  75. UpdateWindow(hWnd);
  76. ////////////////////////////
  77. MSG msg;
  78. while (GetMessage(&msg, NULL, 0, 0))
  79. {
  80. TranslateMessage(&msg);
  81. DispatchMessage(&msg);
  82. }
  83. return (int)msg.wParam;
  84. }
  85.  
  86. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  87. {
  88. PAINTSTRUCT ps;
  89. HDC hdc;
  90. static HWND hExit, hButton;
  91.  
  92.  
  93.  
  94. switch (message)
  95. {
  96. case WM_CREATE:
  97. 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);
  98. 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);
  99. // hStat = CreateWindow(L"STATIC", NULL, WS_CHILD | WS_VISIBLE, 450, 170, 50, 20, hWnd, (HMENU)ID_STATIC1, hInst, NULL);
  100. // hStat2 = CreateWindow(L"static", NULL, WS_CHILD | WS_VISIBLE, 450, 195, 50, 20, hWnd, (HMENU)ID_STATIC2, hInst, NULL);
  101.  
  102.  
  103.  
  104. ///////////////////////////////////////////////////////////////////////////////////////////////
  105.  
  106. // hListBox = CreateWindow(L"listbox", NULL, WS_CHILD | WS_VISIBLE | LBS_STANDARD, 570, 45, 200, 70, hWnd, (HMENU)ID_LIST, hInst, NULL);
  107. // hStat3 = CreateWindow(L"static", NULL, WS_CHILD | WS_VISIBLE, 550, 170, 320, 110, hWnd, (HMENU)ID_STATIC3, hInst, NULL);
  108.  
  109.  
  110. break;
  111.  
  112. /*
  113.  
  114. case WM_PAINT:
  115. hdc = BeginPaint(hWnd, &ps);
  116. SetBkMode(hdc, 0);
  117. TextOut(hdc, 30, 170, location, _tcslen(location));
  118. TextOut(hdc, 124, 195, range, _tcslen(range));
  119.  
  120. BOOL Line(HDC hdc, int x1, int y1, int x2, int y2);
  121. {
  122. MoveToEx(hdc, x1, y1, NULL); //сделать текущими координаты x1, y1
  123. return LineTo(hdc, x2, y2);
  124. }
  125.  
  126. EndPaint(hWnd, &ps);
  127. break;
  128. */
  129. case WM_COMMAND:
  130. switch (LOWORD(wParam))
  131. {
  132.  
  133. case ID_BUTTON:
  134. {
  135. CreateProcess(L"C:\\Users\\Максим\\Desktop\\Учёба\\2 курс\\2 семестр\\ОСи\\Лабораторная 3\\ОС 3я лаба\\global\\Debug\\client.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
  136.  
  137. break;
  138. }
  139.  
  140.  
  141. case ID_EXIT:
  142. {
  143. DestroyWindow(hWnd);
  144. return 0;
  145. break;
  146. }
  147. }
  148. break;
  149.  
  150. case WM_DESTROY:
  151. PostQuitMessage(0);
  152. break;
  153. default:
  154. return DefWindowProc(hWnd, message, wParam, lParam);
  155. break;
  156. }
  157. return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement