Advertisement
Guest User

Untitled

a guest
May 31st, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #undef UNICODE
  3. #include "resource.h"
  4. #include <cstring>
  5. #include <windows.h>
  6. #include <iostream>
  7. extern "C" int __fastcall arrays(int*, int);
  8.  
  9. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  10. //====================================================================
  11. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  12. {
  13.     HWND hMainWnd;
  14.     static char szClassName[] = "MyClass";
  15.     MSG msg;
  16.     WNDCLASSEX wc;
  17.     wc.cbSize = sizeof(wc);
  18.     wc.style = CS_HREDRAW | CS_VREDRAW;
  19.     wc.lpfnWndProc = WndProc;
  20.     wc.cbClsExtra = 0;
  21.     wc.cbWndExtra = 0;
  22.     wc.hInstance = hInstance;
  23.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  24.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  25.     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  26.     wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
  27.     wc.lpszClassName = szClassName;
  28.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  29.  
  30.     RegisterClassEx(&wc);
  31.  
  32.     hMainWnd = CreateWindow(
  33.         szClassName, "Laba5", WS_OVERLAPPEDWINDOW,
  34.         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  35.         (HWND)NULL, (HMENU)NULL,
  36.         (HINSTANCE)hInstance, NULL
  37.         );
  38.  
  39.     if (!hMainWnd) {
  40.         MessageBox(NULL, "Cannot create main window", "Error", MB_OK);
  41.         return 0;
  42.     }
  43.  
  44.     ShowWindow(hMainWnd, nCmdShow);
  45.     UpdateWindow(hMainWnd);
  46.  
  47.     while (GetMessage(&msg, NULL, 0, 0))
  48.     {
  49.         TranslateMessage(&msg);
  50.         DispatchMessage(&msg);
  51.     }
  52.     return msg.wParam;
  53. }
  54.  
  55.  
  56. /////////////////////////////////////////
  57. BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  58. int N;
  59. int a[100];
  60. int result;
  61. BOOL work;
  62. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  63. {
  64.  
  65.     HDC hdc;
  66.     static HINSTANCE hInst;
  67.     PAINTSTRUCT ps;
  68.     static int sx, sy;
  69.     static char text1[200];
  70.     switch (uMsg)
  71.     {
  72.     case WM_SIZE:
  73.         sx = LOWORD(lParam);
  74.         sy = HIWORD(lParam);
  75.         break;
  76.     case WM_COMMAND:
  77.         switch (LOWORD(wParam))
  78.         {
  79.         case ID_FILE_SETTINGS:
  80.             DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DlgProc);
  81.             break;
  82.         }
  83.         InvalidateRect(hWnd, NULL, TRUE);
  84.         break;
  85.  
  86.     case WM_PAINT:
  87.             hdc = BeginPaint(hWnd, &ps);
  88.             if (work)
  89.             {
  90.                 result = arrays(a, N);
  91.                 _itoa(result,text1,10);
  92.                 TextOut(hdc, sx / 3, sy / 2, "Элемент с наименьшей суммой цифр", 32);
  93.                 TextOut(hdc, sx / 2+60, sy / 2, text1, strlen(text1));
  94.             }
  95.             else
  96.             {
  97.                 TextOut(hdc, sx / 3, sy / 2, "Используйте меню для ввода данных", 33);
  98.             }
  99.             EndPaint(hWnd, &ps);
  100.         break;
  101.     case WM_DESTROY:
  102.         PostQuitMessage(0);
  103.         break;
  104.     default:
  105.         return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  106.     }
  107.     return 0;
  108. }
  109. ////////////////////////////////////////////////////////
  110. BOOL CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  111. {
  112.     static int n;
  113.     static int i = 0;
  114.     static char *pch;
  115.     static char  str[100];
  116.     switch (uMsg)
  117.     {
  118.     case WM_COMMAND:
  119.         switch (LOWORD(wParam))
  120.         {
  121.         case IDOK:
  122.             N = n;
  123.             i = 0;
  124.             pch = strtok(str, " "); // во втором параметре указаны разделитель (пробел)
  125.             while (pch != NULL)                         // пока есть лексемы
  126.             {
  127.                 a[i++] = atoi(pch);
  128.                 pch = strtok(NULL, " ");
  129.             }
  130.             work = TRUE;
  131.             EndDialog(hwnd, LOWORD(wParam));
  132.             return TRUE;
  133.             break;
  134.         case IDCANCEL:
  135.             work = FALSE;
  136.             EndDialog(hwnd, LOWORD(wParam));
  137.             return TRUE;
  138.         }
  139.         if (HIWORD(wParam) == EN_CHANGE)
  140.         {
  141.             switch (LOWORD(wParam))
  142.             {
  143.             case IDC_EDIT2:
  144.                 n = GetDlgItemInt(hwnd, IDC_EDIT2, NULL, FALSE);
  145.                 break;
  146.             case IDC_EDIT1:
  147.                 GetDlgItemText(hwnd, IDC_EDIT1, str, 100);
  148.                 break;
  149.             }
  150.         }
  151.         break;
  152.     case WM_CLOSE:
  153.         work = FALSE;
  154.         EndDialog(hwnd, 0);
  155.         return FALSE;
  156.         break;
  157.     }
  158.     return FALSE;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement