Beispiel #1
0
int main()
{
	DynArray <char> a;
	DynArray <char> b;

	char c = 'c';
	char d = 'd';
	char e = 'e';
	char f = 'f';
	char g = 'g';

	a.Push_Back(c);
	a.Push_Back(d);
	b.Push_Back(e);
	b.Push_Back(f);

	char result = a.At(0,result);

	//a = c,d 
	//b = e,f

	printf("At 0: %c\n", result);

	printf("A at 0,1: %c,%c\nB at 0,1: %c,%c\n", a[0], a[1], b[0], b[1]);

	a.Clear();

	printf("A clear... Size: %i\n", a.Size());

	a.Push_Back(c);
	a.Push_Back(d);

	a += b;

	printf("A after += : %c,%c,%c,%c\n", a[0], a[1], a[2], a[3]);

	printf("A[0] = %c, A[3] = %c\n", a[0], a[3]);

	printf("A.GetData = %p\n", a.GetData());

	printf("Capacity: %i, size = %i\n", a.Capacity(), a.Size());

	printf("Empty: ");

	if (a.Empty())
	{
		printf("yes\n");
	}
	else
	{
		printf("no\n");
	}

	a.Flip();

	printf("A fliped: %c,%c,%c,%c\n", a[0], a[1], a[2], a[3]);

	a.Push_Back(c);
	a.Push_Back(d);
	a.Push_Back(e);
	a.Push_Back(f);

	a.Insert(2, g);

	printf("A inserted g in 2: %c,%c,%c,%c,%c,%c,%c,%c,%c\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);

	a.Erase(1);

	printf("A: %s\n", a.GetData());

	DynArray <int> test;
	int swaps = 0;
	int z;
	time_t t;

	test.Push_Back(5);
	test.Push_Back(8);
	test.Push_Back(3);
	test.Push_Back(1);
	test.Push_Back(4);
	test.Push_Back(2);

	printf("Int Array : %i,%i,%i,%i,%i,%i\n", test[0], test[1], test[2], test[3], test[4], test[5]);

	swaps = test.BubbleSort();

	printf("Int Array : %i,%i,%i,%i,%i,%i\nSwaps: %i\n", test[0], test[1], test[2], test[3], test[4], test[5], swaps);
	
	DynArray <int> test2;
	time(&t);
	srand(t);
	for (int i = 0; i <= 1000; i++)
	{
		z = rand();
		test2.Push_Back(z);
	}

	system("pause");
	return 0;
}
Beispiel #2
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szTimerID[20];

	switch (message)
	{
	case WM_CREATE:
		OutTimeDate(hWnd);									//Первый вывод текущего времени
		SetTimer(hWnd, TIMER_01, 1000, (TIMERPROC)NULL);	//функция создает системный таймер c периодом 1с
		SetTimer(hWnd, TIMER_02, 5000, (TIMERPROC)NULL);
		pic.Add(new Circle(Point(250, 250), 150));
		pic.Add(new Circle(Point(400, 200), 50));
		pic.Add(new Circle(Point(500, 150), 100));
		pic.Add(new Line(Point(100, 100), Point(200, 200)));
		pic.Add(new Squer(Point(250, 250), Point(300, 300)));
		return TRUE;
	case WM_TIMER:
		switch (wParam)
		{
		case TIMER_01:
			OutTimeDate(hWnd);
			//MessageBox(NULL, _T("Первый таймер"), _T("wParam"), MB_ICONINFORMATION);
			break;
		case TIMER_02:
			//MessageBox(NULL, _T("Второй таймер"), _T("wParam"), MB_ICONINFORMATION);
			break;
		default:
			wsprintf((LPWSTR)szTimerID, _T("Неизвестный сигнал таймера %X"), wParam);
			MessageBox(NULL, (LPTSTR)szTimerID, _T("wParam"), MB_ICONINFORMATION);
			break;
		}
		/*
		wsprintf((LPWSTR)szTimerID, _T("%X"), wParam);
		MessageBox(NULL, (LPTSTR)szTimerID, _T("wParam"), MB_ICONINFORMATION);
		*/
		break;
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_LINE:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_LINE), hWnd, LineProc);
			InvalidateRect(hWnd, 0, 1);
			break;
		case IDM_CIRCLE:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_CIRCLE), hWnd, CircleProc);
			InvalidateRect(hWnd, 0, 1);
			break;
		case IDM_SQUER:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_SQUER), hWnd, SquerProc);
			InvalidateRect(hWnd, 0, 1);
			break;
		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_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		{
			// TODO: Add any drawing code here...
			//использование функций GDI
			//перо

			HPEN hNewPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0));
			HPEN hOldPen = (HPEN)SelectObject(hdc, hNewPen);

			HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(GRAY_BRUSH));
		
			for (size_t i = 0; i < pic.Size(); ++i)
				pic[i]->Draw(hdc);

			HBRUSH hNewBrush = CreateSolidBrush(RGB(255, 255, 0));
			SelectObject(hdc, hNewBrush);
			
			HBRUSH hNewBrush2 = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 255, 0));
			SelectObject(hdc, hNewBrush2);

			RECT rect = {0, 0, 200, 50};
			//LPRECT lpRect = &rect;
			//GetClientRect(hWnd, lpRect);
			SetTextColor(hdc, RGB(0, 250, 0));
			//SetBkColor(hdc, RGB(250, 0, 0));
			DrawText(hdc, szCurrentTime, -1, &rect, (DT_SINGLELINE | DT_CENTER | DT_VCENTER));
			
			SelectObject(hdc, hOldBrush);
			SelectObject(hdc, hOldPen);
			DeleteObject(hNewBrush);
			DeleteObject(hNewBrush2);
			DeleteObject(hNewPen);
		}
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		for (size_t i = 0; i < pic.Size(); ++i)
			delete pic[i];
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}