Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #undef UNICODE
- #include "resource.h"
- #include <cstring>
- #include <windows.h>
- #include <iostream>
- extern "C" int __fastcall arrays(int*, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- //====================================================================
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- HWND hMainWnd;
- static char szClassName[] = "MyClass";
- MSG msg;
- WNDCLASSEX wc;
- wc.cbSize = sizeof(wc);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
- wc.lpszClassName = szClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- RegisterClassEx(&wc);
- hMainWnd = CreateWindow(
- szClassName, "Laba5", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
- (HWND)NULL, (HMENU)NULL,
- (HINSTANCE)hInstance, NULL
- );
- if (!hMainWnd) {
- MessageBox(NULL, "Cannot create main window", "Error", MB_OK);
- return 0;
- }
- ShowWindow(hMainWnd, nCmdShow);
- UpdateWindow(hMainWnd);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- /////////////////////////////////////////
- BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
- int N;
- int a[100];
- int result;
- BOOL work;
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- HDC hdc;
- static HINSTANCE hInst;
- PAINTSTRUCT ps;
- static int sx, sy;
- static char text1[200];
- switch (uMsg)
- {
- case WM_SIZE:
- sx = LOWORD(lParam);
- sy = HIWORD(lParam);
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case ID_FILE_SETTINGS:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DlgProc);
- break;
- }
- InvalidateRect(hWnd, NULL, TRUE);
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- if (work)
- {
- result = arrays(a, N);
- _itoa(result,text1,10);
- TextOut(hdc, sx / 3, sy / 2, "Элемент с наименьшей суммой цифр", 32);
- TextOut(hdc, sx / 2+60, sy / 2, text1, strlen(text1));
- }
- else
- {
- TextOut(hdc, sx / 3, sy / 2, "Используйте меню для ввода данных", 33);
- }
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return (DefWindowProc(hWnd, uMsg, wParam, lParam));
- }
- return 0;
- }
- ////////////////////////////////////////////////////////
- BOOL CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- static int n;
- static int i = 0;
- static char *pch;
- static char str[100];
- switch (uMsg)
- {
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case IDOK:
- N = n;
- i = 0;
- pch = strtok(str, " "); // во втором параметре указаны разделитель (пробел)
- while (pch != NULL) // пока есть лексемы
- {
- a[i++] = atoi(pch);
- pch = strtok(NULL, " ");
- }
- work = TRUE;
- EndDialog(hwnd, LOWORD(wParam));
- return TRUE;
- break;
- case IDCANCEL:
- work = FALSE;
- EndDialog(hwnd, LOWORD(wParam));
- return TRUE;
- }
- if (HIWORD(wParam) == EN_CHANGE)
- {
- switch (LOWORD(wParam))
- {
- case IDC_EDIT2:
- n = GetDlgItemInt(hwnd, IDC_EDIT2, NULL, FALSE);
- break;
- case IDC_EDIT1:
- GetDlgItemText(hwnd, IDC_EDIT1, str, 100);
- break;
- }
- }
- break;
- case WM_CLOSE:
- work = FALSE;
- EndDialog(hwnd, 0);
- return FALSE;
- break;
- }
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement